1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 04:49:12 +02:00

this fixes #51

This commit is contained in:
gorhill 2014-07-09 16:03:25 -04:00
parent 39ca1534a8
commit a6adad40cc
5 changed files with 98 additions and 15 deletions

19
asset-viewer.html Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>µBlock — Asset</title>
<style>
#content {
font: 12px monospace;
white-space: pre;
}
</style>
</head>
<body>
<div id="content"></div>
<script src="js/udom.js"></script>
<script src="js/messaging-client.js"></script>
<script src="js/asset-viewer.js"></script>
</body>
</html>

View File

@ -50,13 +50,13 @@ messaging.listen(onMessage);
/******************************************************************************/
function getµb() {
var getµb = function() {
return chrome.extension.getBackgroundPage().µBlock;
}
};
/******************************************************************************/
function renderNumber(value) {
var renderNumber = function(value) {
// TODO: localization
if ( +value > 1000 ) {
value = value.toString();
@ -67,13 +67,13 @@ function renderNumber(value) {
}
}
return value;
}
};
/******************************************************************************/
// TODO: get rid of background page dependencies
function renderBlacklists() {
var renderBlacklists = function() {
// empty list first
uDom('#blacklists .blacklistDetails').remove();
@ -145,14 +145,14 @@ function renderBlacklists() {
);
selectedBlacklistsHash = getSelectedBlacklistsHash();
}
};
/******************************************************************************/
// Create a hash so that we know whether the selection of preset blacklists
// has changed.
function getSelectedBlacklistsHash() {
var getSelectedBlacklistsHash = function() {
var hash = '';
var inputs = uDom('#blacklists .blacklistDetails > input');
var i = inputs.length();
@ -163,22 +163,32 @@ function getSelectedBlacklistsHash() {
hash += uDom('#parseAllABPHideFilters').prop('checked').toString();
return hash;
}
};
/******************************************************************************/
// This is to give a visual hint that the selection of blacklists has changed.
function selectedBlacklistsChanged() {
var selectedBlacklistsChanged = function() {
uDom('#blacklistsApply').prop(
'disabled',
getSelectedBlacklistsHash() === selectedBlacklistsHash
);
}
};
/******************************************************************************/
function blacklistsApplyHandler() {
var onListLinkClicked = function(ev) {
messaging.tell({
what: 'gotoExtensionURL',
url: 'asset-viewer.html?url=' + uDom(this).attr('href')
});
ev.preventDefault();
};
/******************************************************************************/
var blacklistsApplyHandler = function() {
var newHash = getSelectedBlacklistsHash();
if ( newHash === selectedBlacklistsHash ) {
return;
@ -200,24 +210,25 @@ function blacklistsApplyHandler() {
switches: switches
});
uDom('#blacklistsApply').attr('disabled', true );
}
};
/******************************************************************************/
function abpHideFiltersCheckboxChanged() {
var abpHideFiltersCheckboxChanged = function() {
messaging.tell({
what: 'userSettings',
name: 'parseAllABPHideFilters',
value: this.checked
});
selectedBlacklistsChanged();
}
};
/******************************************************************************/
uDom.onLoad(function() {
// Handle user interaction
uDom('#blacklists').on('change', '.blacklistDetails', selectedBlacklistsChanged);
uDom('#blacklists').on('click', '.blacklistDetails a', onListLinkClicked);
uDom('#blacklistsApply').on('click', blacklistsApplyHandler);
uDom('#parseAllABPHideFilters').on('change', abpHideFiltersCheckboxChanged);

50
js/asset-viewer.js Normal file
View File

@ -0,0 +1,50 @@
/*******************************************************************************
µBlock - a Chromium browser extension to block requests.
Copyright (C) 2014 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 chrome, messaging, uDom */
/******************************************************************************/
(function() {
/******************************************************************************/
messaging.start('asset-viewer.js');
/******************************************************************************/
var onAssetContentReceived = function(details) {
uDom('#content').html(details && (details.content || ''));
};
/******************************************************************************/
var q = window.location.search;
var matches = q.match(/^\?url=([^&]+)/);
if ( !matches || matches.length !== 2 ) {
return;
}
messaging.ask({ what : 'getAssetContent', url: matches[1] }, onAssetContentReceived);
/******************************************************************************/
})();

View File

@ -137,6 +137,9 @@ var onMessage = function(request, port) {
function defaultHandler(request, sender, callback) {
// Async
switch ( request.what ) {
case 'getAssetContent':
return µBlock.assets.get(request.url, callback);
case 'loadUbiquitousAllowRules':
return µBlock.loadUbiquitousWhitelists();

View File

@ -441,7 +441,7 @@ var makeEventHandler = function(context, selector, callback) {
i = candidates.length;
while ( i-- ) {
if ( candidates[i] === node ) {
return callback.bind(node).call(event);
return callback.call(node, event);
}
}
node = node.parentNode;