61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/src/options.js:
--------------------------------------------------------------------------------
1 | {
2 | let addName = document.getElementById('addName'),
3 | noPattern = document.getElementById('noPattern'),
4 | noEye = document.getElementById('noEye'),
5 | list = document.getElementById('list'),
6 | whiteList = document.getElementById('white-list'),
7 | blackList = document.getElementById('black-list'),
8 | form = document.getElementById('form'),
9 | freeText = document.getElementById('free-text'),
10 | maxSafe = document.getElementById('max-safe'),
11 | closeOnClick = document.getElementById('close-on-click'),
12 | isFreeText = false;
13 | addName.focus();
14 | chrome.runtime.sendMessage({ r: 'getSettings' }, function (settings) {
15 | noPattern.checked = settings.noPattern;
16 | noEye.checked = settings.noEye;
17 | closeOnClick.checked = settings.closeOnClick;
18 | (settings.blackList ? blackList : whiteList).checked = true;
19 | maxSafe.value = settings.maxSafe;
20 | });
21 | chrome.runtime.onMessage.addListener(function (request) {
22 | if (request.r == 'urlListModified')
23 | CreateList();
24 | });
25 | noPattern.onclick = function () {
26 | chrome.runtime.sendMessage({ r: 'setNoPattern', toggle: this.checked });
27 | };
28 | noEye.onclick = function () {
29 | chrome.runtime.sendMessage({ r: 'setNoEye', toggle: this.checked });
30 | };
31 | whiteList.onclick = function () {
32 | chrome.runtime.sendMessage({ r: 'setBlackList', toggle: false });
33 | };
34 | blackList.onclick = function () {
35 | chrome.runtime.sendMessage({ r: 'setBlackList', toggle: true });
36 | };
37 | maxSafe.onchange = function () {
38 | chrome.runtime.sendMessage({ r: 'setMaxSafe', maxSafe: maxSafe.value });
39 | };
40 | closeOnClick.onclick = function () {
41 | chrome.runtime.sendMessage({ r: 'setCloseOnClick', toggle: this.checked });
42 | };
43 | window.onunload = () => maxSafe.blur();
44 | form.onsubmit = function () {
45 | let url = addName.value.trim().toLowerCase();
46 | if (!url.length) return;
47 | chrome.runtime.sendMessage({ r: 'urlListAdd', url: url }, CreateList);
48 | addName.value = '';
49 | return false;
50 | };
51 | list.onclick = ev => {
52 | let del = ev.target.closest('.delete');
53 | if (del) {
54 | let item = ev.target.closest('.item');
55 | chrome.runtime.sendMessage({ r: 'urlListRemove', index: item.ix }, CreateList);
56 | }
57 | };
58 | function CreateList() {
59 | chrome.runtime.sendMessage({ r: 'getUrlList' }, function (urlList) {
60 | list.innerHTML = '';
61 | if (isFreeText) {
62 | let textarea = document.createElement('textarea');
63 | textarea.style.width = '100%';
64 | textarea.rows = 15;
65 | textarea.value = urlList.join('\n');
66 | list.appendChild(textarea);
67 | textarea.onchange = function () {
68 | let text = textarea.value, lines = text.split('\n'), urls = [];
69 | for (let i = 0; i < lines.length; i++) {
70 | let url = lines[i].trim();
71 | if (url)
72 | urls.push(url);
73 | }
74 | chrome.runtime.sendMessage({ r: 'setUrlList', urlList: urls }, CreateList);
75 | };
76 | }
77 | else {
78 | for (let i = 0; i < urlList.length; i++) {
79 | let item = document.createElement('div');
80 | item.className = 'item';
81 | item.ix = i;
82 | item.innerHTML = `