Chrome CRX Downloader

4/3/2021, 1:52:08 AM

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Chrome CRX Downloader
// @namespace   https://github.com/YandLiu/Userscripts/
// @match       https://chrome.google.com/webstore/detail/*
// @grant       none
// @version     1.0
// @author      YandLiu
// @description 4/3/2021, 1:52:08 AM
// ==/UserScript==

(function (root) {
    "use strict";
    var listeners = [];
    var doc = window.document;
    var MutationObserver =
        window.MutationObserver || window.WebKitMutationObserver;
    var observer;

    function ready(selector, fn) {
        // 储存选择器和回调函数
        listeners.push({
            selector: selector,
            fn: fn,
        });
        if (!observer) {
            // 监听document变化
            observer = new MutationObserver(check);
            observer.observe(doc.documentElement, {
                childList: true,
                subtree: true,
            });
        }
        // 检查该元素是否已经在DOM中
        check();
    }

    function check() {
        // 检查DOM元素是否匹配已储存的元素
        for (var i = 0; i < listeners.length; i++) {
            var listener = listeners[i];
            // 检查指定元素是否有匹配
            var elements = document.querySelectorAll(listener.selector);
            for (var j = 0; j < elements.length; j++) {
                var element = elements[j];
                // 确保回调函数只会对该元素调用一次
                if (!element.ready) {
                    element.ready = true;
                    // 对该元素调用回调函数
                    listener.fn.call(element, element);
                }
            }
        }
    }

    // 对外暴露ready
    root.ready = ready;
})(window);

(function () {
    "use strict";
    ready("h1", insert);
})();

function insert() {
    var link =
        "https://clients2.google.com/service/update2/crx?response=redirect&nacl_arch=" +
        "&prodversion=89.0.4389.90" +
        "&acceptformat=crx2,crx3&x=id%3D" +
        document.location.href.split("/")[6].split("?")[0] +
        "%26installsource%3Dondemand%26uc";
    var title = document.querySelector("h1");
    var a = document.createElement("a");
    a.href = link;
    a.innerText = " Download";
    title.appendChild(a);
}