Google Search Highlighter

Highlights searched terms in results in yellow, and underlines exact matches

目前為 2020-07-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Google Search Highlighter
// @namespace    gglSearchHighlight_kk
// @description  Highlights searched terms in results in yellow, and underlines exact matches
// @version      1.0
// @author       Kai Krause <[email protected]>
// @include      http*://www.google.*/*
// @include      http*://www.google.co*.*/*
// @run-at       document-start
// ==/UserScript==

var css = document.createElement("style");
css.innerText = "em { background-color: yellow }";
document.head.appendChild(css);

setInterval(() => {
	var search = document.title;
	search = search.replace(/(imagesize|site|related|cache|inurl|filetype|-|OR).*?(?=\s|$)/g, "|split|");
	search = search.replace(/"/g, "|split|");
	search = search.split("|split|");

	search.forEach((term) => {
		term = term.trimStart().trim().toLowerCase();
		term = term.replace(/(\s\*\s|\*)/g, ".*?");
		if (!term) return;

		document.querySelectorAll("em").forEach((el) => {
			let str = el.textContent.trimStart().trim().toLowerCase();

			let isMatch = false;

			if (str === term) {
				isMatch = true;
			}
			else if (term.includes("*")) {
				let re = new RegExp(term);
				if (re.test(str)) isMatch = true;
			}

			if (isMatch) el.innerHTML = "<u>" + el.textContent + "</u>";
		});
	});
}, 50);

QingJ © 2025

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