由于对Google Search Console *的上瘾行为,我试图通过让自己回到Google Search来阻止自己使用 Google Search Console。
以下 JavaScript 代码在此处的 Web 浏览器控制台中运行,但不适用于用户脚本:
window.setInterval( () => {
const urlPatternToBlock = [
'https://search.google.com/'
];
for (const element of urlPatternToBlock) {
if (window.location.href.includes(urlPatternToBlock)) {
window.open("https://google.com/", "_self");
}
}
}, 1000);
非工作用户脚本是:
// ==UserScript==
// @name New Userscript
// @run-at document-start
// @match *
// ==/UserScript==
window.setInterval( () => {
const urlPatternToBlock = [
'https://search.google.com/'
];
for (const element of urlPatternToBlock) {
if (window.location.href.includes(urlPatternToBlock)) {
window.open("https://google.com/", "_self");
}
}
}, 1000);
我认为这段代码只能从控制台运行但不能从 suerscript 运行的原因是因为一些 301 重定向或其他一些重定向。
让我们一起,URL在Web 浏览器的URL 字段中保持不变,因此如果这里有重定向,它一定是难以捉摸的。
如何防止网络浏览器跟随特定网站中的重定向?
这个特定的网站与任何敏感信息(例如付款详细信息、密码或其他任何内容)没有任何关系,因此通常阻止其重定向不是问题。
更新
通过修改后的命令使用单个值的以下代码@match
有效,但它仍然没有解决我遇到的原始问题,该问题处理值数组。
// ==UserScript==
// @name google_single_value
// @run-at document-start
// @match https://search.google.com/search-console/*
// ==/UserScript==
if (window.location.href.includes('https://search.google.com')) {
window.open("https://google.com/", "_self");
};