// ==UserScript== // @name View Twitter Origin Images // @namespace https://greasyfork.org // @version 0.0.1 // @description 將新版推特的圖片轉為原畫質版本,並可以從右鍵取得圖片網址 // @author Pixmi // @icon https://i.imgur.com/AmUaAWh.png // @include https://twitter.com/* // @include https://pbs.twimg.com/media/* // @grant none // @downloadURL none // ==/UserScript== /* jshint esversion: 6 */ "use strict"; if (window.location.href.includes('pbs.twimg.com/media')) { const twimg_URL = /https:\/\/pbs\.twimg\.com\/media\/([a-zA-Z0-9\-]+)\.(jpg|jpeg|png)\?name\=orig/; let imgHref = location.href; if (!twimg_URL.test(imgHref)) { let url = imgHref.replace('?format=','.').replace(/\&name=(\w+)/g,'?name=orig'); window.location.replace(url); } } else { 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); } }