Greasy Fork

Greasy Fork is available in English.

View Full Twitter Image

Undo Twitter's insistence to down-res images when viewing on its dedicated page and add a button to download the full image without the weird file extensions which don't count as actual images.

当前为 2018-02-03 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         View Full Twitter Image
// @version      1.2.5
// @description  Undo Twitter's insistence to down-res images when viewing on its dedicated page and add a button to download the full image without the weird file extensions which don't count as actual images.
// @author       ForgottenUmbrella
// @match        https://pbs.twimg.com/media/*
// @grant        none
// @noframes
// @namespace    http://greasyfork.icu/users/83187
// ==/UserScript==

// function createButton(text, func) {
//     "use strict";
//     var button = document.createElement("button");
//     button.value = text;
//     button.onclick = func;
//     document.body.appendChild(button);
// }

function download(filename) {
    "use strict";
    var element = document.createElement("a");
    // The `download` attribute only works if `href` is set.
    element.href = location.href;
    element.download = filename;
    element.style.display = "none";
    document.body.appendChild(element);
    element.click();
    document.body.removeChild(element);
}

// function domCreate(type, after, func, text, style) {
//     "use strict";
//     var element = document.createElement(type);
//     document.body.insertBefore(element, after);
//     if (typeof func !== "undefined") {
//         element.onclick = func;
//     }
//     if (typeof text !== "undefined") {
//         var t = document.createTextNode(text);
//         element.appendChild(t);
//     }
//     if (typeof style !== "undefined") {
//         element.style.height = style.height;
//         element.style.width = style.width;
//         element.style.marginLeft = style.margin_left;
//         element.style.marginRight = style.margin_right;
//         element.style.marginTop = style.margin_top;
//         element.style.marginBottom = style.margin_bottom;
//     }
//     return element;
// }

// function downloadPic() {
//     "use strict";
//     var link = document.createElement("a");
//     var notFilename = "https://pbs.twimg.com/media/";
//     var notFiletype = ":orig";
//     var filename = location.href.slice(
//         notFilename.length, location.href.length - notFiletype.length);
//     link.href = location.href;
//     link.setAttribute("download", filename);
//     link.click();
// }

// function iqdbSearch() {
//     "use strict";
//     location.href = "https://iqdb.org?url=" + location.href;
// }

(function() {
    "use strict";
    console.log("(Full Image) Running.");
    if (location.href.includes(":large")) {
        console.log("(Full Image) Will replace large with original.");
        location.href = location.href.replace(":large", ":orig");
    } else if (!location.href.includes(":orig")) {
        console.log("(Full Image) Will change URL to original.");
        location.href += ":orig";
    }

    var spacing = document.createElement("p");
    var image = document.getElementsByTagName("img")[0];
    document.body.insertBefore(spacing, image);

    var button = document.createElement("button");
    button.innerHTML = "Download";
    var filename = location.href.slice(
        "https://pbs.twimg.com/media/".length,
        location.href.length - ":orig".length
    );
    button.onclick = function() {
        download(filename);
    };
    document.body.insertBefore(button, spacing);
    // On Chrome, the button appears atop the image; on Firefox, to the left.

    // var spacing = domCreate("p", image);
    // var btn = domCreate("button", spacing, downloadPic, "Download");
    // var btn_2 = domCreate(
    //     "button", spacing, iqdbSearch, "IQDB Search", {
    //             margin_left: "20px"});
})();