-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent-script.js
70 lines (61 loc) · 2.09 KB
/
content-script.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
66
67
68
69
70
// TODO: Duplicate code
function safe_tags(str) {
return str.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
}
function safe_attrs(str) {
return safe_tags(str).replace(/"/g,'"').replace(/'<'/g,''');
}
// TODO: Duplicate code.
function pageName(url) {
return encodeURIComponent(url).replace(/\//g, '%2F');
}
let askCreateIframe = null;
// FIXME: duplicate code
function askCreate(url) {
askCreateIframe = document.createElement('iframe');
askCreateIframe.style.background = "pink";
askCreateIframe.style.height = "50%";
askCreateIframe.style.width = "100%";
askCreateIframe.style.position = "fixed";
askCreateIframe.style.top = "0px";
askCreateIframe.style.right = "0px";
askCreateIframe.style.zIndex = "9000000000000000001";
askCreateIframe.frameBorder = "none";
askCreateIframe.src = chrome.runtime.getURL('create-page.html?url=' + encodeURIComponent(url));
document.body.appendChild(askCreateIframe);
}
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
if(request.kind == "toggle") {
toggle(request.url);
} else if(request.kind == "askCreate") {
askCreate(request.url);
} else if(request.kind == "closePanel") {
iframe.style.width="0px";
} else if(request.kind == "closeAskCreate") {
askCreateIframe.parentNode.removeChild(askCreateIframe)
}
})
let iframe = null;
if(!window.browser) {
iframe = document.createElement('iframe');
iframe.style.background = "lightgray";
iframe.style.height = "100%";
iframe.style.width = "0px";
iframe.style.position = "fixed";
iframe.style.top = "0px";
iframe.style.right = "0px";
iframe.style.zIndex = "9000000000000000000";
iframe.frameBorder = "none";
window.addEventListener('load', () => {
document.body.appendChild(iframe);
});
}
function toggle(url) {
if(iframe.style.width == "0px"){
iframe.style.width="400px";
iframe.src = chrome.runtime.getURL("sidebar.html?url=") + encodeURIComponent(url)
}
else{
iframe.style.width="0px";
}
}