更改页面时不重新加载内容脚本

时间:2018-09-16 08:47:47

标签: javascript google-chrome-extension

使用chrome扩展程序,我想在带有内容脚本的特定网站的菜单中放置一个按钮。它可以工作,但是当我单击重定向到该网站页面的链接时,直到我按F5键,该按钮才出现在页面上。 这是清单:

{
"name": "osu!PlayButton",
"version": "1.0",
"description": "Launch the game from the website !",
"manifest_version": 2,
"content_scripts": [{
    "js": ["putTheButton.js"],
    "matches": ["https://osu.ppy.sh/home/*","https://osu.ppy.sh/community/*","https://osu.ppy.sh/rankings/*","https://osu.ppy.sh/store/*","https://osu.ppy.sh/help/*","https://osu.ppy.sh/beatmapsets/*","https://osu.ppy.sh/beatmaps/*","https://osu.ppy.sh/users/*"]
 }]
}

还有putTheButton.js脚本:

var menuAvatar = document.querySelector(".nav2-header .nav2__col--avatar");

var theContainer = document.createElement("div");
theContainer.className = "nav2__col";

var thePlayButton = document.createElement("a");
thePlayButton.className = "nav2__button nav2__button--stadium";
thePlayButton.setAttribute("href","osu://");
thePlayButton.innerHTML = "Play !";

theContainer.appendChild(thePlayButton);
menuAvatar.insertAdjacentElement("beforebegin",theContainer);

感谢您的帮助!

0 个答案:

没有答案
相关问题