Firefox扩展程序,用于创建新图标或替换位置/地址栏中的现有图标

问题描述 投票:0回答:2

我想创建一个Firefox扩展,在地址栏中创建一个新图标,或用扩展名中指定的图标替换现有图标。

然后,添加一些javascript以仅在用户查看特定域时显示此自定义徽标。

如果这对于位置/地址栏不可行,则在状态栏上显示徽标是可以的(再次由仅在用户位于特定域时显示徽标的javascript驱动)。

可以这样做吗?

我不认为独自一人会解决我的问题。我希望只有当用户在特定域上时才能显示图标/徽标(例如xyz.com/testPage.html或abc.com/anotherTest.html)

javascript firefox firefox-addon greasemonkey favicon
2个回答
1
投票

你可以使用Greasemonkey做到这一点。这里有一个有效的快速脚本。

//create the icon
a=document.createElement("link");
a.setAttribute("rel", "icon");
a.setAttribute("href","http://www.google.com/favicon.ico");

//append the icon to the head
document.documentElement.firstChild.appendChild(a);

Greasemonkey's manual: (Adding scripts)

如果您尝试更改的图标的网站已经有一个,您将不得不做类似的事情

// get the head elements
head = document.documentElement.firstElementChild.childNodes;

//delete the existing favicon
for(i in head){
    if((head[i].rel == "shortcut icon")||(head[i].rel == "icon")){
         head.removeChild(head[i]);
    }
}

在设置新的图标之前,我无法让它工作。

有一个project to create a standard object for favicon manipulation应该工作,但不适合我。


0
投票

你可以改变DOM创建一个这样的链接元素:

<link rel="icon" type="image/png" href="/somepath/image.png" />
© www.soinside.com 2019 - 2024. All rights reserved.