Skip to content

Commit

Permalink
fix #2067 (experimental) + support for hidden settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 3, 2016
1 parent 18d1c48 commit 8c3da95
Show file tree
Hide file tree
Showing 20 changed files with 437 additions and 49 deletions.
15 changes: 15 additions & 0 deletions platform/chromium/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

// For background page or non-background pages

/* exported objectAssign */

'use strict';

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

/******************************************************************************/

// As per MDN, Object.assign appeared first in Chromium 45.
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Browser_compatibility

var objectAssign = Object.assign || function(target, source) {
var keys = Object.keys(source);
for ( var i = 0, n = keys.length, key; i < n; i++ ) {
key = keys[i];
target[key] = source[key];
}
};

/******************************************************************************/

// https://github.com/gorhill/uBlock/issues/1070
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set#Browser_compatibility
// This polyfill is designed to fulfill *only* what uBlock Origin needs -- this
Expand Down
4 changes: 3 additions & 1 deletion platform/chromium/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,9 @@ vAPI.onLoadAllCompleted = function() {
µb.tabContextManager.commit(tab.id, tab.url);
µb.bindTabToPageStats(tab.id);
// https://github.com/chrisaljoudi/uBlock/issues/129
scriptStart(tab.id);
if ( /^https?:\/\//.test(tab.url) ) {
scriptStart(tab.id);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion platform/chromium/vapi-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ vAPI.messaging = {
if ( listeners === undefined ) {
return;
}
var pos = this.listeners.indexOf(callback);
var pos = listeners.indexOf(callback);
if ( pos === -1 ) {
console.error('Listener not found on channel "%s"', channelName);
return;
Expand Down
16 changes: 16 additions & 0 deletions platform/firefox/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,24 @@

// For background page or non-background pages

/* exported objectAssign */

'use strict';

/******************************************************************************/
/******************************************************************************/

// As per MDN, Object.assign appeared first in Firefox 34.
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Browser_compatibility

var objectAssign = Object.assign || function(target, source) {
var keys = Object.keys(source);
for ( var i = 0, n = keys.length, key; i < n; i++ ) {
key = keys[i];
target[key] = source[key];
}
};

/******************************************************************************/

// Patching for Pale Moon which does not implement ES6 Set/Map.
Expand Down
24 changes: 20 additions & 4 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
"message":"About",
"description":"appears as tab name in dashboard"
},
"advancedSettingsPageName":{
"message":"Advanced settings",
"description":"Title for the advanced settings page"
},
"popupPowerSwitchInfo":{
"message":"Click: disable\/enable uBlock₀ for this site.\n\nCtrl+click: disable uBlock₀ only on this page.",
"description":"English: Click: disable\/enable uBlock₀ for this site.\n\nCtrl+click: disable uBlock₀ only on this page."
Expand Down Expand Up @@ -204,8 +208,12 @@
"description": ""
},
"settingsAdvancedUserPrompt":{
"message":"I am an advanced user (<a href='https:\/\/github.com\/gorhill\/uBlock\/wiki\/Advanced-user-features'>Required reading<\/a>)",
"description":"English: "
"message":"I am an advanced user (<a href='https:\/\/github.com\/gorhill\/uBlock\/wiki\/Advanced-user-features'>required reading<\/a>)",
"description":""
},
"settingsAdvancedUserSettings":{
"message":"advanced settings",
"description":"For the tooltip of a link which gives access to advanced settings"
},
"settingsPrefetchingDisabledPrompt":{
"message":"Disable pre-fetching (to prevent any connection for blocked network requests)",
Expand Down Expand Up @@ -671,13 +679,21 @@
"message": "This device name:",
"description": "used as a prompt for the user to provide a custom device name"
},
"advancedSettingsWarning": {
"message": "Warning! Change these advanced settings at your own risk.",
"description": "A warning to users at the top of 'Advanced settings' page"
},
"genericSubmit": {
"message": "Submit",
"description": "for generic 'submit' buttons"
"description": "for generic 'Submit' buttons"
},
"genericApplyChanges": {
"message": "Apply changes",
"description": "for generic 'Apply changes' buttons"
},
"genericRevert": {
"message": "Revert",
"description": "for generic 'revert' buttons"
"description": "for generic 'Revert' buttons"
},
"genericBytes": {
"message": "bytes",
Expand Down
26 changes: 26 additions & 0 deletions src/advanced-settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title data-i18n="advancedSettingsPageName"></title>
<link rel="stylesheet" type="text/css" href="css/common.css">
<link rel="stylesheet" type="text/css" href="css/dashboard-common.css">
<link rel="stylesheet" type="text/css" href="css/advanced-settings.css">
<link rel="shortcut icon" type="image/png" href="img/icon_16.png"/>
</head>

<body>
<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>
<p>
<button id="advancedSettingsApply" class="custom important" type="button" disabled="true" data-i18n="genericApplyChanges"></button>&ensp;
<p><textarea id="advancedSettings" dir="auto" spellcheck="false"></textarea>

<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/udom.js"></script>
<script src="js/i18n.js"></script>
<script src="js/dashboard-common.js"></script>
<script src="js/advanced-settings.js"></script>

</body>
</html>
15 changes: 15 additions & 0 deletions src/css/advanced-settings.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
div > p:first-child {
margin-top: 0;
}
div > p:last-child {
margin-bottom: 0;
}
textarea {
box-sizing: border-box;
font-size: smaller;
height: 60vh;
text-align: left;
white-space: pre;
width: 100%;
word-wrap: normal;
}
9 changes: 6 additions & 3 deletions src/css/settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ ul#userSettings .subgroup > span {
font-size: larger;
font-weight: bold;
}
#advanced-user-enabled ~ a.fa {
display: none;
}
body.advancedUser #advanced-user-enabled ~ a.fa {
display: inline;
}
#localData > ul > li {
margin-top: 1em;
}
#localData > ul > li > ul > li:nth-of-type(2) {
font-family: monospace;
}
#experimental-enabled {
margin-top: 1em;
}
12 changes: 12 additions & 0 deletions src/document-suspended.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<a href=""></a>
<script src="js/vapi-common.js"></script>
<script src="js/vapi-client.js"></script>
<script src="js/document-suspended.js"></script>
</body>
</html>
114 changes: 114 additions & 0 deletions src/js/advanced-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*******************************************************************************
uBlock Origin - a browser extension to block requests.
Copyright (C) 2016 Raymond Hill
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://github.com/gorhill/uBlock
*/

