This repository was archived by the owner on Dec 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
61 lines (51 loc) · 1.81 KB
/
index.html
File metadata and controls
61 lines (51 loc) · 1.81 KB
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
<!DOCTYPE html><html><head><title>Live Page Code [background]</title>
<script>
window.addEventListener('load', function () {
if (typeof widget === 'undefined' || !widget.preferences) { storage = window.opera.scriptStorage; }
else { storage = widget.preferences; }
var v12 = (typeof opera.extension.tabGroups !== 'undefined');
function s2b(s) { return s === 'true' ? true : false; }
function log(){ if (s2b(storage['debugmode'])) opera.postError('[LivePageCode]: ' + Array.prototype.slice.call(arguments)); }
var button = opera.contexts.toolbar.createItem({
disabled: true,
title: 'Save live page code',
icon: 'icons/icon16.png',
onclick: function () {
var atab, aport;
log('toolbar button clicked.');
try { aport = atab = opera.extension.tabs.getFocused(); } catch (e) {log('active tab not found.');}
if (!atab) return;
if (v12) aport = atab.port;
aport.postMessage({
type: 'save-snapshot',
url: atab.url,
images: s2b(storage['saveimages']) || false,
b64: s2b(storage['encodeb64']) || true,
debug: s2b(storage['debugmode']) || false,
});
}
});
opera.contexts.toolbar.addItem(button);
function toggleButton (e) {
var atab = opera.extension.tabs.getFocused();
button.disabled = v12 ? !atab.port : !atab;
}
function setButtonState (port, state) {
if (v12) {
// in case source tab is active
if (port === opera.extension.tabs.getFocused().port) {
button.disabled = !state;
}
}
}
opera.extension.onconnect = function (e) {
setButtonState(e.source, false)
};
opera.extension.onmessage = function (e) {
if (e.data.type === 'status_enabled') setButtonState(e.source, true);
};
opera.extension.tabs.onfocus = toggleButton;
}, false);
</script>
</head>
</html>