Browse Source

Flickr: link direct to "All Sizes"

Jason Tarka 1 year ago
parent
commit
f3a317bae5
1 changed files with 50 additions and 0 deletions
  1. 50 0
      flickr-link-to-all-sizes.user.js

+ 50 - 0
flickr-link-to-all-sizes.user.js

@@ -0,0 +1,50 @@
+// ==UserScript==
+// @name         Flickr: link direct to "All Sizes"
+// @namespace    http://tampermonkey.net/
+// @version      2024-12-17
+// @description  try to take over the world!
+// @author       You
+// @match        https://flickr.com/photos/*/
+// @match        https://flickr.com/photos/*/page*
+// @match        https://flickr.com/photos/*/with/*
+// @match        https://flickr.com/photos/*/albums/*
+// @match        https://flickr.com/photos/*/albums/*/page*
+// @match        https://flickr.com/photos/*/albums/*/with/*
+// @icon         https://www.google.com/s2/favicons?sz=64&domain=flickr.com
+// @grant        none
+// ==/UserScript==
+
+(function() {
+    'use strict';
+
+    (function monitorUpdateLinks() {
+        let parent = document.querySelector('#content');
+        let lastNumberProcessed = 0;
+
+        let observer = new MutationObserver(m => {
+            let links = parent.querySelectorAll('a[href^="/photos"]');
+            if (links.length == lastNumberProcessed) return;
+
+            Array.from(links).forEach(a => {
+                a.href = updateLink(a.href);
+            });
+        });
+        observer.observe(parent, {
+            subtree: true,
+            childList: true,
+            attributes: true,
+        });
+
+        function updateLink(url) {
+            if (url.match(/(3k|comments|page.*)$/))
+                return url;
+
+            let parts = url.match(/\/photos\/[^/]+\/[0-9]+/);
+            if (!parts)
+                return url;
+
+            console.log('Updating url:', url);
+            return `${parts[0]}/sizes/3k`
+        }
+    })();
+})();