|
@@ -13,13 +13,56 @@ function addScr (data) {
|
|
|
document.body.appendChild(script)
|
|
document.body.appendChild(script)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function loadJS( url, callback ){
|
|
|
|
|
+ var script = document.createElement('script'),
|
|
|
|
|
+ fn = callback || function(){};
|
|
|
|
|
+ script.type = 'text/javascript';
|
|
|
|
|
+ //IE
|
|
|
|
|
+ if(script.readyState){
|
|
|
|
|
+ script.onreadystatechange = function(){
|
|
|
|
|
+ if( script.readyState == 'loaded' || script.readyState == 'complete' ){
|
|
|
|
|
+ script.onreadystatechange = null;
|
|
|
|
|
+ fn();
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //其他浏览器
|
|
|
|
|
+ script.onload = function(){
|
|
|
|
|
+ fn();
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+ script.src = url;
|
|
|
|
|
+ document.getElementsByTagName('head')[0].appendChild(script);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function loadCSS (url) {
|
|
|
|
|
+ var headObj = document.getElementsByTagName('head')[0];
|
|
|
|
|
+ var cssObj = document.createElement('link');
|
|
|
|
|
+ cssObj.rel = 'stylesheet';
|
|
|
|
|
+ cssObj.href = url;
|
|
|
|
|
+ headObj.appendChild(cssObj);
|
|
|
|
|
+}
|
|
|
chrome.runtime.sendMessage({name:"getData", url: window.location.href},function(dataTemp){
|
|
chrome.runtime.sendMessage({name:"getData", url: window.location.href},function(dataTemp){
|
|
|
// console.log(dataTemp)
|
|
// console.log(dataTemp)
|
|
|
if (!dataTemp) return
|
|
if (!dataTemp) return
|
|
|
let urlStr = window.location.href
|
|
let urlStr = window.location.href
|
|
|
dataTemp.forEach(element => {
|
|
dataTemp.forEach(element => {
|
|
|
if (new RegExp(element.url).test(urlStr)) {
|
|
if (new RegExp(element.url).test(urlStr)) {
|
|
|
- addScr(element.data)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (element.script) {
|
|
|
|
|
+ JSON.parse(element.script).forEach(element => {
|
|
|
|
|
+ console.log(`load: ${element}`)
|
|
|
|
|
+ loadJS(element)
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ if (element.style) {
|
|
|
|
|
+ JSON.parse(element.style).forEach(element => {
|
|
|
|
|
+ loadCSS(element)
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ addScr(element.data)
|
|
|
|
|
+ }, 0);
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|