-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
65 lines (60 loc) · 2.27 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
var tabId = undefined;
var running = false;
var def_get_source = "function get_source(){ \
var url=location.href; \
if (location.protocol == 'file:') \
return; \
else \
var domain=location.protocol+'\/\/'+location.hostname+(location.port?':'+location.port:''); \
$.ajax({url:url,async:false,cache:false,dataType:'text',success:function(data){source=data}}); \
var css_src=source.match(/(href=(\"|\'))(?!http).+(\\.css)/g); \
if (css_src!=null){ \
$.each(css_src,function(){ \
var path=this.replace(/href=(\"|\')\\/?/,domain+'/'); \
$.ajax({url:path,async:false,cache:false,dataType:'text',success:function(data){source+=data}})});} \
var js_src=source.match(/(src=(\"|\'))(?!http).+(\\.js)/g); \
if (js_src!=null){ \
$.each(js_src,function(a,path){ \
var path=this.replace(/src=(\"|\')\\/?/,domain+'/'); \
$.ajax({url:path,async:false,cache:false,dataType:'text',success:function(data){source+=data}})});} \
return source \
}";
var code = def_get_source +
"var origin=get_source(); \
try{clearInterval(interval)}catch(e){} \
interval=setInterval(function(){ \
source=get_source(); \
if(origin!=source){origin=source;window.location.reload()} \
},2000)";
chrome.tabs.onUpdated.addListener(function() {
if (running){
chrome.tabs.executeScript(tabId, { file: "jquery-1.7.1.min.js" }, function() {
chrome.tabs.executeScript(tabId,
{code:code});
});
}
else{
chrome.browserAction.setIcon({path:"play.png"});
}
});
chrome.browserAction.onClicked.addListener(function() {
chrome.windows.getCurrent(function(win) {
chrome.tabs.getSelected(win.id, actionClicked);
});
});
function actionClicked(tab) {
if (running){
chrome.browserAction.setIcon({path:"play.png"});
chrome.tabs.executeScript(tabId, {code:"try{clearInterval(interval)}catch(e){}"});
running = false;
}
else{
tabId = tab.id;
chrome.browserAction.setIcon({path:"stop.png"});
chrome.tabs.executeScript(tabId, { file: "jquery-1.7.1.min.js" }, function() {
chrome.tabs.executeScript(tabId,
{code:code});
});
running = true;
}
}