mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
this fixes #51
This commit is contained in:
parent
39ca1534a8
commit
a6adad40cc
19
asset-viewer.html
Normal file
19
asset-viewer.html
Normal 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>
|
@ -50,13 +50,13 @@ messaging.listen(onMessage);
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
function getµb() {
|
var getµb = function() {
|
||||||
return chrome.extension.getBackgroundPage().µBlock;
|
return chrome.extension.getBackgroundPage().µBlock;
|
||||||
}
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
function renderNumber(value) {
|
var renderNumber = function(value) {
|
||||||
// TODO: localization
|
// TODO: localization
|
||||||
if ( +value > 1000 ) {
|
if ( +value > 1000 ) {
|
||||||
value = value.toString();
|
value = value.toString();
|
||||||
@ -67,13 +67,13 @@ function renderNumber(value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// TODO: get rid of background page dependencies
|
// TODO: get rid of background page dependencies
|
||||||
|
|
||||||
function renderBlacklists() {
|
var renderBlacklists = function() {
|
||||||
// empty list first
|
// empty list first
|
||||||
uDom('#blacklists .blacklistDetails').remove();
|
uDom('#blacklists .blacklistDetails').remove();
|
||||||
|
|
||||||
@ -145,14 +145,14 @@ function renderBlacklists() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
selectedBlacklistsHash = getSelectedBlacklistsHash();
|
selectedBlacklistsHash = getSelectedBlacklistsHash();
|
||||||
}
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// Create a hash so that we know whether the selection of preset blacklists
|
// Create a hash so that we know whether the selection of preset blacklists
|
||||||
// has changed.
|
// has changed.
|
||||||
|
|
||||||
function getSelectedBlacklistsHash() {
|
var getSelectedBlacklistsHash = function() {
|
||||||
var hash = '';
|
var hash = '';
|
||||||
var inputs = uDom('#blacklists .blacklistDetails > input');
|
var inputs = uDom('#blacklists .blacklistDetails > input');
|
||||||
var i = inputs.length();
|
var i = inputs.length();
|
||||||
@ -163,22 +163,32 @@ function getSelectedBlacklistsHash() {
|
|||||||
hash += uDom('#parseAllABPHideFilters').prop('checked').toString();
|
hash += uDom('#parseAllABPHideFilters').prop('checked').toString();
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// This is to give a visual hint that the selection of blacklists has changed.
|
// This is to give a visual hint that the selection of blacklists has changed.
|
||||||
|
|
||||||
function selectedBlacklistsChanged() {
|
var selectedBlacklistsChanged = function() {
|
||||||
uDom('#blacklistsApply').prop(
|
uDom('#blacklistsApply').prop(
|
||||||
'disabled',
|
'disabled',
|
||||||
getSelectedBlacklistsHash() === selectedBlacklistsHash
|
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();
|
var newHash = getSelectedBlacklistsHash();
|
||||||
if ( newHash === selectedBlacklistsHash ) {
|
if ( newHash === selectedBlacklistsHash ) {
|
||||||
return;
|
return;
|
||||||
@ -200,24 +210,25 @@ function blacklistsApplyHandler() {
|
|||||||
switches: switches
|
switches: switches
|
||||||
});
|
});
|
||||||
uDom('#blacklistsApply').attr('disabled', true );
|
uDom('#blacklistsApply').attr('disabled', true );
|
||||||
}
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
function abpHideFiltersCheckboxChanged() {
|
var abpHideFiltersCheckboxChanged = function() {
|
||||||
messaging.tell({
|
messaging.tell({
|
||||||
what: 'userSettings',
|
what: 'userSettings',
|
||||||
name: 'parseAllABPHideFilters',
|
name: 'parseAllABPHideFilters',
|
||||||
value: this.checked
|
value: this.checked
|
||||||
});
|
});
|
||||||
selectedBlacklistsChanged();
|
selectedBlacklistsChanged();
|
||||||
}
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
uDom.onLoad(function() {
|
uDom.onLoad(function() {
|
||||||
// Handle user interaction
|
// Handle user interaction
|
||||||
uDom('#blacklists').on('change', '.blacklistDetails', selectedBlacklistsChanged);
|
uDom('#blacklists').on('change', '.blacklistDetails', selectedBlacklistsChanged);
|
||||||
|
uDom('#blacklists').on('click', '.blacklistDetails a', onListLinkClicked);
|
||||||
uDom('#blacklistsApply').on('click', blacklistsApplyHandler);
|
uDom('#blacklistsApply').on('click', blacklistsApplyHandler);
|
||||||
uDom('#parseAllABPHideFilters').on('change', abpHideFiltersCheckboxChanged);
|
uDom('#parseAllABPHideFilters').on('change', abpHideFiltersCheckboxChanged);
|
||||||
|
|
||||||
|
50
js/asset-viewer.js
Normal file
50
js/asset-viewer.js
Normal 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);
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
})();
|
@ -137,6 +137,9 @@ var onMessage = function(request, port) {
|
|||||||
function defaultHandler(request, sender, callback) {
|
function defaultHandler(request, sender, callback) {
|
||||||
// Async
|
// Async
|
||||||
switch ( request.what ) {
|
switch ( request.what ) {
|
||||||
|
case 'getAssetContent':
|
||||||
|
return µBlock.assets.get(request.url, callback);
|
||||||
|
|
||||||
case 'loadUbiquitousAllowRules':
|
case 'loadUbiquitousAllowRules':
|
||||||
return µBlock.loadUbiquitousWhitelists();
|
return µBlock.loadUbiquitousWhitelists();
|
||||||
|
|
||||||
|
@ -441,7 +441,7 @@ var makeEventHandler = function(context, selector, callback) {
|
|||||||
i = candidates.length;
|
i = candidates.length;
|
||||||
while ( i-- ) {
|
while ( i-- ) {
|
||||||
if ( candidates[i] === node ) {
|
if ( candidates[i] === node ) {
|
||||||
return callback.bind(node).call(event);
|
return callback.call(node, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node = node.parentNode;
|
node = node.parentNode;
|
||||||
|
Loading…
Reference in New Issue
Block a user