|
|
// 使用油猴脚本在页面加载前注入 CSS 来隐藏 favicon
// ==UserScript==
// @name 隐藏网页图标
// @Namespace http://tampermonkey.net/
// @Version 0.1
// @description 彻底隐藏网页图标,刷新不闪烁
// @author You
// @match *://*/*
// @run-before document-start
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 在文档开始前就注入样式,防止闪烁
var style = document.createElement('style');
style.textContent = 'link[rel="icon"], link[rel="shortcut icon"] { display: none !important; }';
if (document.head) {
document.head.insertBefore(style, document.head.firstChild);
} else {
// 如果 head 还不存在,监听 DOMContentLoaded
document.addEventListener('DOMContentLoaded', function() {
document.head.insertBefore(style, document.head.firstChild);
});
}
})();
// 另一种方法是直接移除 favicon 链接标签
// 在控制台或油猴脚本中使用:
var removeFavicon = function() {
var links = document.querySelectorAll('link[rel="icon"], link[rel="shortcut icon"]');
links.forEach(function(link) { link.remove(); });
};
// 立即执行一次
removeFavicon();
// 监听 DOM 变化持续移除
var observer = new MutationObserver(removeFavicon);
observer.observe(document.documentElement, { childList: true, subtree: true }); |
|