如何在 运行 脚本之前检查 URL 中的特定单词?
How to check for a specific word in the URL before running script?
我现在的脚本在URL栏
修改一个link
(function() {
'use strict';
location.replace(location.href.replace("www.reddit.com", "old.reddit.com"));
})();
我希望它检查 URL 是否在 运行 脚本的其余部分之前包含单词 "old"。我该怎么做?
您可以通过将 URL 视为普通字符串来检查单词 old
的索引。
if(location.href.indexOf('old') > -1) {
// do something
}
就这么简单
我现在的脚本在URL栏
修改一个link(function() {
'use strict';
location.replace(location.href.replace("www.reddit.com", "old.reddit.com"));
})();
我希望它检查 URL 是否在 运行 脚本的其余部分之前包含单词 "old"。我该怎么做?
您可以通过将 URL 视为普通字符串来检查单词 old
的索引。
if(location.href.indexOf('old') > -1) {
// do something
}
就这么简单