[Deprecated] Ptt Imgur Cleaner

Replace smaller version Imgur image to large one.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name          [Deprecated] Ptt Imgur Cleaner
// @namespace     https://blog.gslin.org/ptt-imgur-gm
// @description   Replace smaller version Imgur image to large one.
// @include       https://www.ptt.cc/bbs/*
// @include       https://www.ptt.cc/man/*
// @run-at        document-idle
// @version       0.20191006.1
// @grant         none
// @run-at        document-start
// @license       MIT
// ==/UserScript==

(function(){
    let head = document.getElementsByTagName('head')[0];

    let meta = document.createElement('meta');
    meta.setAttribute('content', 'same-origin');
    meta.setAttribute('name', 'Referrer');
    head.appendChild(meta);

    let css = document.createElement('style');
    css.type = 'text/css';
    css.innerHTML = ".richcontent { max-width: 100%; }\nimg { max-height: 100%; }";
    head.appendChild(css);

    setInterval(() => {
        let targets = document.querySelectorAll('.richcontent iframe.imgur-embed-iframe-pub');
        targets.forEach(el => {
            var id = el.getAttribute('id').substring(23);

            // Use .webp
            var img = document.createElement('img');
            img.setAttribute('src', '//i.imgur.com/' + id + '.webp');

            el.parentNode.replaceChild(img, el);
        });
    }, 200);
})();