forked from violentmonkey/violentmonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirm.js
50 lines (50 loc) · 1.52 KB
/
confirm.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
var $=document.getElementById.bind(document),M=$('msg'),I=$('bInstall'),data={},
B=$('bClose'),C=$('cClose'),T;
B.onclick=function(){window.close();};
C.onchange=function(){
chrome.runtime.sendMessage({cmd:'SetOption',data:{key:'closeAfterInstall',value:C.checked}});
};
I.onclick=function(){
chrome.runtime.sendMessage({
cmd:'ParseScript',
data:{
url:data.url,
from:data.from,
code:T.getValue(),
},
});
I.disabled=true;
};
chrome.runtime.onMessage.addListener(function(req,src,callback) {
var maps={
ShowMessage: function(o){
M.innerHTML=o.message;
if(callback) callback();
if(o.status>=0&&C.checked) window.close();
},
},f=maps[req.cmd];
if(f) f(req.data,src,callback);
return true;
});
chrome.runtime.sendMessage({cmd:'GetOption',data:'closeAfterInstall'},function(o){C.checked=!!o;});
initEditor(function(o){
T=o;o=location.search.slice(1);
o.split('&').forEach(function(i){
i.replace(/^([^=]*)=(.*)$/,function(r,g1,g2){data[g1]=decodeURIComponent(g2);});
});
function error(){M.innerHTML=_('msgErrorLoadingURL',[data.url]);}
if(!data.url) error(); else {
M.innerHTML=_('msgLoadingURL',[data.url]);
var x=new XMLHttpRequest();
x.open('GET',data.url,true);
x.onloadend=function(){
if((!this.status||this.status==200)&&this.responseText) {
M.innerHTML=_('msgLoadedJS',[data.url]);
T.setValueAndFocus(this.responseText);
I.disabled=false;
} else error();
};
x.send();
}
},{exit:B.onclick,readonly:true});
initCSS();initI18n(function(){document.body.classList.remove('hide');});