Greasy Fork

Greasy Fork is available in English.

View Twitter Origin Images

Convert the new Twitter image to the original quality, and the replace image URL, support right click 'Copy Image Location' & 'Open Image In New Tab'.

当前为 2019-07-29 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         View Twitter Origin Images
// @name:zh-TW   檢視Twitter原始圖檔
// @namespace    http://greasyfork.icu
// @version      0.0.5
// @description  Convert the new Twitter image to the original quality, and the replace image URL, support right click 'Copy Image Location' & 'Open Image In New Tab'.
// @description:zh-TW  將新版推特的圖片轉為原始畫質版本,並支援從右鍵取得原始圖片網址
// @author       Pixmi
// @icon         https://i.imgur.com/AmUaAWh.png
// @include      https://twitter.com/*
// @include      https://pbs.twimg.com/media/*
// @license      MIT
// @run-at       document-end
// @grant        none
// ==/UserScript==

/* jshint esversion: 6 */

if (window.location.href.includes('pbs.twimg.com/media')) {
    let imgHref = location.href;
    if (imgHref.includes("https://pbs.twimg.com/media/") && !imgHref.match(/\?name=orig/)) {
        let url = imgHref.replace('?format=','.').replace(/\&name=(\w+)/g,'?name=orig');
        window.location.replace(url);
    }
} else {
    console.log('View Twitter Origin Images 0.0.5 start up.');
    let rootmatch = document.evaluate("//div[@id='react-root']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    let rootnode = rootmatch.singleNodeValue;

    if (rootnode) {
        let imgSet;
        var callback = function (mutationsList, observer) {
            for (let mutation of mutationsList) {
                if (mutation.target.className.includes("css-1dbjc4n")) {
                    imgSet = mutation.target.getElementsByTagName('img');
                    let i;
                    for (i = 0; i < imgSet.length; i++) {
                        let imgSrc = imgSet[i].src;
                        if (imgSrc.includes("https://pbs.twimg.com/media/") && !imgSrc.match(/name=orig/)) {
                            // console.log(`replace ${imgSrc}`);
                            imgSet[i].src = imgSrc.replace('?format=','.').replace(/&name=(\w+)/g,'?name=orig');
                        }
                    }
                }
            }
        };
        const observeConfig = {
            attributes: true,
            childList: true,
            subtree: true
        };
        const observer = new MutationObserver(callback);

        observer.observe(document.body, observeConfig);
    }
}