Greasy Fork is available in English.
将新版推特的图片转为原始画质版本,并支援从右键取得原始图片网址
当前为
// ==UserScript==
// @name View Twitter Origin Images
// @name:zh-TW 檢視Twitter原始圖檔
// @name:zh-CN 检视Twitter原始图档
// @namespace http://greasyfork.icu
// @version 0.0.6
// @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
// ==/UserScript==
/* jshint esversion: 6 */
let imgHref = window.location.href;
if (imgHref.match(/https:\/\/pbs\.twimg\.com\/media\/([a-zA-Z0-9\-\_]+)(\?format=|.)(jpg|jpeg|png)/) && !imgHref.includes('?name=orig')) {
if (imgHref.indexOf('?format=') > 0) {
imgHref = imgHref.replace('?format=', '.');
}
if (imgHref.match(/\&name=(\w+)/)) {
imgHref = imgHref.replace(/\&name=(\w+)/g, '?name=orig');
} else {
imgHref = `${imgHref}?name=orig`;
}
window.location.replace(imgHref);
}
if (imgHref.includes('twitter.com')) {
console.log('View Twitter Origin Images 0.0.6 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);
}
}