flickr-link-to-all-sizes.user.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // ==UserScript==
  2. // @name Flickr: link direct to "All Sizes"
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-12-17
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://flickr.com/photos/*/
  8. // @match https://flickr.com/photos/*/page*
  9. // @match https://flickr.com/photos/*/with/*
  10. // @match https://flickr.com/photos/*/albums/*
  11. // @match https://flickr.com/photos/*/albums/*/page*
  12. // @match https://flickr.com/photos/*/albums/*/with/*
  13. // @icon https://www.google.com/s2/favicons?sz=64&domain=flickr.com
  14. // @grant none
  15. // ==/UserScript==
  16. (function() {
  17. 'use strict';
  18. (function monitorUpdateLinks() {
  19. let parent = document.querySelector('#content');
  20. let lastNumberProcessed = 0;
  21. let observer = new MutationObserver(m => {
  22. let links = parent.querySelectorAll('a[href^="/photos"]');
  23. if (links.length == lastNumberProcessed) return;
  24. Array.from(links).forEach(a => {
  25. a.href = updateLink(a.href);
  26. });
  27. });
  28. observer.observe(parent, {
  29. subtree: true,
  30. childList: true,
  31. attributes: true,
  32. });
  33. function updateLink(url) {
  34. if (url.match(/(3k|comments|page.*)$/))
  35. return url;
  36. let parts = url.match(/\/photos\/[^/]+\/[0-9]+/);
  37. if (!parts)
  38. return url;
  39. console.log('Updating url:', url);
  40. return `${parts[0]}/sizes/3k`
  41. }
  42. })();
  43. })();