我想有一些代碼只對特定的URL集運行所有網站。對於我的生活,我無法弄清楚爲什麼每個網站點擊,它運行的代碼,並不限於我限制它的網站。的jQuery + Greasemonkey的:受影響,不僅限於「window.location.href.indexOf」
// ==UserScript==
// @name test
// @namespace test1
// @description test2
// @include https://*
// @version 1
// @grant none
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
// ==/UserScript==
$(document).ready(function()
{ if( (!window.location.href.indexOf("https://www.youtube.com") > -1)
&& (!window.location.href.indexOf("https://www.google.com") > -1)
)
{
alert("test");
}
});
window.location.href.indexOf(「https://開頭www.youtube.com「)始終爲真,如果匹配則爲false。 true and false總是> -1 – Shanimal