diff --git a/asset-viewer.html b/asset-viewer.html new file mode 100644 index 000000000..3e1ed0beb --- /dev/null +++ b/asset-viewer.html @@ -0,0 +1,19 @@ + + + + +µBlock — Asset + + + +
+ + + + + diff --git a/js/3p-filters.js b/js/3p-filters.js index 52e32b71d..bc5619977 100644 --- a/js/3p-filters.js +++ b/js/3p-filters.js @@ -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); diff --git a/js/asset-viewer.js b/js/asset-viewer.js new file mode 100644 index 000000000..761495966 --- /dev/null +++ b/js/asset-viewer.js @@ -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); + +/******************************************************************************/ + +})(); diff --git a/js/messaging.js b/js/messaging.js index 14cb53116..d013e7ce3 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -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(); diff --git a/js/udom.js b/js/udom.js index 112bfd719..3f1a1c70a 100644 --- a/js/udom.js +++ b/js/udom.js @@ -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;