微软CRX下载器

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

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

// ==UserScript==
// @name         微软CRX下载器
// @namespace    http://tampermonkey.net/
// @version      0.12
// @description  使非Edge浏览器,也能从微软扩展商店下载CRX文件
// @author       那年那tu那些事
// @include      *://microsoftedge.microsoft.com/addons/*
// @icon         https://i.loli.net/2021/08/18/mMtybsTwCBkFPW5.png
// ==/UserScript==

(function() {
	//替换原图标
	function changeButton(crxid, oldbuttonOBJ) {
		//crxid写入URL
		var crxurl =
			"https://edge.microsoft.com/extensionwebstorebase/v1/crx?response=redirect&acceptformat=crx3&x=id%3D" +
			crxid.slice(0, 32) + "%26installsource%3Dondemand%26uc";
		//克隆原图标
		var newbuttonOBJ = oldbuttonOBJ.cloneNode();
		//构造新图标内容、样式、功能
		newbuttonOBJ.id = "newButton-" + crxid;
		newbuttonOBJ.style = "opacity:1;z-index: 999;cursor:pointer !important;";
		newbuttonOBJ.innerHTML = "<a href=" + crxurl +
			" target='_blank' style='color: white;text-decoration:none;width:100%'><b>下载CRX</b><br></a>";
		//解除button的禁用
		newbuttonOBJ.disabled = false;
		//图标加上name属性,防止一直被遍历赋值
		newbuttonOBJ.name = "newbutton";
		oldbuttonOBJ.name = "oldbutton";
		//插入新图标
		var buttonPare = oldbuttonOBJ.parentElement;
		buttonPare.insertBefore(newbuttonOBJ, oldbuttonOBJ);
		//隐藏原图标
		oldbuttonOBJ.style.display = "none";
		//隐藏原提示语
		if (buttonPare.children.length === 3) {
			if (buttonPare.children[2].getAttribute("aria-live") === "polite") {
				buttonPare.children[2].style.display = "none";
			}
		}

	}
	//搜索获取图标
	function SearchCRXbutton() {
		//获取所有button对象
		var AllButtonObj = document.getElementsByTagName("button");
		//遍历所有button,找到“获取”图标(button id:getOrRemoveButton-xxxxxx)
		for (let i = 0; i < AllButtonObj.length; i++) {
			var ButtonObj = AllButtonObj[i];
			var AfterButtonObj = ButtonObj;
			if ((i + 1) < AllButtonObj.length) {
				AfterButtonObj = AllButtonObj[i + 1];
			}
			var ButtonObjID = ButtonObj.id;
			var ButtonObjName = ButtonObj.name;
			//获取crxid并替换图标
			if ((ButtonObjID.search("getOrRemoveButton-") !== -1) && (ButtonObjName === "")) {
				//从button id中获取crxid
				var crxid = ButtonObjID.slice("getOrRemoveButton-".length);
				//调用方法替换原图标
				changeButton(crxid, ButtonObj);
			}
			//新图标跟随旧图标显示/消失
			if (ButtonObjID.search("newButton-") !== -1) {
				var crxid = ButtonObjID.slice("newButton-".length);
				if (AfterButtonObj.id === "getOrRemoveButton-" + crxid) {
					ButtonObj.style.display = "";
				} else {
					ButtonObj.style.display = "none";
				}
			}

		}
	}
	//定时循环搜索
	var crxdownloaderSetTimer = 100;
	var crxdownloaderTimer = setInterval(function() {
		SearchCRXbutton();
	}, crxdownloaderSetTimer);
	console.log(crxdownloaderSetTimer + "ms定时器ID:" + crxdownloaderTimer)
})();