Skip to content

Commit 8c3da95

Browse files
committed
fix gorhill#2067 (experimental) + support for hidden settings
1 parent 18d1c48 commit 8c3da95

20 files changed

Lines changed: 437 additions & 49 deletions

platform/chromium/polyfill.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
// For background page or non-background pages
2323

24+
/* exported objectAssign */
25+
2426
'use strict';
2527

2628
/******************************************************************************/
@@ -57,6 +59,19 @@ if ( String.prototype.endsWith instanceof Function === false ) {
5759

5860
/******************************************************************************/
5961

62+
// As per MDN, Object.assign appeared first in Chromium 45.
63+
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Browser_compatibility
64+
65+
var objectAssign = Object.assign || function(target, source) {
66+
var keys = Object.keys(source);
67+
for ( var i = 0, n = keys.length, key; i < n; i++ ) {
68+
key = keys[i];
69+
target[key] = source[key];
70+
}
71+
};
72+
73+
/******************************************************************************/
74+
6075
// https://github.com/gorhill/uBlock/issues/1070
6176
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#Browser_compatibility
6277
// This polyfill is designed to fulfill *only* what uBlock Origin needs -- this

platform/chromium/vapi-background.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,9 @@ vAPI.onLoadAllCompleted = function() {
11961196
µb.tabContextManager.commit(tab.id, tab.url);
11971197
µb.bindTabToPageStats(tab.id);
11981198
// https://github.com/chrisaljoudi/uBlock/issues/129
1199-
scriptStart(tab.id);
1199+
if ( /^https?:\/\//.test(tab.url) ) {
1200+
scriptStart(tab.id);
1201+
}
12001202
}
12011203
};
12021204

platform/chromium/vapi-client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ vAPI.messaging = {
468468
if ( listeners === undefined ) {
469469
return;
470470
}
471-
var pos = this.listeners.indexOf(callback);
471+
var pos = listeners.indexOf(callback);
472472
if ( pos === -1 ) {
473473
console.error('Listener not found on channel "%s"', channelName);
474474
return;

platform/firefox/polyfill.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,24 @@
2121

2222
// For background page or non-background pages
2323

24+
/* exported objectAssign */
25+
2426
'use strict';
2527

28+
/******************************************************************************/
29+
/******************************************************************************/
30+
31+
// As per MDN, Object.assign appeared first in Firefox 34.
32+
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Browser_compatibility
33+
34+
var objectAssign = Object.assign || function(target, source) {
35+
var keys = Object.keys(source);
36+
for ( var i = 0, n = keys.length, key; i < n; i++ ) {
37+
key = keys[i];
38+
target[key] = source[key];
39+
}
40+
};
41+
2642
/******************************************************************************/
2743

2844
// Patching for Pale Moon which does not implement ES6 Set/Map.

src/_locales/en/messages.json

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
"message":"About",
4040
"description":"appears as tab name in dashboard"
4141
},
42+
"advancedSettingsPageName":{
43+
"message":"Advanced settings",
44+
"description":"Title for the advanced settings page"
45+
},
4246
"popupPowerSwitchInfo":{
4347
"message":"Click: disable\/enable uBlock₀ for this site.\n\nCtrl+click: disable uBlock₀ only on this page.",
4448
"description":"English: Click: disable\/enable uBlock₀ for this site.\n\nCtrl+click: disable uBlock₀ only on this page."
@@ -204,8 +208,12 @@
204208
"description": ""
205209
},
206210
"settingsAdvancedUserPrompt":{
207-
"message":"I am an advanced user (<a href='https:\/\/github.com\/gorhill\/uBlock\/wiki\/Advanced-user-features'>Required reading<\/a>)",
208-
"description":"English: "
211+
"message":"I am an advanced user (<a href='https:\/\/github.com\/gorhill\/uBlock\/wiki\/Advanced-user-features'>required reading<\/a>)",
212+
"description":""
213+
},
214+
"settingsAdvancedUserSettings":{
215+
"message":"advanced settings",
216+
"description":"For the tooltip of a link which gives access to advanced settings"
209217
},
210218
"settingsPrefetchingDisabledPrompt":{
211219
"message":"Disable pre-fetching (to prevent any connection for blocked network requests)",
@@ -671,13 +679,21 @@
671679
"message": "This device name:",
672680
"description": "used as a prompt for the user to provide a custom device name"
673681
},
682+
"advancedSettingsWarning": {
683+
"message": "Warning! Change these advanced settings at your own risk.",
684+
"description": "A warning to users at the top of 'Advanced settings' page"
685+
},
674686
"genericSubmit": {
675687
"message": "Submit",
676-
"description": "for generic 'submit' buttons"
688+
"description": "for generic 'Submit' buttons"
689+
},
690+
"genericApplyChanges": {
691+
"message": "Apply changes",
692+
"description": "for generic 'Apply changes' buttons"
677693
},
678694
"genericRevert": {
679695
"message": "Revert",
680-
"description": "for generic 'revert' buttons"
696+
"description": "for generic 'Revert' buttons"
681697
},
682698
"genericBytes": {
683699
"message": "bytes",

src/advanced-settings.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title data-i18n="advancedSettingsPageName"></title>
6+
<link rel="stylesheet" type="text/css" href="css/common.css">
7+
<link rel="stylesheet" type="text/css" href="css/dashboard-common.css">
8+
<link rel="stylesheet" type="text/css" href="css/advanced-settings.css">
9+
<link rel="shortcut icon" type="image/png" href="img/icon_16.png"/>
10+
</head>
11+
12+
<body>
13+
<p><span data-i18n="advancedSettingsWarning"></span> <a class="fa info important" href="https://github.com/gorhill/uBlock/wiki/Advanced-user-features" target="_blank">&#xf05a;</a>
14+
<p>
15+
<button id="advancedSettingsApply" class="custom important" type="button" disabled="true" data-i18n="genericApplyChanges"></button>&ensp;
16+
<p><textarea id="advancedSettings" dir="auto" spellcheck="false"></textarea>
17+
18+
<script src="js/vapi-common.js"></script>
19+
<script src="js/vapi-client.js"></script>
20+
<script src="js/udom.js"></script>
21+
<script src="js/i18n.js"></script>
22+
<script src="js/dashboard-common.js"></script>
23+
<script src="js/advanced-settings.js"></script>
24+
25+
</body>
26+
</html>

src/css/advanced-settings.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
div > p:first-child {
2+
margin-top: 0;
3+
}
4+
div > p:last-child {
5+
margin-bottom: 0;
6+
}
7+
textarea {
8+
box-sizing: border-box;
9+
font-size: smaller;
10+
height: 60vh;
11+
text-align: left;
12+
white-space: pre;
13+
width: 100%;
14+
word-wrap: normal;
15+
}

src/css/settings.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@ ul#userSettings .subgroup > span {
1818
font-size: larger;
1919
font-weight: bold;
2020
}
21+
#advanced-user-enabled ~ a.fa {
22+
display: none;
23+
}
24+
body.advancedUser #advanced-user-enabled ~ a.fa {
25+
display: inline;
26+
}
2127
#localData > ul > li {
2228
margin-top: 1em;
2329
}
2430
#localData > ul > li > ul > li:nth-of-type(2) {
2531
font-family: monospace;
2632
}
27-
#experimental-enabled {
28-
margin-top: 1em;
29-
}

