百度Favicon、谷歌Favicon
当前为
// ==UserScript==
// @name AC-百度Favicon
// @namespace BlockKafanTopicinGoogle
// @include /^https?://www.baidu.com/.*/
// @include /^https?://www.bing.com/.*/
// @include /^https?://encrypted.google.[^\/]+/
// @include /^https?://www.google.[^\/]+/
// @icon https://coding.net/u/zb227/p/zbImg/git/raw/master/img0/icon.jpg
// @author AC
// @version 0.4.0
// @connect https?://[\S]+
// @description 百度Favicon、谷歌Favicon
// @note 0.4.0 修复百度的各种图标丢失问题
// @grant none
// ==/UserScript==
//===================================================普通规则变量定义=======================================================
//===================================================主入口=======================================================
mo = new MutationObserver(function(allmutations) {
blockKafanBaidu();
});
targets = document.body;
var fatherName = new Array(
"c-container", //baidu
"rc", //google
"b_algo" //bing
);
mo.observe(targets, {'childList': true, 'subtree': true});
//document.addEventListener('DOMNodeInserted',blockKafanBaidu,false);
function blockKafanBaidu() {
var citeList;
if(location.href.indexOf(".baidu.com") > -1){
citeList = document.querySelectorAll(".c-showurl");
//之前取的是g,但这个标签在google中是最大的标签,导致谷歌页面卡住,所以先判断是baidu站点
}else if(location.href.indexOf(".google.com") > -1){
citeList = document.querySelectorAll("._Rm");
//之前取的是g,但这个标签在google中是最大的标签,导致谷歌页面卡住,所以先判断是baidu站点
}else if(location.href.indexOf(".bing.com") > -1){
citeList = document.querySelectorAll(".b_attribution>cite");
}
deal(citeList);
}
// 传入nodelist,然后查找两个列,查看是否一致,一致则删除
function deal(citeList){
for (var index = 0; index < citeList.length; index++) {
var url = replaceAll(citeList[index].innerHTML);
if(null == citeList[index].getAttribute("deal")){
deal_fatherNode(citeList[index], getFaviconUrl(url));
}
}
}
function deal_fatherNode(node, faviconUrl){
// faviconUrl = "http://"+faviconUrl+"/cdn.ico?defaulticon=http://soz.im/favicon.ico";
var curNode = node;
for(II = 0; II <= 5; II++){
curNode = curNode.parentNode;
if(isInUrlList(curNode.className)){
break;
}
}
if(II <= 5){
console.log(curNode.id);
var pos = curNode.innerHTML.indexOf("fav-url");
//他自己已经做了favicon了
if(pos > 0)
return;
//var imgHTML = "<img class=\"faviconT\" style=\"vertical-align:sub;\" src=\"http://g.soz.im/"+faviconUrl+"\" height=20 width=20> ";
var imgHTML = "<img class=\"faviconT\" style=\"vertical-align:sub;\" src=\"http://"+faviconUrl+"\" height=20 width=20 onerror=\"this.src='http://code.taobao.org/svn/zb227IMG/favicon.ico'\"/> ";
var insNode = curNode.firstChild;
if(insNode.length > 0){ //如果是false,那么就是正常节点,否则为文字节点
insNode = curNode.childNodes[1];
}
if(insNode.innerHTML.indexOf("class=\"faviconT") > 0) {
node.setAttribute("deal", "1"); return;
}
insNode.innerHTML = imgHTML + insNode.innerHTML;
node.setAttribute("deal", "1");
}
}
/*去掉网址中的<xxx>*/
function replaceAll(sbefore){
var send;
send = sbefore.replace(/<[^>]*>/g ,"");
return send;
}
function getFaviconUrl(citeUrl){
var citeUrl = citeUrl.replace(/https?:\/\//g,"");
var citeUrl = citeUrl.replace(/( |\/).*/g,"");
return citeUrl+"/favicon.ico";
}
function isInUrlList(url){
var leng = fatherName.length;
for(var i = 0; i < leng; i++){
if(url.indexOf(fatherName[i]) > 0){
return true;
}
}
return false;
}
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址