// ==UserScript== // @name View Twitter Origin Images // @name:zh-TW 檢視Twitter原始圖檔 // @name:zh-CN 检视Twitter原始图档 // @namespace https://greasyfork.org // @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 將新版推特的圖片轉為原始畫質版本,並支援從右鍵取得原始圖片網址 // @description:zh-CN 将新版推特的图片转为原始画质版本,并支援从右键取得原始图片网址 // @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 // @downloadURL 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); } }