src/document-suspended.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title></title>
5+
</head>
6+
<body>
7+
<a href=""></a>
8+
<script src="js/vapi-common.js"></script>
9+
<script src="js/vapi-client.js"></script>
10+
<script src="js/document-suspended.js"></script>
11+
</body>
12+
</html>

src/js/advanced-settings.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*******************************************************************************
2+
3+
uBlock Origin - a browser extension to block requests.
4+
Copyright (C) 2016 Raymond Hill
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see {http://www.gnu.org/licenses/}.
18+
19+
Home: https://github.com/gorhill/uBlock
20+
*/
21+
22+
/* global uDom */
23+
24+
'use strict';
25+
26+
/******************************************************************************/
27+
28+
(function() {
29+
30+
/******************************************************************************/
31+
32+
var messaging = vAPI.messaging;
33+
var cachedData = '';
34+
var rawAdvancedSettings = uDom.nodeFromId('advancedSettings');
35+
36+
/******************************************************************************/
37+
38+
var hashFromAdvancedSettings = function(raw) {
39+
return raw.trim().replace(/\s+/g, '|');
40+
};
41+
42+
/******************************************************************************/
43+
44+
// This is to give a visual hint that the content of user blacklist has changed.
45+
46+
var advancedSettingsChanged = (function () {
47+
var timer = null;
48+
49+
var handler = function() {
50+
timer = null;
51+
var changed = hashFromAdvancedSettings(rawAdvancedSettings.value) !== cachedData;
52+
uDom.nodeFromId('advancedSettingsApply').disabled = !changed;
53+
};
54+
55+
return function() {
56+
if ( timer !== null ) {
57+
clearTimeout(timer);
58+
}
59+
timer = vAPI.setTimeout(handler, 100);
60+
};
61+
})();
62+
63+
/******************************************************************************/
64+
65+
function renderAdvancedSettings() {
66+
var onRead = function(raw) {
67+
cachedData = hashFromAdvancedSettings(raw);
68+
var pretty = [],
69+
whitespaces = ' ',
70+
lines = raw.split('\n'),
71+
max = 0,
72+
pos,
73+
i, n = lines.length;
74+
for ( i = 0; i < n; i++ ) {
75+
pos = lines[i].indexOf(' ');
76+
if ( pos > max ) {
77+
max = pos;
78+
}
79+
}
80+
for ( i = 0; i < n; i++ ) {
81+
pos = lines[i].indexOf(' ');
82+
pretty.push(whitespaces.slice(0, max - pos) + lines[i]);
83+
}
84+
rawAdvancedSettings.value = pretty.join('\n') + '\n';
85+
advancedSettingsChanged();
86+
rawAdvancedSettings.focus();
87+
};
88+
messaging.send('dashboard', { what: 'readHiddenSettings' }, onRead);
89+
}
90+
91+
/******************************************************************************/
92+
93+
var applyChanges = function() {
94+
messaging.send(
95+
'dashboard',
96+
{
97+
what: 'writeHiddenSettings',
98+
content: rawAdvancedSettings.value
99+
},
100+
renderAdvancedSettings
101+
);
102+
};
103+
104+
/******************************************************************************/
105+
106+
// Handle user interaction
107+
uDom('#advancedSettings').on('input', advancedSettingsChanged);
108+
uDom('#advancedSettingsApply').on('click', applyChanges);
109+
110+
renderAdvancedSettings();
111+
112+
/******************************************************************************/
113+
114+
})();

0 commit comments

Comments
 (0)