Greasy Fork

Greasy Fork is available in English.

View Twitter Origin Images

將新版推特的圖片轉為原畫質版本,並可以從右鍵取得圖片網址

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         View Twitter Origin Images
// @namespace    http://greasyfork.icu
// @version      0.0.4
// @description  將新版推特的圖片轉為原畫質版本,並可以從右鍵取得圖片網址
// @author       Pixmi
// @icon         https://i.imgur.com/AmUaAWh.png
// @include      https://twitter.com/*
// @include      https://pbs.twimg.com/media/*
// @run-at       document-end
// @grant        none
// ==/UserScript==

/* jshint esversion: 6 */

if (window.location.href.includes('pbs.twimg.com/media')) {
    let imgHref = location.href;
    // if (!twimg_URL.test(imgHref)) {
    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.4 start up.');
    let rootmatch = document.evaluate("//div[@id='react-root']", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    let rootnode = rootmatch.singleNodeValue;

    //new Twitter UI
    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(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);
    }
}