【发布时间】:2021-03-14 04:05:36
【问题描述】:
我在 Tampermonkey 中使用此代码来防止某些脚本标签执行: https://stackoverflow.com/a/50024143/8849796
(function() {
'use strict';
window.stop();
const xhr = new XMLHttpRequest();
xhr.open('GET', window.location.href);
xhr.onload = () => {
var html = xhr.responseText
.replace(/<script\b[\s\S]*?<\/script>/g, s => {
// check if script tag should be replaced/deleted
if (s.includes('window.location')) {
return '';
} else {
return s;
}
});
document.open();
document.write(html);
document.close();
};
xhr.send();
})();
代码删除所有包含字符串'window.location'的脚本标签。
它工作得很好,只是我的浏览器的地址栏中没有显示图标图标。我正在使用 Vivaldi 浏览器。
此行为的原因可能是什么?
当我禁用 Tampermonkey 脚本时,图标会重新出现。但是我检查了 Tampermonkey 脚本并没有改变关于用于显示 favicon 的标签的任何内容。
【问题讨论】:
-
也许是 window.stop();正在阻止页面在加载之前加载网站图标。
-
对修改代码以使其不影响网站图标的显示有何建议?
标签: javascript html xmlhttprequest favicon tampermonkey