【问题标题】:have an issue with tampermonkey and javascript [duplicate]tampermonkey和javascript有问题[重复]
【发布时间】:2018-07-20 20:20:20
【问题描述】:

我想将 youtube 更改为正常样式。我的想法是,正常的叠加层最后有一个“&disable_polymer=true”。所以我尝试使用 tampermonkey 将 youtube 上的每个站点更改为末尾带有 &disable_polymer=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_polymer=true 放入一个循环中,因为 youtube.com/* 包含 youtube.com/&disable_polymer=true 所以该网站现在变为:“@987654321 @&disable_polymer=true&disable_polymer=true**&disable_polymer=true** 谁能帮我解决这个问题?请不要窃取我的想法

【问题讨论】:

    标签: javascript tampermonkey


    【解决方案1】:

    首先检查它是否包含该字符串..

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-11
      • 2013-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多