-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathadvanced-options.js
144 lines (131 loc) · 6.46 KB
/
advanced-options.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
(window => {
const document = window.document;
const chrome = window.chrome;
const _m = chrome.i18n.getMessage;
const __m = _m;
document.addEventListener('DOMContentLoaded', () => {
document.title = `${_m('extName')} ${_m('advancedOptions')}`;
const customIconPreview = $('custom-icon-preview').firstElementChild;
const canvas = document.createElement('canvas');
canvas.width = canvas.height = 19;
const ctx = canvas.getContext('2d');
let dontLoad = true;
customIconPreview.onload = () => {
if (dontLoad) {
dontLoad = false;
return;
}
ctx.clearRect(0, 0, 19, 19);
ctx.drawImage(customIconPreview, 0, 0, 19, 19);
const imageData = ctx.getImageData(0, 0, 19, 19);
chrome.action.setIcon({
imageData: imageData
});
localStorage.customIcon = JSON.stringify(imageData.data);
};
if (localStorage.customIcon) {
const customIcon = JSON.parse(localStorage.customIcon);
const imageData = ctx.getImageData(0, 0, 19, 19);
for (const key in customIcon) imageData.data[key] = customIcon[key];
ctx.putImageData(imageData, 0, 0);
customIconPreview.src = canvas.toDataURL();
}
const customIconFile = $('custom-icon-file');
customIconFile.addEventListener('change', function () {
const files = this.files;
let reader;
if (files && files.length) {
const file = files[0];
if (/image\/[a-z]+/i.test(file.type)) {
reader = new FileReader();
reader.onload = e => {
const result = e.target.result;
customIconPreview.src = result;
};
reader.readAsDataURL(files[0]);
} else {
alert('Not an image. Try another one.');
}
}
});
const defaultIconButton = $('default-icon-button');
defaultIconButton.addEventListener('click', () => {
delete localStorage.customIcon;
chrome.action.setIcon({
path: 'icon.png'
});
dontLoad = true;
customIconPreview.src = 'icon.png';
});
const customSeparatorColor = $('custom-separator-color');
if (localStorage.separatorcolor) customSeparatorColor.value = localStorage.separatorcolor;
customSeparatorColor.addEventListener('change', () => {
localStorage.separatorcolor = customSeparatorColor.value;
});
const customSeparatorTitle = $('custom-separator-title');
if (localStorage.separatorTitle) {
customSeparatorTitle.value = localStorage.separatorTitle;
} else {
customSeparatorTitle.value = '|';
}
customSeparatorTitle.addEventListener('change', () => {
localStorage.separatorTitle = customSeparatorTitle.value;
});
const customSeparatorUrl = $('custom-separator-url');
if (localStorage.separatorUrl) {
customSeparatorUrl.value = localStorage.separatorUrl;
} else {
customSeparatorUrl.value = 'http://separatethis.com/';
}
customSeparatorUrl.addEventListener('change', () => {
localStorage.separatorUrl = customSeparatorUrl.value;
});
const customSeparatorString = $('custom-separator-string');
if (localStorage.separatorString) {
customSeparatorString.value = localStorage.separatorString;
} else {
customSeparatorString.value = "separatethis.com;"
}
customSeparatorString.addEventListener('change', () => {
localStorage.separatorString = customSeparatorString.value;
});
const textareaUserstyle = $('userstyle');
if (localStorage.userstyle) textareaUserstyle.value = localStorage.userstyle;
CodeMirror.fromTextArea(textareaUserstyle, {
onChange: c => {
localStorage.userstyle = c.getValue();
}
});
$('reset-button').addEventListener('click', () => {
localStorage.clear();
alert('vBookmarks has been reset.');
location.reload();
}, false);
window.onerror = function () {
chrome.extension.sendRequest({
error: [].slice.call(arguments)
})
};
document.getElementById('small-options').innerText = __m('options');
document.getElementById('ext-name').innerText = __m('extName');
document.getElementById('advanced-options').innerText = __m('advancedOptions');
document.getElementById('custom-icon').innerText = __m('customIcon');
document.getElementById('custom-icon-description').innerText = __m('customIconDescription');
document.getElementById('default-icon-button').innerText = __m('defaultIconButton');
document.getElementById('default-icon-button-or').innerText = __m('defaultIconButtonOr');
document.getElementById('custom-styles').innerText = __m('customStyles');
document.getElementById('custom-separator-color-description').innerText = __m('customSeparatorColorDescription');
document.getElementById('custom-separator-title-description').innerText = __m('customSeparatorTitleDescription');
document.getElementById('custom-separator-url-description').innerText = __m('customSeparatorUrlDescription');
document.getElementById('custom-separator-string-description').innerText = __m('customSeparatorStringDescription');
document.getElementById('custom-styles-description').innerText = __m('customStylesDescription');
document.getElementById('reset-settings').innerText = __m('resetSettings');
document.getElementById('reset-settings-description').innerText = __m('resetSettingsDescription');
document.getElementById('reset-button').innerText = __m('resetButton');
document.getElementById('options-footer-1').innerHTML = '<p>Thanks: Lim Chee Aun</p>';
document.getElementById('options-footer-3').innerHTML =
'<a href="https://github.com/windviki">Follow me @windviki on Github</a>';
document.getElementById('options-footer-4').innerHTML =
'<a href="https://windviki.github.io/vBookmarks/">vBookmarks Mainpage (docs and source code)</a>';
});
})(window);