Burning Vocabulary类似版

仿真Burning Vocabulary,没有翻译功能,仅限于在经济学人网站上对单词进行标注

目前为 2023-09-23 提交的版本。查看 最新版本

// ==UserScript==
// @name         Burning Vocabulary类似版
// @namespace    http://tampermonkey.net/
// @version      1.10
// @description  仿真Burning Vocabulary,没有翻译功能,仅限于在经济学人网站上对单词进行标注
// @author       TCH
// @match        *://www.economist.com
// @include      *://*economist.com/*
// @grant        GM_setValue
// @grant        GM_deleteValue
// @grant        GM_listValues
// @license      tangchuanhui
// ==/UserScript==

(function() {

	var allsText = document.getElementsByTagName("body")[0].innerHTML;

	function makeallcolor(searchVal, nColor) {
		searchVal = " " + searchVal;
		var sKey = "<span name='addSpan' style='color:" + nColor + "';>" + searchVal + "</span>";
		var num = -1;
		var rStr = new RegExp(searchVal, "g");
		var rHtml = new RegExp("\<.*?\>", "ig"); //匹配html元素
		var aHtml = allsText.match(rHtml); //存放html元素的数组
		allsText = allsText.replace(rHtml, '{~}'); //替换html标签
		allsText = allsText.replace(rStr, sKey); //替换key
		allsText = allsText.replace(/{~}/g, function() { //恢复html标签
			num++;
			return aHtml[num];
		});
	}


	function makecolor(searchVal, nColor) {
		var oDiv = document.getElementsByTagName("body")[0];
		var sText = oDiv.innerHTML;
		searchVal = " " + searchVal;
		var sKey = "<span name='addSpan' style='color:" + nColor + "';>" + searchVal + "</span>";
		var num = -1;
		var rStr = new RegExp(searchVal, "g");
		var rHtml = new RegExp("\<.*?\>", "ig"); //匹配html元素
		var aHtml = sText.match(rHtml); //存放html元素的数组
		sText = sText.replace(rHtml, '{~}'); //替换html标签
		sText = sText.replace(rStr, sKey); //替换key
		sText = sText.replace(/{~}/g, function() { //恢复html标签
			num++;
			return aHtml[num];
		});
		oDiv.innerHTML = sText;
	}


	alert("开始染色");


	let list_value = GM_listValues();
	alert(list_value);
	for (var i = 0; i < list_value.length; i++) {
		makeallcolor(list_value[i], "red");
	}
	document.getElementsByTagName("body")[0].innerHTML = allsText;


	//监听选择文本的动作
	var selectionFirst = null;
	var selectionSecond = null;
	document.addEventListener("selectionchange", () => {
		selectionFirst = selectionSecond;
		selectionSecond = document.getSelection()
			.toString();

	});


	alert("染色结束");


alert("开始渲染按钮");
	let div = document.createElement("div");
	div.style = "position:fixed; bottom:20px; left: 0; margin: auto; right: 0;text-align:center;"
	div.innerHTML = '<span id="biaozhubiaozhu"style="width:150rpx;margin:15px;background-color: red;font-size: 30px;border-color: red;border-radius: 5px;" >标注</span><span id="quxiaobiaozhu" style="width:150rpx;margin:15px;background-color: black;font-size: 30px;color: white;border-radius: 5px;">取消</span>';
	document.onclick = function(event) {
		if (event.target.id == "biaozhubiaozhu") {

			selectionFirst = selectionSecond; //在有些浏览器,需要把这句去除
			if (selectionFirst !== null && selectionFirst !== void 0 && selectionFirst.toString()) {

				GM_setValue(selectionFirst, selectionFirst);

				makecolor(selectionFirst, "red");
			}

		} else if (event.target.id == "quxiaobiaozhu") {

			selectionFirst = selectionSecond; //在有些浏览器,需要把这句去除

			if (selectionFirst !== null && selectionFirst !== void 0 && selectionFirst.toString()) {
				GM_deleteValue(selectionFirst)

				makecolor(selectionFirst, "black");
			}
		}
	};
	document.body.append(div);



})();

QingJ © 2025

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