RPS High Quality Images

Replaces low quality and low resolution images with their original

目前为 2020-01-03 提交的版本。查看 最新版本

// ==UserScript==
// @name         RPS High Quality Images
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Replaces low quality and low resolution images with their original
// @author       BlankedyBlank
// @match        https://www.rockpapershotgun.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var images = document.getElementsByTagName("img");
    var links = document.getElementsByTagName("a");
    var regex = /background-image:url\((.*)\/RPSS\/resize.*?;/i;

    //Replaces normal article images, and most on site
    for (var i=0, imax=images.length; i<imax; i++) {
        if (images[i].getAttributeNames().includes("data-original")) {
            images[i].src = images[i].getAttribute("data-original");
    }

    //Replaces "spotlight" images (etc) that are specified as a background in the "style" attribute
    for (var j=0, jmax=links.length; j<jmax; j++) {
        if ((links[j].hasAttribute("style")) && links[j].getAttribute("style").match("resize")) {
            links[j].style = links[j].getAttribute("style").replace(regex, "background-image:url($1);");
        }
    }
}
})();