2014-06-24 00:42:43 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
µ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
|
|
|
|
*/
|
|
|
|
|
2014-11-16 14:09:28 +01:00
|
|
|
/* global µBlock, vAPI, YaMD5 */
|
2014-11-16 03:21:13 +01:00
|
|
|
|
2014-10-17 21:44:19 +02:00
|
|
|
/******************************************************************************/
|
2014-11-16 14:09:28 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-11-16 15:49:55 +01:00
|
|
|
// Default handler
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2014-11-16 15:49:55 +01:00
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-11-16 15:49:55 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
2014-10-17 21:44:19 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
2014-11-16 15:49:55 +01:00
|
|
|
// Async
|
2014-10-17 21:44:19 +02:00
|
|
|
switch ( request.what ) {
|
|
|
|
case 'getAssetContent':
|
2014-12-17 14:04:21 +01:00
|
|
|
// https://github.com/gorhill/uBlock/issues/417
|
|
|
|
µb.assets.get(request.url, callback);
|
2014-10-17 21:44:19 +02:00
|
|
|
return;
|
|
|
|
|
2014-11-16 15:49:55 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2014-10-17 21:44:19 +02:00
|
|
|
case 'contextMenuEvent':
|
|
|
|
µb.contextMenuClientX = request.clientX;
|
|
|
|
µb.contextMenuClientY = request.clientY;
|
|
|
|
break;
|
|
|
|
|
2014-12-01 17:25:33 +01:00
|
|
|
case 'getAppData':
|
|
|
|
response = vAPI.app;
|
|
|
|
break;
|
|
|
|
|
2014-10-17 21:44:19 +02:00
|
|
|
case 'getUserSettings':
|
2014-11-16 15:49:55 +01:00
|
|
|
response = µb.userSettings;
|
2014-10-17 21:44:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'gotoURL':
|
|
|
|
vAPI.tabs.open(request.details);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'reloadAllFilters':
|
|
|
|
µb.reloadPresetBlacklists(request.switches, request.update);
|
|
|
|
break;
|
|
|
|
|
2015-01-06 14:01:15 +01:00
|
|
|
case 'reloadTab':
|
2015-01-20 00:42:58 +01:00
|
|
|
if ( vAPI.isNoTabId(request.tabId) === false ) {
|
|
|
|
vAPI.tabs.reload(request.tabId);
|
|
|
|
}
|
2015-01-06 14:01:15 +01:00
|
|
|
break;
|
|
|
|
|
2014-10-17 21:44:19 +02:00
|
|
|
case 'userSettings':
|
2014-11-16 15:49:55 +01:00
|
|
|
response = µb.changeUserSettings(request.name, request.value);
|
2014-10-17 21:44:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-11-16 14:09:28 +01:00
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-10-17 21:44:19 +02:00
|
|
|
}
|
2014-11-16 15:49:55 +01:00
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
|
|
|
vAPI.messaging.setup(onMessage);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
2014-10-17 21:44:19 +02:00
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
// popup.js
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var µb = µBlock;
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-12-30 22:36:29 +01:00
|
|
|
var getHostnameDict = function(hostnameToCountMap) {
|
|
|
|
var r = {};
|
2015-01-08 16:37:19 +01:00
|
|
|
var domainFromHostname = µb.URI.domainFromHostname;
|
2014-12-30 22:36:29 +01:00
|
|
|
var domain, counts;
|
|
|
|
for ( var hostname in hostnameToCountMap ) {
|
|
|
|
if ( hostnameToCountMap.hasOwnProperty(hostname) === false ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ( r.hasOwnProperty(hostname) ) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-11 15:47:14 +01:00
|
|
|
domain = domainFromHostname(hostname) || hostname;
|
2014-12-30 22:36:29 +01:00
|
|
|
counts = hostnameToCountMap[domain] || 0;
|
|
|
|
r[domain] = {
|
|
|
|
domain: domain,
|
|
|
|
blockCount: counts & 0xFFFF,
|
|
|
|
allowCount: counts >>> 16 & 0xFFFF
|
|
|
|
};
|
|
|
|
if ( hostname === domain ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
counts = hostnameToCountMap[hostname] || 0;
|
|
|
|
r[hostname] = {
|
|
|
|
domain: domain,
|
|
|
|
blockCount: counts & 0xFFFF,
|
|
|
|
allowCount: counts >>> 16 & 0xFFFF
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var getDynamicFilterRules = function(srcHostname, desHostnames) {
|
2014-12-28 16:07:43 +01:00
|
|
|
var r = {};
|
|
|
|
var dFiltering = µb.dynamicNetFilteringEngine;
|
2014-12-30 22:36:29 +01:00
|
|
|
r['/ * image'] = dFiltering.evaluateCellZY('*', '*', 'image').toFilterString();
|
|
|
|
r['/ * inline-script'] = dFiltering.evaluateCellZY('*', '*', 'inline-script').toFilterString();
|
|
|
|
r['/ * 1p-script'] = dFiltering.evaluateCellZY('*', '*', '1p-script').toFilterString();
|
|
|
|
r['/ * 3p-script'] = dFiltering.evaluateCellZY('*', '*', '3p-script').toFilterString();
|
|
|
|
r['/ * 3p-frame'] = dFiltering.evaluateCellZY('*', '*', '3p-frame').toFilterString();
|
|
|
|
if ( typeof srcHostname !== 'string' ) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
r['. * image'] = dFiltering.evaluateCellZY(srcHostname, '*', 'image').toFilterString();
|
|
|
|
r['. * inline-script'] = dFiltering.evaluateCellZY(srcHostname, '*', 'inline-script').toFilterString();
|
|
|
|
r['. * 1p-script'] = dFiltering.evaluateCellZY(srcHostname, '*', '1p-script').toFilterString();
|
|
|
|
r['. * 3p-script'] = dFiltering.evaluateCellZY(srcHostname, '*', '3p-script').toFilterString();
|
|
|
|
r['. * 3p-frame'] = dFiltering.evaluateCellZY(srcHostname, '*', '3p-frame').toFilterString();
|
|
|
|
|
|
|
|
for ( var desHostname in desHostnames ) {
|
|
|
|
if ( desHostnames.hasOwnProperty(desHostname) ) {
|
|
|
|
r['/ ' + desHostname + ' *'] = dFiltering.evaluateCellZY('*', desHostname, '*').toFilterString();
|
|
|
|
r['. ' + desHostname + ' *'] = dFiltering.evaluateCellZY(srcHostname, desHostname, '*').toFilterString();
|
|
|
|
}
|
|
|
|
}
|
2014-12-28 16:07:43 +01:00
|
|
|
return r;
|
2014-10-06 20:02:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-12-30 22:36:29 +01:00
|
|
|
var getStats = function(tabId) {
|
2014-06-24 00:42:43 +02:00
|
|
|
var r = {
|
2015-01-06 17:44:06 +01:00
|
|
|
advancedUserEnabled: µb.userSettings.advancedUserEnabled,
|
2014-12-01 17:25:33 +01:00
|
|
|
appName: vAPI.app.name,
|
|
|
|
appVersion: vAPI.app.version,
|
2015-01-06 17:44:06 +01:00
|
|
|
cosmeticFilteringSwitch: false,
|
|
|
|
dfEnabled: µb.userSettings.dynamicFilteringEnabled,
|
2014-06-24 00:42:43 +02:00
|
|
|
globalAllowedRequestCount: µb.localSettings.allowedRequestCount,
|
2015-01-06 17:44:06 +01:00
|
|
|
globalBlockedRequestCount: µb.localSettings.blockedRequestCount,
|
|
|
|
netFilteringSwitch: false,
|
2014-06-24 00:42:43 +02:00
|
|
|
pageURL: '',
|
|
|
|
pageAllowedRequestCount: 0,
|
2015-01-06 17:44:06 +01:00
|
|
|
pageBlockedRequestCount: 0,
|
|
|
|
tabId: tabId
|
2014-06-24 00:42:43 +02:00
|
|
|
};
|
2014-12-30 22:36:29 +01:00
|
|
|
var pageStore = µb.pageStoreFromTabId(tabId);
|
2014-06-24 00:42:43 +02:00
|
|
|
if ( pageStore ) {
|
|
|
|
r.pageURL = pageStore.pageURL;
|
2014-12-30 22:36:29 +01:00
|
|
|
r.pageDomain = pageStore.pageDomain;
|
2014-06-24 00:42:43 +02:00
|
|
|
r.pageHostname = pageStore.pageHostname;
|
|
|
|
r.pageBlockedRequestCount = pageStore.perLoadBlockedRequestCount;
|
|
|
|
r.pageAllowedRequestCount = pageStore.perLoadAllowedRequestCount;
|
2014-08-02 17:40:27 +02:00
|
|
|
r.netFilteringSwitch = pageStore.getNetFilteringSwitch();
|
2014-12-30 22:36:29 +01:00
|
|
|
r.hostnameDict = getHostnameDict(pageStore.hostnameToCountMap);
|
2015-01-10 17:23:28 +01:00
|
|
|
r.contentLastModified = pageStore.contentLastModified;
|
2014-12-30 22:36:29 +01:00
|
|
|
r.dynamicFilterRules = getDynamicFilterRules(pageStore.pageHostname, r.hostnameDict);
|
|
|
|
} else {
|
|
|
|
r.hostnameDict = {};
|
|
|
|
r.dynamicFilterRules = getDynamicFilterRules();
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-01-20 00:42:58 +01:00
|
|
|
var getTargetTabId = function(tab) {
|
|
|
|
if ( !tab ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the URL is that of the network request logger, fill the popup with
|
|
|
|
// the data from the tab being observed by the logger.
|
|
|
|
// This allows a user to actually modify filtering profile for
|
|
|
|
// behind-the-scene requests.
|
|
|
|
if ( tab.url.indexOf(vAPI.getURL('devtools.html')) !== 0 ) {
|
|
|
|
return tab.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the target tab id from the URL
|
|
|
|
var matches = tab.url.match(/[\?&]tabId=([^&]+)/);
|
|
|
|
if ( matches && matches.length === 2 ) {
|
|
|
|
return matches[1];
|
|
|
|
}
|
|
|
|
return tab.id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
2015-01-10 17:23:28 +01:00
|
|
|
case 'getPopupData':
|
2014-12-30 22:36:29 +01:00
|
|
|
vAPI.tabs.get(null, function(tab) {
|
2015-01-20 00:42:58 +01:00
|
|
|
var tabId = getTargetTabId(tab);
|
2014-12-30 22:36:29 +01:00
|
|
|
callback(getStats(tabId));
|
|
|
|
});
|
2014-10-17 21:44:19 +02:00
|
|
|
return;
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2014-10-06 20:02:44 +02:00
|
|
|
case 'gotoPick':
|
|
|
|
// Picker launched from popup: clear context menu args
|
|
|
|
µb.contextMenuClientX = -1;
|
|
|
|
µb.contextMenuClientY = -1;
|
|
|
|
µb.elementPickerExec(request.tabId);
|
|
|
|
break;
|
|
|
|
|
2015-01-10 17:23:28 +01:00
|
|
|
case 'hasPopupContentChanged':
|
|
|
|
var pageStore = µb.pageStoreFromTabId(request.tabId);
|
|
|
|
var lastModified = pageStore ? pageStore.contentLastModified : 0;
|
|
|
|
response = lastModified !== request.contentLastModified;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'toggleDynamicFilter':
|
|
|
|
µb.toggleDynamicFilter(request);
|
|
|
|
response = getStats(request.tabId);
|
|
|
|
break;
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
case 'toggleNetFiltering':
|
2014-09-28 18:05:46 +02:00
|
|
|
µb.toggleNetFilteringSwitch(
|
2014-08-02 17:40:27 +02:00
|
|
|
request.url,
|
|
|
|
request.scope,
|
2014-06-24 00:42:43 +02:00
|
|
|
request.state
|
|
|
|
);
|
2014-09-28 18:05:46 +02:00
|
|
|
µb.updateBadgeAsync(request.tabId);
|
2014-06-24 00:42:43 +02:00
|
|
|
break;
|
|
|
|
|
2014-11-16 14:09:28 +01:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.messaging.listen('popup.js', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-06-27 23:06:42 +02:00
|
|
|
// contentscript-start.js
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-08-02 17:40:27 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
2014-06-24 01:23:36 +02:00
|
|
|
var pageStore;
|
|
|
|
if ( sender && sender.tab ) {
|
2014-08-02 17:40:27 +02:00
|
|
|
pageStore = µb.pageStoreFromTabId(sender.tab.id);
|
2014-06-24 01:23:36 +02:00
|
|
|
}
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
switch ( request.what ) {
|
|
|
|
case 'retrieveDomainCosmeticSelectors':
|
2014-08-02 17:40:27 +02:00
|
|
|
if ( pageStore && pageStore.getNetFilteringSwitch() ) {
|
2014-09-08 23:46:58 +02:00
|
|
|
response = µb.cosmeticFilteringEngine.retrieveDomainSelectors(request);
|
2014-08-02 17:40:27 +02:00
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
break;
|
2014-11-16 14:09:28 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-06-27 23:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.messaging.listen('contentscript-start.js', onMessage);
|
2014-06-27 23:06:42 +02:00
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-06-27 23:06:42 +02:00
|
|
|
})();
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-06-27 23:06:42 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// contentscript-end.js
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-08-02 17:40:27 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var tagNameToRequestTypeMap = {
|
|
|
|
'embed': 'object',
|
|
|
|
'iframe': 'sub_frame',
|
|
|
|
'img': 'image',
|
|
|
|
'object': 'object'
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// Evaluate many requests
|
|
|
|
|
|
|
|
var filterRequests = function(pageStore, details) {
|
2014-12-28 16:07:43 +01:00
|
|
|
var µburi = µb.URI;
|
|
|
|
|
|
|
|
// Create evaluation context
|
2015-01-14 23:45:55 +01:00
|
|
|
details.pageHostname = vAPI.punycodeHostname(details.pageHostname);
|
2014-12-28 16:07:43 +01:00
|
|
|
details.pageDomain = µburi.domainFromHostname(details.pageHostname);
|
2014-10-07 22:30:40 +02:00
|
|
|
details.rootHostname = pageStore.rootHostname;
|
|
|
|
details.rootDomain = pageStore.rootDomain;
|
2014-12-28 16:07:43 +01:00
|
|
|
details.requestHostname = '';
|
2014-09-14 22:20:40 +02:00
|
|
|
|
|
|
|
var inRequests = details.requests;
|
|
|
|
var outRequests = [];
|
|
|
|
var request, result;
|
|
|
|
var i = inRequests.length;
|
|
|
|
while ( i-- ) {
|
|
|
|
request = inRequests[i];
|
|
|
|
if ( tagNameToRequestTypeMap.hasOwnProperty(request.tagName) === false ) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-14 23:45:55 +01:00
|
|
|
details.requestURL = vAPI.punycodeURL(request.url);
|
|
|
|
details.requestHostname = µburi.hostnameFromURI(details.requestURL);
|
2014-12-28 16:07:43 +01:00
|
|
|
details.requestType = tagNameToRequestTypeMap[request.tagName];
|
|
|
|
result = pageStore.filterRequest(details);
|
2014-09-14 22:20:40 +02:00
|
|
|
if ( pageStore.boolFromResult(result) ) {
|
|
|
|
outRequests.push(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
collapse: µb.userSettings.collapseBlocked,
|
|
|
|
requests: outRequests
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// Evaluate a single request
|
|
|
|
|
|
|
|
var filterRequest = function(pageStore, details) {
|
|
|
|
if ( tagNameToRequestTypeMap.hasOwnProperty(details.tagName) === false ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-28 16:07:43 +01:00
|
|
|
var µburi = µb.URI;
|
2015-01-14 23:45:55 +01:00
|
|
|
details.pageHostname = vAPI.punycodeHostname(details.pageHostname);
|
2014-12-28 16:07:43 +01:00
|
|
|
details.pageDomain = µburi.domainFromHostname(details.pageHostname);
|
2014-10-07 22:30:40 +02:00
|
|
|
details.rootHostname = pageStore.rootHostname;
|
|
|
|
details.rootDomain = pageStore.rootDomain;
|
2015-01-14 23:45:55 +01:00
|
|
|
details.requestURL = vAPI.punycodeURL(details.requestURL);
|
2014-12-28 16:07:43 +01:00
|
|
|
details.requestHostname = µburi.hostnameFromURI(details.requestURL);
|
|
|
|
details.requestType = tagNameToRequestTypeMap[details.tagName];
|
|
|
|
var result = pageStore.filterRequest(details);
|
2014-09-14 22:20:40 +02:00
|
|
|
if ( pageStore.boolFromResult(result) ) {
|
|
|
|
return { collapse: µb.userSettings.collapseBlocked };
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(details, sender, callback) {
|
2014-06-27 23:06:42 +02:00
|
|
|
// Async
|
2014-09-14 22:20:40 +02:00
|
|
|
switch ( details.what ) {
|
2014-06-27 23:06:42 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
var pageStore;
|
|
|
|
if ( sender && sender.tab ) {
|
2014-08-02 17:40:27 +02:00
|
|
|
pageStore = µb.pageStoreFromTabId(sender.tab.id);
|
2014-06-27 23:06:42 +02:00
|
|
|
}
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
switch ( details.what ) {
|
2014-06-24 00:42:43 +02:00
|
|
|
case 'retrieveGenericCosmeticSelectors':
|
2015-01-09 03:04:48 +01:00
|
|
|
if ( pageStore && pageStore.getCosmeticFilteringSwitch() ) {
|
2014-09-14 22:20:40 +02:00
|
|
|
response = µb.cosmeticFilteringEngine.retrieveGenericSelectors(details);
|
2014-08-02 17:40:27 +02:00
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
break;
|
|
|
|
|
2014-08-14 19:59:37 +02:00
|
|
|
case 'injectedSelectors':
|
2014-09-14 22:20:40 +02:00
|
|
|
µb.cosmeticFilteringEngine.addToSelectorCache(details);
|
2014-06-27 23:06:42 +02:00
|
|
|
break;
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
// Evaluate many requests
|
|
|
|
case 'filterRequests':
|
|
|
|
if ( pageStore && pageStore.getNetFilteringSwitch() ) {
|
|
|
|
response = filterRequests(pageStore, details);
|
|
|
|
}
|
2014-08-15 16:34:13 +02:00
|
|
|
break;
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
// Evaluate a single request
|
|
|
|
case 'filterRequest':
|
|
|
|
if ( pageStore && pageStore.getNetFilteringSwitch() ) {
|
|
|
|
response = filterRequest(pageStore, details);
|
|
|
|
}
|
2014-06-29 18:38:18 +02:00
|
|
|
break;
|
2014-11-16 14:09:28 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-10-20 13:26:02 +02:00
|
|
|
}
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2014-10-20 13:26:02 +02:00
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
|
|
|
vAPI.messaging.listen('contentscript-end.js', onMessage);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// element-picker.js
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-10-20 13:26:02 +02:00
|
|
|
/******************************************************************************/
|
2014-09-28 18:05:46 +02:00
|
|
|
|
2014-10-20 13:26:02 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2014-09-28 18:05:46 +02:00
|
|
|
case 'elementPickerArguments':
|
2014-07-13 02:32:44 +02:00
|
|
|
response = {
|
2014-09-28 18:05:46 +02:00
|
|
|
i18n: {
|
2014-10-21 16:45:54 +02:00
|
|
|
'@@bidi_dir': document.body.getAttribute('dir'),
|
2014-10-17 21:44:19 +02:00
|
|
|
create: vAPI.i18n('pickerCreate'),
|
|
|
|
pick: vAPI.i18n('pickerPick'),
|
|
|
|
quit: vAPI.i18n('pickerQuit'),
|
|
|
|
netFilters: vAPI.i18n('pickerNetFilters'),
|
|
|
|
cosmeticFilters: vAPI.i18n('pickerCosmeticFilters'),
|
|
|
|
cosmeticFiltersHint: vAPI.i18n('pickerCosmeticFiltersHint')
|
2014-09-28 18:05:46 +02:00
|
|
|
},
|
2014-09-28 20:38:17 +02:00
|
|
|
target: µb.contextMenuTarget,
|
|
|
|
clientX: µb.contextMenuClientX,
|
|
|
|
clientY: µb.contextMenuClientY
|
2014-07-13 02:32:44 +02:00
|
|
|
};
|
2014-09-28 20:38:17 +02:00
|
|
|
µb.contextMenuTarget = '';
|
|
|
|
µb.contextMenuClientX = -1;
|
|
|
|
µb.contextMenuClientY = -1;
|
2014-07-13 02:32:44 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'createUserFilter':
|
2014-09-28 18:05:46 +02:00
|
|
|
µb.appendUserFilters(request.filters);
|
2014-07-13 02:32:44 +02:00
|
|
|
break;
|
|
|
|
|
2014-11-16 14:09:28 +01:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-07-13 02:32:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2014-10-20 13:26:02 +02:00
|
|
|
vAPI.messaging.listen('element-picker.js', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// 3p-filters.js
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-11-26 18:45:36 +01:00
|
|
|
var prepEntries = function(entries) {
|
|
|
|
var µburi = µb.URI;
|
|
|
|
var entry;
|
|
|
|
for ( var k in entries ) {
|
|
|
|
if ( entries.hasOwnProperty(k) === false ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
entry = entries[k];
|
|
|
|
if ( typeof entry.homeURL === 'string' ) {
|
|
|
|
entry.homeHostname = µburi.hostnameFromURI(entry.homeURL);
|
|
|
|
entry.homeDomain = µburi.domainFromHostname(entry.homeHostname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-07-25 22:12:20 +02:00
|
|
|
var getLists = function(callback) {
|
2014-07-26 22:10:20 +02:00
|
|
|
var r = {
|
|
|
|
available: null,
|
|
|
|
current: µb.remoteBlacklists,
|
|
|
|
cosmetic: µb.userSettings.parseAllABPHideFilters,
|
2014-12-28 16:07:43 +01:00
|
|
|
netFilterCount: µb.staticNetFilteringEngine.getFilterCount(),
|
2014-09-08 23:46:58 +02:00
|
|
|
cosmeticFilterCount: µb.cosmeticFilteringEngine.getFilterCount(),
|
2014-08-20 02:41:52 +02:00
|
|
|
autoUpdate: µb.userSettings.autoUpdate,
|
2014-08-20 16:26:57 +02:00
|
|
|
userFiltersPath: µb.userFiltersPath,
|
2014-07-26 22:10:20 +02:00
|
|
|
cache: null
|
|
|
|
};
|
2014-08-20 02:41:52 +02:00
|
|
|
var onMetadataReady = function(entries) {
|
2014-07-26 22:10:20 +02:00
|
|
|
r.cache = entries;
|
2014-11-26 18:45:36 +01:00
|
|
|
prepEntries(r.cache);
|
2014-09-09 01:45:22 +02:00
|
|
|
callback(r);
|
2014-07-26 22:10:20 +02:00
|
|
|
};
|
|
|
|
var onLists = function(lists) {
|
|
|
|
r.available = lists;
|
2014-11-26 18:45:36 +01:00
|
|
|
prepEntries(r.available);
|
2014-09-09 01:45:22 +02:00
|
|
|
µb.assets.metadata(onMetadataReady);
|
2014-07-25 22:12:20 +02:00
|
|
|
};
|
2014-07-26 22:10:20 +02:00
|
|
|
µb.getAvailableLists(onLists);
|
2014-07-25 22:12:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
2014-07-25 22:12:20 +02:00
|
|
|
case 'getLists':
|
|
|
|
return getLists(callback);
|
|
|
|
|
2014-09-09 01:45:22 +02:00
|
|
|
case 'purgeAllCaches':
|
|
|
|
return µb.assets.purgeAll(callback);
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
case 'writeUserUbiquitousBlockRules':
|
|
|
|
return µb.assets.put(µb.userFiltersPath, request.content, callback);
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2014-07-26 22:10:20 +02:00
|
|
|
case 'purgeCache':
|
|
|
|
µb.assets.purge(request.path);
|
|
|
|
break;
|
|
|
|
|
2014-11-16 14:09:28 +01:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.messaging.listen('3p-filters.js', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// 1p-filters.js
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
2014-06-24 00:42:43 +02:00
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
|
|
|
case 'readUserFilters':
|
|
|
|
return µb.assets.get(µb.userFiltersPath, callback);
|
|
|
|
|
|
|
|
case 'writeUserFilters':
|
|
|
|
return µb.assets.put(µb.userFiltersPath, request.content, callback);
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2014-11-16 14:09:28 +01:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.messaging.listen('1p-filters.js', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-12-31 23:26:17 +01:00
|
|
|
// dyna-rules.js
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
|
|
|
case 'getDynamicRules':
|
|
|
|
response = µb.dynamicNetFilteringEngine.toString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'setDynamicRules':
|
|
|
|
µb.dynamicNetFilteringEngine.fromString(request.rawRules);
|
|
|
|
µb.saveDynamicRules();
|
|
|
|
response = µb.dynamicNetFilteringEngine.toString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
|
|
|
vAPI.messaging.listen('dyna-rules.js', onMessage);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-07-17 16:52:43 +02:00
|
|
|
// whitelist.js
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
2014-07-17 16:52:43 +02:00
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
2014-07-17 16:52:43 +02:00
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
|
|
|
case 'getWhitelist':
|
2014-08-02 17:40:27 +02:00
|
|
|
response = µb.stringFromWhitelist(µb.netWhitelist);
|
2014-07-17 16:52:43 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'setWhitelist':
|
2014-08-02 17:40:27 +02:00
|
|
|
µb.netWhitelist = µb.whitelistFromString(request.whitelist);
|
2014-07-17 16:52:43 +02:00
|
|
|
µb.saveWhitelist();
|
|
|
|
break;
|
|
|
|
|
2014-11-16 14:09:28 +01:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-07-17 16:52:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2014-10-17 21:44:19 +02:00
|
|
|
vAPI.messaging.listen('whitelist.js', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-07-17 16:52:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-07-17 16:52:43 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-01-20 00:42:58 +01:00
|
|
|
// devtools.js
|
2014-07-02 18:02:29 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-01-06 14:01:15 +01:00
|
|
|
var getPageDetails = function(callback) {
|
|
|
|
var out = {};
|
|
|
|
var tabIds = Object.keys(µb.pageStores);
|
|
|
|
|
2015-01-20 00:42:58 +01:00
|
|
|
// Just in case... I expect there will always be a behind-the-scene page
|
|
|
|
// store, but just to be safe.
|
|
|
|
if ( tabIds.length === 0 ) {
|
2015-01-06 14:01:15 +01:00
|
|
|
callback(out);
|
|
|
|
return;
|
2014-07-02 18:02:29 +02:00
|
|
|
}
|
2015-01-06 14:01:15 +01:00
|
|
|
|
2015-01-20 00:42:58 +01:00
|
|
|
var countdown = tabIds.length;
|
|
|
|
var doCountdown = function() {
|
2015-01-06 14:01:15 +01:00
|
|
|
countdown -= 1;
|
|
|
|
if ( countdown === 0 ) {
|
|
|
|
callback(out);
|
2014-07-02 18:02:29 +02:00
|
|
|
}
|
2014-07-07 03:52:16 +02:00
|
|
|
};
|
2015-01-06 14:01:15 +01:00
|
|
|
|
2015-01-20 00:42:58 +01:00
|
|
|
// Let's not populate the page selector with reference itself
|
|
|
|
var devtoolsURL = vAPI.getURL('devtools.html');
|
|
|
|
var devtoolsURLLen = devtoolsURL.length;
|
|
|
|
|
|
|
|
var onTabDetails = function(tab) {
|
|
|
|
if ( tab && tab.url.slice(0, devtoolsURLLen) !== devtoolsURL ) {
|
|
|
|
out[tab.id] = tab.title;
|
|
|
|
}
|
|
|
|
doCountdown();
|
|
|
|
};
|
|
|
|
|
2015-01-06 14:01:15 +01:00
|
|
|
var i = countdown;
|
|
|
|
while ( i-- ) {
|
2015-01-20 00:42:58 +01:00
|
|
|
// Special case: behind-the-scene virtual tab (does not really exist)
|
|
|
|
if ( vAPI.isNoTabId(tabIds[i]) ) {
|
|
|
|
out[vAPI.noTabId] = vAPI.i18n('logBehindTheScene');
|
|
|
|
doCountdown();
|
|
|
|
} else {
|
|
|
|
vAPI.tabs.get(tabIds[i], onTabDetails);
|
|
|
|
}
|
2014-07-02 18:02:29 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-07-02 18:02:29 +02:00
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
2015-01-06 14:01:15 +01:00
|
|
|
case 'getPageDetails':
|
|
|
|
getPageDetails(callback);
|
2014-11-16 14:09:28 +01:00
|
|
|
return;
|
|
|
|
|
2014-07-02 18:02:29 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2014-11-16 14:09:28 +01:00
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-07-02 18:02:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2015-01-20 00:42:58 +01:00
|
|
|
vAPI.messaging.listen('devtools.js', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-07-02 18:02:29 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-09-14 22:20:40 +02:00
|
|
|
/******************************************************************************/
|
2014-07-02 18:02:29 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2015-01-06 17:44:06 +01:00
|
|
|
// settings.js
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
2014-12-17 14:04:21 +01:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-10-07 14:59:35 +02:00
|
|
|
var getUserData = function(callback) {
|
|
|
|
var onUserFiltersReady = function(details) {
|
|
|
|
callback({
|
|
|
|
'timeStamp': Date.now(),
|
2014-10-20 22:10:59 +02:00
|
|
|
'version': vAPI.app.version,
|
2014-10-07 14:59:35 +02:00
|
|
|
'userSettings': µb.userSettings,
|
|
|
|
'filterLists': µb.remoteBlacklists,
|
|
|
|
'netWhitelist': µb.stringFromWhitelist(µb.netWhitelist),
|
|
|
|
'userFilters': details.content
|
|
|
|
});
|
|
|
|
};
|
|
|
|
µb.assets.get('assets/user/filters.txt', onUserFiltersReady);
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var restoreUserData = function(userData) {
|
2014-10-11 22:44:56 +02:00
|
|
|
var countdown = 5;
|
|
|
|
var onCountdown = function() {
|
|
|
|
countdown -= 1;
|
|
|
|
if ( countdown === 0 ) {
|
2014-12-02 17:02:17 +01:00
|
|
|
vAPI.app.restart();
|
2014-10-11 22:44:56 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var onAllRemoved = function() {
|
|
|
|
// Be sure to adjust `countdown` if adding/removing anything below
|
|
|
|
µBlock.saveLocalSettings(onCountdown);
|
|
|
|
µb.XAL.keyvalSetMany(userData.userSettings, onCountdown);
|
|
|
|
µb.XAL.keyvalSetOne('remoteBlacklists', userData.filterLists, onCountdown);
|
|
|
|
µb.XAL.keyvalSetOne('netWhitelist', userData.netWhitelist, onCountdown);
|
|
|
|
µb.assets.put('assets/user/filters.txt', userData.userFilters, onCountdown);
|
|
|
|
};
|
|
|
|
|
2014-10-07 16:46:10 +02:00
|
|
|
// If we are going to restore all, might as well wipe out clean local
|
|
|
|
// storage
|
2014-10-11 22:44:56 +02:00
|
|
|
µb.XAL.keyvalRemoveAll(onAllRemoved);
|
2014-10-07 14:59:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var resetUserData = function() {
|
2014-10-07 16:46:10 +02:00
|
|
|
µb.XAL.keyvalRemoveAll();
|
2014-10-07 14:59:35 +02:00
|
|
|
// Keep global counts, people can become quite attached to numbers
|
2014-10-07 16:46:10 +02:00
|
|
|
µBlock.saveLocalSettings();
|
2014-12-02 17:02:17 +01:00
|
|
|
vAPI.app.restart();
|
2014-10-07 14:59:35 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2014-09-28 18:05:46 +02:00
|
|
|
var onMessage = function(request, sender, callback) {
|
2014-06-24 00:42:43 +02:00
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
2014-10-07 14:59:35 +02:00
|
|
|
case 'getUserData':
|
|
|
|
return getUserData(callback);
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
2014-10-07 14:59:35 +02:00
|
|
|
case 'restoreUserData':
|
|
|
|
restoreUserData(request.userData);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'resetUserData':
|
|
|
|
resetUserData();
|
|
|
|
break;
|
2014-11-16 14:09:28 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
2014-06-24 00:42:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
2015-01-06 17:44:06 +01:00
|
|
|
vAPI.messaging.listen('settings.js', onMessage);
|
2014-09-28 18:05:46 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
2015-01-06 14:01:15 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
// devtool-log.js
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var µb = µBlock;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
var onMessage = function(request, sender, callback) {
|
|
|
|
// Async
|
|
|
|
switch ( request.what ) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync
|
|
|
|
var response;
|
|
|
|
|
|
|
|
switch ( request.what ) {
|
|
|
|
case 'readLogBuffer':
|
|
|
|
var pageStore = µb.pageStoreFromTabId(request.tabId);
|
|
|
|
if ( pageStore ) {
|
|
|
|
response = pageStore.logBuffer.readAll();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return vAPI.messaging.UNHANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(response);
|
|
|
|
};
|
|
|
|
|
|
|
|
vAPI.messaging.listen('devtool-log.js', onMessage);
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
})();
|
|
|
|
|
2014-08-20 02:41:52 +02:00
|
|
|
// https://www.youtube.com/watch?v=3_WcygKJP1k
|
|
|
|
|
2014-06-24 00:42:43 +02:00
|
|
|
/******************************************************************************/
|