/* global uDom */

'use strict';

/******************************************************************************/

(function() {

/******************************************************************************/

var messaging = vAPI.messaging;
var cachedData = '';
var rawAdvancedSettings = uDom.nodeFromId('advancedSettings');

/******************************************************************************/

var hashFromAdvancedSettings = function(raw) {
return raw.trim().replace(/\s+/g, '|');
};

/******************************************************************************/

// This is to give a visual hint that the content of user blacklist has changed.

var advancedSettingsChanged = (function () {
var timer = null;

var handler = function() {
timer = null;
var changed = hashFromAdvancedSettings(rawAdvancedSettings.value) !== cachedData;
uDom.nodeFromId('advancedSettingsApply').disabled = !changed;
};

return function() {
if ( timer !== null ) {
clearTimeout(timer);
}
timer = vAPI.setTimeout(handler, 100);
};
})();

/******************************************************************************/

function renderAdvancedSettings() {
var onRead = function(raw) {
cachedData = hashFromAdvancedSettings(raw);
var pretty = [],
whitespaces = ' ',
lines = raw.split('\n'),
max = 0,
pos,
i, n = lines.length;
for ( i = 0; i < n; i++ ) {
pos = lines[i].indexOf(' ');
if ( pos > max ) {
max = pos;
}
}
for ( i = 0; i < n; i++ ) {
pos = lines[i].indexOf(' ');
pretty.push(whitespaces.slice(0, max - pos) + lines[i]);
}
rawAdvancedSettings.value = pretty.join('\n') + '\n';
advancedSettingsChanged();
rawAdvancedSettings.focus();
};
messaging.send('dashboard', { what: 'readHiddenSettings' }, onRead);
}

/******************************************************************************/

var applyChanges = function() {
messaging.send(
'dashboard',
{
what: 'writeHiddenSettings',
content: rawAdvancedSettings.value
},
renderAdvancedSettings
);
};

/******************************************************************************/

// Handle user interaction
uDom('#advancedSettings').on('input', advancedSettingsChanged);
uDom('#advancedSettingsApply').on('click', applyChanges);

renderAdvancedSettings();

/******************************************************************************/

})();
8 changes: 8 additions & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ return {
webrtcIPAddressHidden: false
},

hiddenSettingsDefault: {
ignoreRedirectFilters: false,
ignoreScriptInjectFilters: false,
suspendTabsUntilReady: false
},
// This will be filled ASAP:
hiddenSettings: {},

// Features detection.
privacySettingsSupported: vAPI.browserSettings instanceof Object,
cloudStorageSupported: vAPI.cloud instanceof Object,
Expand Down
1 change: 1 addition & 0 deletions src/js/cosmetic-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ FilterContainer.prototype.createUserScriptRule = function(hash, hostname, select

FilterContainer.prototype.retrieveUserScripts = function(domain, hostname) {
if ( this.userScriptCount === 0 ) { return; }
if ( µb.hiddenSettings.ignoreScriptInjectFilters === true ) { return; }

var reng = µb.redirectEngine;
if ( !reng ) { return; }
Expand Down
8 changes: 4 additions & 4 deletions src/js/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
µBlock - a browser extension to block requests.
Copyright (C) 2014 Raymond Hill
uBlock Origin - a browser extension to block requests.
Copyright (C) 2014-2016 Raymond Hill
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
Expand All @@ -21,12 +21,12 @@

/* global uDom */

'use strict';

/******************************************************************************/

(function() {

'use strict';

/******************************************************************************/

var resizeFrame = function() {
Expand Down
Loading

0 comments on commit 8c3da95

Please sign in to comment.