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"

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Unrandomize Tumblr Image Server
// @namespace    https://greasyfork.org/en/users/85671-jcunews
// @description  Changes all Tumblr hosted images to use a fixed server name. e.g. "78.media.tumblr.com" to "media.tumblr.com"
// @author       jcunews
// @version      1.0.1
// @license      GNU AGPLv3
// @match        *://*.tumblr.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {

  var regex = /^(https?:\/\/)\d+\.(media\.tumblr\.com\/[0-9a-f]{32}\/tumblr_.*)$/;

  function processSrc(ele) {
    if (!ele.src || (ele.tagName !== "IMG")) return;
    var match = ele.src.match(regex);
    if (!match) return;
    ele.src = match[1] + match[2];
  }

  function processContainer(container) {
    var eles = container.querySelectorAll('img[src*=".media.tumblr.com/"]');
    processSrc(container);
    Array.prototype.slice.call(eles).forEach(processSrc);
  }

  var observer = new MutationObserver(function(records) {
    records.forEach(function(record) {
      if (record.attributeName) {
        if (record.attributeName === "src") processSrc(record.target);
      } else {
        var nodes = Array.prototype.slice.call(record.addedNodes);
        nodes.forEach(function(node) {
          if (node.nodeType === 1) processContainer(node);
        });
      }
    });
  });

  addEventListener("load", function() {
    processContainer(document.body);
    observer.observe(document.body, {
      childList: true,
      attributes: true,
      subtree: true
    });
  });

})();