Twitter Image :orig Promoter

Automatically promotes twitter image links to :orig, such as from :large.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Twitter Image :orig Promoter
// @version      0.6
// @description  Automatically promotes twitter image links to :orig, such as from :large.
// @author       Cro
// @match        https://pbs.twimg.com/media/*
// @grant        none
// @namespace    https://greasyfork.org/users/10865
// @icon         https://www.google.com/s2/favicons?domain=twitter.com
// @license      MIT
// ==/UserScript==
(function () {
    "use strict";
    var queryVars = function(str) {
        return str.replace(/^\?/, '').split('&').map(x => x.split('=')).reduce((a, [k, v]) => { a[k] = v; return a; }, {});
    };
    // Check if this page contains a single image whose source is also the location.
    var image = document.getElementsByTagName('img')[0];
    if (image && image.getAttribute('src') == location.href) {
        var pathname = location.pathname;
        // Check if we already have the orig modifier
        if (!pathname.match(/:orig$/)) {
            // Trim modifiers.
            var idx = pathname.lastIndexOf(':');
            if (idx >= 0)
            {
                pathname = pathname.substr(0, idx);
            }
            // Check if we need to append the file type.
            var format = queryVars(location.search).format;
            if (format && !location.pathname.endsWith(format))
            {
                pathname += '.' + format;
            }
            // Add the modifier.
            pathname += ':orig';
            window.location = pathname;
        }
    }
})();