在阻止Tampemonkey执行特定的内联脚本标记后,Favicon消失了 [英] Favicon disappears after preventing execution of a specific inline script tag by Tampemonkey
问题描述
我在Tampermonkey中使用此代码来防止某些脚本标记执行: https://stackoverflow.com/a/50024143/8849796
I use this code in Tampermonkey to prevent certain script tag from executing: 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'
的脚本标签.
The code removes all script tags that contain string 'window.location'
.
除了在我的浏览器中地址栏中未显示收藏夹图标之外,它都能正常工作.我正在使用Vivaldi浏览器.
It works perfectly except that the favicon icon is not displayed in my browser in address bar. I am using Vivaldi browser.
这种行为可能是什么原因?
What could be the cause of this behavior?
当我禁用Tampermonkey脚本时,图标图标重新出现.但是我检查了Tampermonkey脚本是否对用于显示收藏夹图标的标签没有任何更改.
When I disable the Tampermonkey script the favicon reappears. But I checked that the Tampermonkey script does not change anything regarding the tags used for displaying favicon.
推荐答案
我通过在问题代码后面使用以下代码设置图标图标 href
属性来解决此问题.
I solved it by setting the favicon href
attribute using the following code after the code in my question.
var favi=document.querySelector('[rel="shortcut icon"]');
favi.setAttribute("href",favi.getAttribute("href"));
这篇关于在阻止Tampemonkey执行特定的内联脚本标记后,Favicon消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!