微软CRX下载器

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

目前为 2021-08-17 提交的版本。查看 最新版本

// ==UserScript==
// @name         微软CRX下载器
// @namespace    http://tampermonkey.net/
// @version      0.8
// @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 CreateCRXdownloader(crxid) {
		//ID写入URL
		var crxurl =
			"https://edge.microsoft.com/extensionwebstorebase/v1/crx?response=redirect&acceptformat=crx3&x=id%3D" +
			crxid.slice(0, 32) + "%26installsource%3Dondemand%26uc";
		//构造“下载CRX”图标
		var newButton = document.createElement("button");
		newButton.id = "buttonID" + crxid;
		newButton.style =
			"z-index: 9999;overflow:hidden;box-sizing:border-box;transition:all 0.1s ease-in-out;line-height:1;font-family:inherit;align-items:center;white-space:nowrap;justify-content:center;text-decoration:none;font-size:14px;width:100%; min-width: 100px;height:100%; min-height: 30px; 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);
			document.getElementById("buttonID" + crxid).onclick = function() {
				window.open(crxurl);
			}
			buttonChid.style.display = "none";
			//隐藏原有的提示语
			if (buttonPare.children.length === 3) {
				if (buttonPare.children[2].getAttribute("aria-live") === "polite") {
					buttonPare.children[2].style.display = "none";
				}
			}
			console.log("下载图标替换成功!");
		}
	}

	//搜索获取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;
					}
				}
			}

		}
	}

	//定时循环替换
	setInterval(function() {
		//获取扩展ID
		var crxid = SearchCRXid();
		//替换图标
		if (crxid !== undefined) {
			CreateCRXdownloader(crxid);
		}
		//隐藏图标
		var hideButton = document.getElementsByTagName("button");
		for (let i = 0; i < hideButton.length; i++) {
			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) {
					var ButtonIDStr = hideButton[i].getAttribute("id").slice("buttonID".length);
					var newButtonDisplay = "none";
					if ((i + 1) < hideButton.length) {
						if (hideButton[(i + 1)].getAttribute("id") !== null) {
							if (hideButton[(i + 1)].getAttribute("id").search("getOrRemoveButton-" +
									ButtonIDStr) !== -1) {
								newButtonDisplay = "";
							}
						}
					}
					hideButton[i].style.display = newButtonDisplay;
				}
			}
		}
	}, 100)
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址