我试图将谷歌收件箱“固定”页面的网站图标更改为图钉,以便一目了然地知道哪个选项卡是哪个。
我知道可能有扩展程序可以做到这一点,但我正在学习Javascript并尝试自己尝试。我使用“url.indexOf”命令成功更改了其他网站的图标,但是收件箱'Pinned'页面没有更改URL。所以我想编写JavaScript来查找单词“Pinned”,如果找到,则执行Favicon更改操作。这就是我的代码:
favico = function() {
this.is_changed = 0;
this.retry = 1000;
this.timerFindButtons = null;
this.list = [
"foo",
"bar"
];
}
favico.prototype.init = function(){
setTimeout(this.looping.bind(this), this.retry);
}
favico.prototype.looping = function(){
var head = document.getElementsByTagName('head')[0];
var links = head.querySelectorAll('link');
var eles = document.querySelectorAll("div");
for(var ii=0;ii<eles.length;ii++){
var foo = eles[ii].getAttribute('jstcache');
if(foo != null && foo.indexOf('1683') != -1){
var bar = eles[ii].innerText;
if(bar.indexOf('Pinned') != -1){
links[0].setAttribute('href', 'data:image/x-icon;base64,...');
this.is_changed = 1;}
else {
this.is_changed = 0;
links[0].setAttribute('href', '//ssl.gstatic.com/bt/C3341AA7A1A076756462EE2E5CD71C11/ic_product_inbox_16dp_r2_2x.png');}
}
}
setTimeout(this.looping.bind(this), this.retry);
}
var oo = new favico()
oo.init();
我做错了什么?非常感谢任何能够帮助我的人!
querySelectorAll()
,而应该使用querySelector
。 - Madara's Ghost