Chrome Extension 加載遠端的 Script


Chrome Extension 中直接將 Script Tag 插入到網頁的 Head Tag 中
這樣做就可以做成只要更動遠方的 script 就可以更新 website

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"content_scripts": [ {
"js": [ "content.js" ],
"matches": [ "http://*/*" ]
} ],
"description": "This is a test description",
"icons": {
"48": "icon/48.png"
},
"name": "Tester",
"permissions": [ "http://*/*" ],
"version": "1.0"
}
1
2
3
4
5
6
(function(url) {
var script_tag = document.createElement("script");
script_tag.type = "text/javascript";
script_tag.src = url;
document.getElementsByTagName("head")[0].appendChild(script_tag);
})("https://github.com/[username]/[repo_name]/raw/[branch]/content.js")