Burning Vocabulary油猴简易版

日常习惯用Kiwi Browser 101.0.4951.57 + Bypass Paywalls 愉快的学习经济学人,后来无意中看到英语学习神器Burning Vocabulary,尝试在Kiwi上安装Burning Vocabulary,但适配不佳(双击单词的时候总是有偏差)。狐猴浏览器和Burning Vocabulary适配的挺好,但是狐猴浏览器上安装Bypass Paywalls失败。

经过权宜,觉得Kiwi Browser 101.0.4951.57 + Bypass Paywalls的方法更优,因此我写了这个油猴脚本替代Burning Vocabulary,简易版,只能标注没有翻译,毕竟手动选中用谷歌翻译也挺方便。

安装这个脚本后,打开经济学人网站,屏幕底部出现两个按钮"标注"”取消“。选中单词,点击”标注“,该单词在经济学人网站所有出现的地方都会标红;点击”取消“,该单词的颜色就会变成黑色。

以下是效果图:

 以下是代码:

// ==UserScript==
// @name         Burning Vocabulary类似版
// @namespace    http://tampermonkey.net/
// @version      1.2
// @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() {

	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;
	}

	let list_value = GM_listValues();
	for (var i = 0; i < list_value.length; i++) {
		makecolor(list_value[i], "red");
	}


	var selectionFirst = null;
	var selectionSecond = null;
	document.addEventListener("selectionchange", () => {
		selectionFirst = selectionSecond;
		selectionSecond = document.getSelection()
			.toString();

	});


	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);


})();

以下是下载地址:

Burning Vocabulary类似版 (greasyfork.org)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值