tampermonkey和javascript有问题



我想把youtube改成普通风格。我的想法是,普通的覆盖层,在末尾有一个"&disable_ppolymer=true"。所以我试着用tampermonkey把youtube上的每个网站都改成一个&disable_ppolymer=最后为true。这是我想到的:

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.youtube.com/*
// @grant        none
// ==/UserScript==
var currentLocation = window.location;
window.location.replace(window.location + "&disable_polymer=true");

但问题是,(你可以自己尝试(tampermonkey只会反复地把&disable_ppolymer在循环中为true,因为youtube.com/*包括youtube.com/&disable_ppolymer=true,因此网站现在变为:"http://www.youtube.com/&disable_ppolymer=true&disable_ppolymer=真**&disable_ppolymer=true**有人能帮我吗?请不要窃取我的想法

只需先检查它是否包含该字符串。。

if(!window.location.toString().toLowerCase().contains("disable_polymer")){
window.location.replace(window.location + "&disable_polymer=true")
}

最新更新