Init from Manwell
This commit is contained in:
commit
4ec6d1e14f
25 changed files with 1369 additions and 0 deletions
46
content.js
Normal file
46
content.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
let myHead = document.createElement("custom-web");
|
||||
document.documentElement.appendChild(myHead);
|
||||
|
||||
chrome.runtime.sendMessage({
|
||||
action: "set-url",
|
||||
value: window.location.href
|
||||
});
|
||||
|
||||
File.loadAll().then(files => {
|
||||
let activeFiles = [];
|
||||
for(let i = 0; i < files.length; i++){
|
||||
let info = files[i].info;
|
||||
|
||||
if(info.links && info.links.length > 0) {
|
||||
let found = false;
|
||||
for(let l = 0; l < info.links.length && !found; l++) {
|
||||
let regexp = new RegExp(info.links[l]);
|
||||
found = window.location.href.match(regexp);
|
||||
}
|
||||
if(!found) continue;
|
||||
}
|
||||
activeFiles.push(info);
|
||||
if(!info.enabled) continue;
|
||||
if(info.type == "JS") {
|
||||
let jsContainer = document.createElement("script");
|
||||
jsContainer.textContent = info.content;
|
||||
myHead.appendChild(jsContainer);
|
||||
} else {
|
||||
let cssContainer = document.createElement("style");
|
||||
cssContainer.textContent = info.content;
|
||||
myHead.appendChild(cssContainer);
|
||||
}
|
||||
}
|
||||
let isTop = (window == window.top);
|
||||
|
||||
if(isTop){ // Only allow top to set URL
|
||||
chrome.runtime.sendMessage({
|
||||
action: "set-url",
|
||||
value: window.location.href
|
||||
});
|
||||
}
|
||||
chrome.runtime.sendMessage({
|
||||
action: "add-files",
|
||||
value: activeFiles
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue