Google Webspam Report for Firefox

Open the webspam reporting form for that page from the context menu (right-click menu) of the link of Google search.

目前为 2020-08-29 提交的版本。查看 最新版本

// ==UserScript==
// @name        Google Webspam Report for Firefox
// @name:ja     Google Webスパム報告 for Firefox
// @description Open the webspam reporting form for that page from the context menu (right-click menu) of the link of Google search.
// @description:ja Google検索のリンクのコンテキストメニュー (右クリックメニュー) から、そのページを報告するためのWebスパム報告フォームを開きます。
// @version     0.1.0
// @namespace   https://gf.qytechs.cn/users/137
// @match       https://www.google.com/webmasters/tools/spamreportform
// @match       https://www.google.com/webmasters/tools/spamreportform?*
// @match       https://www.google.com/webmasters/tools/spamreportform#*
// @include     https://www.google.*
// @require     https://gitcdn.xyz/cdn/greasemonkey/gm4-polyfill/a834d46afcc7d6f6297829876423f58bb14a0d97/gm4-polyfill.js
// @require     https://gf.qytechs.cn/scripts/19616/code/utilities.js?version=840913
// @license     MPL-2.0
// @contributionURL https://www.amazon.co.jp/registry/wishlist/E7PJ5C3K7AM2
// @incompatible  Edge
// @compatible  Firefox
// @incompatible  Opera
// @incompatible  Chrome
// @grant       GM.openInTab
// @grant       GM_openInTab
// @noframes
// @run-at      document-end
// @icon        https://www.google.com/favicon.ico
// @author      100の人
// @homepageURL https://gf.qytechs.cn/scripts/373026
// ==/UserScript==

'use strict';

const DETAILS_TEMPLATES = [
	'This site was automatically generated by machine translation.',
];

Gettext.setLocalizedTexts({
	/*eslint-disable quote-props, max-len */
	'ja': {
		'Open webspam reporting form': 'Webスパム報告フォームを開く',
		'Clear': 'クリア',
		'This site was automatically generated by machine translation.': '機械翻訳により自動生成されたサイトです。',
	},
	/*eslint-enable quote-props, max-len */
});
Gettext.originalLocale = 'en';
Gettext.setLocale(navigator.language);

if (location.origin === 'https://www.google.com' && location.pathname === '/webmasters/tools/spamreportform') {
	const comments = document.getElementById('comments');
	const parent = comments.closest('.input-field');
	parent.insertAdjacentHTML('beforebegin', '<div class="text"><select></select></div>');
	const select = parent.previousElementSibling.firstElementChild;
	select.add(new Option(_('Clear'), ''));
	for (const details of DETAILS_TEMPLATES) {
		select.add(new Option(_(details), details));
	}
	select.value = comments.value = DETAILS_TEMPLATES[0];
	parent.previousElementSibling.firstElementChild.addEventListener('change', function (event) {
		comments.value = event.target.value;
	});
} else if (/^www\.google(\.com?)?\.[a-z]+$/.test(location.host)) {
	let menu, anchor;

	addEventListener('contextmenu', function (event) {
		if (!event.isTrusted) {
			return;
		}

		const a = event.target.closest('a');
		if (!a || !a.getElementsByTagName('h3')[0]) {
			return;
		}

		if (!menu) {
			document.body.insertAdjacentHTML('afterbegin', h`<menu type="context" id="${Math.random()}">
				<menuitem label="${_('Open webspam reporting form')}" />
			</menu>`);
			menu = document.body.firstElementChild;
			menu.firstElementChild.addEventListener('click', async function (event) {
				if (!event.isTrusted) {
					return;
				}
				
				GM.openInTab('https://www.google.com/webmasters/tools/spamreportform?' + new URLSearchParams({
					spamurl: anchor.getAttribute('href').startsWith('/url?')
						? new URLSearchParams(anchor.search).get('url')
						: anchor.href,
					query: new URLSearchParams(location.search).get('q'),
				}), false);
			});
		}

		if (!a.contextMenu) {
			a.setAttribute('contextmenu', menu.id);
		}

		anchor = a;
	});
}

QingJ © 2025

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