Greasy Fork is available in English.

Unrandomize Tumblr Image Server

Changes all Tumblr hosted images to use a fixed server name. e.g. "78.media.tumblr.com" to "media.tumblr.com"

  1. // ==UserScript==
  2. // @name Unrandomize Tumblr Image Server
  3. // @namespace https://greasyfork.org/en/users/85671-jcunews
  4. // @description Changes all Tumblr hosted images to use a fixed server name. e.g. "78.media.tumblr.com" to "media.tumblr.com"
  5. // @author jcunews
  6. // @version 1.0.1
  7. // @license GNU AGPLv3
  8. // @match *://*.tumblr.com/*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function() {
  14.  
  15. var regex = /^(https?:\/\/)\d+\.(media\.tumblr\.com\/[0-9a-f]{32}\/tumblr_.*)$/;
  16.  
  17. function processSrc(ele) {
  18. if (!ele.src || (ele.tagName !== "IMG")) return;
  19. var match = ele.src.match(regex);
  20. if (!match) return;
  21. ele.src = match[1] + match[2];
  22. }
  23.  
  24. function processContainer(container) {
  25. var eles = container.querySelectorAll('img[src*=".media.tumblr.com/"]');
  26. processSrc(container);
  27. Array.prototype.slice.call(eles).forEach(processSrc);
  28. }
  29.  
  30. var observer = new MutationObserver(function(records) {
  31. records.forEach(function(record) {
  32. if (record.attributeName) {
  33. if (record.attributeName === "src") processSrc(record.target);
  34. } else {
  35. var nodes = Array.prototype.slice.call(record.addedNodes);
  36. nodes.forEach(function(node) {
  37. if (node.nodeType === 1) processContainer(node);
  38. });
  39. }
  40. });
  41. });
  42.  
  43. addEventListener("load", function() {
  44. processContainer(document.body);
  45. observer.observe(document.body, {
  46. childList: true,
  47. attributes: true,
  48. subtree: true
  49. });
  50. });
  51.  
  52. })();