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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/*******************************************************************************
ηMatrix - a browser extension to black/white list requests.
Copyright (C) 2014-2019 Raymond Hill
Copyright (C) 2019 Alessio Vanni
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://libregit.org/heckyel/ematrix
uMatrix Home: https://github.com/gorhill/uMatrix
*/
/* global uDom */
'use strict';
/******************************************************************************/
(function() {
/******************************************************************************/
var cachedSettings = {};
/******************************************************************************/
function changeUserSettings(name, value) {
vAPI.messaging.send('settings.js', {
what: 'userSettings',
name: name,
value: value
});
}
/******************************************************************************/
function changeMatrixSwitch(name, state) {
vAPI.messaging.send('settings.js', {
what: 'setMatrixSwitch',
switchName: name,
state: state
});
}
/******************************************************************************/
function onChangeValueHandler(elem, setting, min, max) {
var oldVal = cachedSettings.userSettings[setting];
var newVal = Math.round(parseFloat(elem.value));
if ( typeof newVal !== 'number' ) {
newVal = oldVal;
} else {
newVal = Math.max(newVal, min);
newVal = Math.min(newVal, max);
}
elem.value = newVal;
if ( newVal !== oldVal ) {
changeUserSettings(setting, newVal);
}
}
/******************************************************************************/
function prepareToDie() {
onChangeValueHandler(
uDom.nodeFromId('deleteUnusedSessionCookiesAfter'),
'deleteUnusedSessionCookiesAfter',
15, 1440
);
onChangeValueHandler(
uDom.nodeFromId('clearBrowserCacheAfter'),
'clearBrowserCacheAfter',
15, 1440
);
}
/******************************************************************************/
function onInputChanged(ev) {
var target = ev.target;
switch ( target.id ) {
case 'displayTextSize':
changeUserSettings('displayTextSize', target.value + 'px');
break;
case 'clearBrowserCache':
case 'cloudStorageEnabled':
case 'collapseBlacklisted':
case 'collapseBlocked':
case 'colorBlindFriendly':
case 'deleteCookies':
case 'deleteLocalStorage':
case 'deleteUnusedSessionCookies':
case 'iconBadgeEnabled':
case 'processHyperlinkAuditing':
changeUserSettings(target.id, target.checked);
break;
case 'noMixedContent':
case 'noscriptTagsSpoofed':
case 'processReferer':
changeMatrixSwitch(
target.getAttribute('data-matrix-switch'),
target.checked
);
break;
case 'deleteUnusedSessionCookiesAfter':
onChangeValueHandler(target, 'deleteUnusedSessionCookiesAfter', 15, 1440);
break;
case 'clearBrowserCacheAfter':
onChangeValueHandler(target, 'clearBrowserCacheAfter', 15, 1440);
break;
case 'popupScopeLevel':
changeUserSettings('popupScopeLevel', target.value);
break;
default:
break;
}
switch ( target.id ) {
case 'collapseBlocked':
synchronizeWidgets();
break;
default:
break;
}
}
/******************************************************************************/
function synchronizeWidgets() {
var e1, e2;
e1 = uDom.nodeFromId('collapseBlocked');
e2 = uDom.nodeFromId('collapseBlacklisted');
if ( e1.checked ) {
e2.setAttribute('disabled', '');
} else {
e2.removeAttribute('disabled');
}
}
/******************************************************************************/
vAPI.messaging.send(
'settings.js',
{ what: 'getUserSettings' },
function onSettingsReceived(settings) {
// Cache copy
cachedSettings = settings;
var userSettings = settings.userSettings;
var matrixSwitches = settings.matrixSwitches;
uDom('[data-setting-bool]').forEach(function(elem){
elem.prop('checked', userSettings[elem.prop('id')] === true);
});
uDom('[data-matrix-switch]').forEach(function(elem){
var switchName = elem.attr('data-matrix-switch');
if ( typeof switchName === 'string' && switchName !== '' ) {
elem.prop('checked', matrixSwitches[switchName] === true);
}
});
uDom.nodeFromId('displayTextSize').value =
parseInt(userSettings.displayTextSize, 10) || 14;
uDom.nodeFromId('popupScopeLevel').value = userSettings.popupScopeLevel;
uDom.nodeFromId('deleteUnusedSessionCookiesAfter').value =
userSettings.deleteUnusedSessionCookiesAfter;
uDom.nodeFromId('clearBrowserCacheAfter').value =
userSettings.clearBrowserCacheAfter;
synchronizeWidgets();
document.addEventListener('change', onInputChanged);
// https://github.com/gorhill/httpswitchboard/issues/197
uDom(window).on('beforeunload', prepareToDie);
}
);
/******************************************************************************/
})();
|