Google Search Highlighter

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

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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==

let embedCSS = setInterval(() => {
	if (document.head) {
		let css = document.createElement("style");
		css.innerText = "em { background-color: #FFFF7F; color: black !important }";
		document.head.appendChild(css);
		clearInterval(embedCSS);
	}
}, 4);

setInterval(() => {
	let 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);