微软CRX下载器

使非Edge浏览器,也能从微软扩展商店下载CRX文件

目前為 2021-08-17 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         微软CRX下载器
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  使非Edge浏览器,也能从微软扩展商店下载CRX文件
// @author       那年那tu那些事
// @match        *://microsoftedge.microsoft.com/addons/*
// @icon         https://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RE4sQDc?ver=30c2&q=90&m=6&h=40&w=40&b=%23FFFFFFFF&l=f&o=t&aim=true
// ==/UserScript==

(function() {

	//构造CRX下载器
	function MicrosoftCRXdownloader(crxid) {
		//ID写入URL
		var crxurl =
			"https://edge.microsoft.com/extensionwebstorebase/v1/crx?response=redirect&acceptformat=crx3&x=id%3D" +
			crxid + "%26installsource%3Dondemand%26uc";
		//构造下载按钮
		var newButton = document.createElement("button");
		newButton.id = "buttonID" + crxid;
		newButton.style =
			"width:100%; min-width: 100px;height:max-content; min-height: 40px; cursor: pointer; margin-inline-end: 8px;background: rgb(0, 120, 212);border:2px solid transparent;border-radius:2px;text-align: center;";
		newButton.innerHTML = "<a href=" + crxurl +
			" target='_blank' style='color: white;text-decoration:none;'><b>下载CRX</b><br></a>";
		//将“下载CRX”按钮替换“获取”按钮
		if ((document.getElementById("getOrRemoveButton-" + crxid) !== null) && (document
				.getElementById("buttonID" + crxid) === null)) {
			let buttonPare = document.getElementById("getOrRemoveButton-" + crxid).parentElement;
			let buttonChid = document.getElementById("getOrRemoveButton-" + crxid);
			buttonPare.insertBefore(newButton, buttonChid);
			console.log("buttonID" + crxid + "替换成功!");
			buttonChid.style.display = "none";
			document.getElementById("buttonID" + crxid).onclick = function() {
				window.open(crxurl);
			}
		}
	}

	//搜索获取CRX插件ID
	function SearchCRXid() {
		var AllButtonObj = document.getElementsByTagName("button");
		for (let i = 0; i < AllButtonObj.length; i++) {
			var ButtonObjID = AllButtonObj[i].getAttribute("id");

			if ((i - 1) >= 0) {
				var NewButtonObjID = AllButtonObj[i - 1].getAttribute("id");
			} else {
				var NewButtonObjID = ButtonObjID;
			}
			if (ButtonObjID !== null) {
				if (ButtonObjID.search("getOrRemoveButton-") !== -1) {
					var crxid = ButtonObjID.slice(ButtonObjID.search("getOrRemoveButton-") + "getOrRemoveButton-"
						.length);
					if (NewButtonObjID !== ("buttonID" + crxid)) {
						return crxid;
					}
				}
			}

		}
	}

	//判断是否执行
	if (window.location.pathname.search("detail/") !== -1) { //扩展详情页
		//获取扩展ID
		var crxid = window.location.pathname;
		crxid = crxid.slice(crxid.search("detail/") + "detail/".length);
		crxid = crxid.slice(crxid.search("/") + 1);
		//替换按钮
		var CRXtimerID = setInterval(function() {
			MicrosoftCRXdownloader(crxid);
		}, 200)
		//3s超时,刷新页面
		setTimeout(function() {
			clearInterval(CRXtimerID);
			if (document.getElementById("buttonID" + crxid) === null) {
				console.log("buttonID" + crxid + "替换失败!");
				window.location.reload();
			}
		}, 3000);
	} else { //商店主页及其他非详情页
		setInterval(function() {
			//获取扩展ID
			var crxid = SearchCRXid();
			//隐藏按钮
			for (let i = 0; i < document.getElementsByTagName("button").length; i++) {
				var hideButton = document.getElementsByTagName("button");
				if (hideButton[i].getAttribute("id") !== null) {
					//隐藏所有原本的“获取”按钮
					if (hideButton[i].getAttribute("id").search("getOrRemoveButton-") !== -1) {
						hideButton[i].style.display = "none";
					}
					//当原本的“获取”按钮消失,替换按钮也消失
					if (hideButton[i].getAttribute("id").search("buttonID") !== -1) {
						if (hideButton[i + 1].getAttribute("id") !== null) {
							if (hideButton[i + 1].getAttribute("id").search("getOrRemoveButton-") === -1) {
								hideButton[i].style.display = "none";
							} else {
								hideButton[i].style.display = "";
							}
						} else {
							hideButton[i].style.display = "none";
						}
					}

				}

			}
			//替换按钮
			if (crxid !== undefined) {
				MicrosoftCRXdownloader(crxid);
			}
		}, 100)
	}
})();