mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 01:02:08 +01:00
this fixes #227
This commit is contained in:
parent
284b4f62d1
commit
43f9657d0f
6 changed files with 85 additions and 44 deletions
|
@ -2,7 +2,7 @@
|
|||
"manifest_version": 2,
|
||||
|
||||
"name": "uBlock Origin",
|
||||
"version": "0.9.6.0",
|
||||
"version": "0.9.7.5",
|
||||
|
||||
"default_locale": "en",
|
||||
"description": "__MSG_extShortDesc__",
|
||||
|
@ -13,8 +13,8 @@
|
|||
|
||||
"browser_action": {
|
||||
"default_icon": {
|
||||
"19": "img/browsericons/icon19-off.png",
|
||||
"38": "img/browsericons/icon38-off.png"
|
||||
"19": "img/browsericons/icon19.png",
|
||||
"38": "img/browsericons/icon19.png"
|
||||
},
|
||||
"default_title": "uBlock Origin",
|
||||
"default_popup": "popup.html"
|
||||
|
|
|
@ -277,6 +277,7 @@ body[dir="rtl"] #popupContainer > div {
|
|||
#urlFilteringMenu .dialog {
|
||||
background-color: white;
|
||||
border: 1px solid gray;
|
||||
max-width: 70%;
|
||||
padding: 0.2em;
|
||||
position: fixed;
|
||||
}
|
||||
|
@ -310,7 +311,6 @@ body.dirty #urlFilteringMenu .save {
|
|||
#urlFilteringMenu .entries {
|
||||
font-size: 13px;
|
||||
max-height: 12em;
|
||||
max-width: 70vw;
|
||||
overflow-y: auto;
|
||||
}
|
||||
#urlFilteringMenu .entries > div {
|
||||
|
|
|
@ -645,6 +645,8 @@ var urlFilteringMenu = (function() {
|
|||
return;
|
||||
}
|
||||
|
||||
var persist = !!ev.ctrlKey || !!ev.metaKey;
|
||||
|
||||
// Remove url filtering rule
|
||||
if ( target.classList.contains('action') ) {
|
||||
messager.send({
|
||||
|
@ -652,7 +654,8 @@ var urlFilteringMenu = (function() {
|
|||
context: selectContext.value,
|
||||
url: target.getAttribute('data-url'),
|
||||
type: uglyTypeFromSelector(),
|
||||
action: 0
|
||||
action: 0,
|
||||
persist: persist
|
||||
}, colorize);
|
||||
return;
|
||||
}
|
||||
|
@ -664,7 +667,8 @@ var urlFilteringMenu = (function() {
|
|||
context: selectContext.value,
|
||||
url: target.parentNode.getAttribute('data-url'),
|
||||
type: uglyTypeFromSelector(),
|
||||
action: 2
|
||||
action: 2,
|
||||
persist: persist
|
||||
}, colorize);
|
||||
return;
|
||||
}
|
||||
|
@ -676,7 +680,8 @@ var urlFilteringMenu = (function() {
|
|||
context: selectContext.value,
|
||||
url: target.parentNode.getAttribute('data-url'),
|
||||
type: uglyTypeFromSelector(),
|
||||
action: 3
|
||||
action: 3,
|
||||
persist: persist
|
||||
}, colorize);
|
||||
return;
|
||||
}
|
||||
|
@ -688,7 +693,8 @@ var urlFilteringMenu = (function() {
|
|||
context: selectContext.value,
|
||||
url: target.parentNode.getAttribute('data-url'),
|
||||
type: uglyTypeFromSelector(),
|
||||
action: 1
|
||||
action: 1,
|
||||
persist: persist
|
||||
}, colorize);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1212,35 +1212,6 @@ var getURLFilteringData = function(details) {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
var saveTemporaryURLFilteringRules = function(details) {
|
||||
var changed = false;
|
||||
var suf = µb.sessionURLFiltering;
|
||||
var puf = µb.permanentURLFiltering;
|
||||
var urls = details.urls,
|
||||
context = details.context,
|
||||
type = details.type;
|
||||
var url, sOwn, pOwn;
|
||||
var i = urls.length;
|
||||
while ( i-- ) {
|
||||
url = urls[i];
|
||||
suf.evaluateZ(context, url, type);
|
||||
sOwn = suf.context === context && suf.url === url && suf.type === type;
|
||||
puf.evaluateZ(context, url, type);
|
||||
pOwn = puf.context === context && puf.url === url && puf.type === type;
|
||||
if ( sOwn && !pOwn ) {
|
||||
puf.setRule(context, url, type, suf.r);
|
||||
changed = true;
|
||||
}
|
||||
if ( !sOwn && pOwn ) {
|
||||
puf.removeRule(context, url, type);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var onMessage = function(request, sender, callback) {
|
||||
// Async
|
||||
switch ( request.what ) {
|
||||
|
@ -1276,7 +1247,13 @@ var onMessage = function(request, sender, callback) {
|
|||
break;
|
||||
|
||||
case 'saveURLFilteringRules':
|
||||
if ( saveTemporaryURLFilteringRules(request) ) {
|
||||
response = µb.permanentURLFiltering.copyRules(
|
||||
µb.sessionURLFiltering,
|
||||
request.context,
|
||||
request.urls,
|
||||
request.type
|
||||
);
|
||||
if ( response ) {
|
||||
µb.savePermanentURLFilteringRules();
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -325,6 +325,21 @@ var matchWhitelistDirective = function(url, hostname, directive) {
|
|||
}
|
||||
|
||||
this.cosmeticFilteringEngine.removeFromSelectorCache(details.context, 'net');
|
||||
|
||||
if ( !details.persist ) {
|
||||
return;
|
||||
}
|
||||
|
||||
changed = this.permanentURLFiltering.setRule(
|
||||
details.context,
|
||||
details.url,
|
||||
details.type,
|
||||
details.action
|
||||
);
|
||||
|
||||
if ( changed ) {
|
||||
this.savePermanentFirewallRules();
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
/*******************************************************************************
|
||||
|
||||
buckets: map of [origin + urlkey]
|
||||
buckets: map of [origin + urlkey + type]
|
||||
bucket: array of rule entry, sorted from shorter to longer url
|
||||
|
||||
rule entry: { url, action }
|
||||
|
@ -127,6 +127,10 @@ var addRuleEntry = function(urls, url, action) {
|
|||
/******************************************************************************/
|
||||
|
||||
var urlKeyFromURL = function(url) {
|
||||
// Experimental: running benchmarks first
|
||||
//if ( url === '*' ) {
|
||||
// return url;
|
||||
//}
|
||||
var match = reURLKey.exec(url);
|
||||
return match !== null ? match[0] : '';
|
||||
};
|
||||
|
@ -142,7 +146,7 @@ var URLNetFiltering = function() {
|
|||
/******************************************************************************/
|
||||
|
||||
// rules:
|
||||
// hostname + urlkey => urls
|
||||
// origin + urlkey + type => urls
|
||||
// urls = collection of urls to match
|
||||
|
||||
URLNetFiltering.prototype.reset = function() {
|
||||
|
@ -243,12 +247,12 @@ URLNetFiltering.prototype.evaluateZ = function(context, target, type) {
|
|||
return this;
|
||||
}
|
||||
|
||||
var urls, pos, i, entry, prefixKey;
|
||||
var urls, pos, i, entry, keyShard;
|
||||
|
||||
for (;;) {
|
||||
this.context = context;
|
||||
prefixKey = context + ' ' + urlKey;
|
||||
if ( urls = this.rules[prefixKey + ' ' + type] ) {
|
||||
keyShard = context + ' ' + urlKey;
|
||||
if ( urls = this.rules[keyShard + ' ' + type] ) {
|
||||
i = indexOfMatch(urls, target);
|
||||
if ( i !== -1 ) {
|
||||
entry = urls[i];
|
||||
|
@ -258,7 +262,7 @@ URLNetFiltering.prototype.evaluateZ = function(context, target, type) {
|
|||
return this;
|
||||
}
|
||||
}
|
||||
if ( urls = this.rules[prefixKey + ' *'] ) {
|
||||
if ( urls = this.rules[keyShard + ' *'] ) {
|
||||
i = indexOfMatch(urls, target);
|
||||
if ( i !== -1 ) {
|
||||
entry = urls[i];
|
||||
|
@ -268,6 +272,21 @@ URLNetFiltering.prototype.evaluateZ = function(context, target, type) {
|
|||
return this;
|
||||
}
|
||||
}
|
||||
/* Experimental: running benchmarks first
|
||||
if ( urls = this.rules[context + ' * ' + type] ) {
|
||||
entry = urls[0];
|
||||
this.url = '*';
|
||||
this.type = type;
|
||||
this.r = entry.action;
|
||||
return this;
|
||||
}
|
||||
if ( urls = this.rules[context + ' * *'] ) {
|
||||
entry = urls[0];
|
||||
this.url = this.type = '*';
|
||||
this.r = entry.action;
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
if ( context === '*' ) {
|
||||
break;
|
||||
}
|
||||
|
@ -304,6 +323,30 @@ URLNetFiltering.prototype.toFilterString = function() {
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
URLNetFiltering.prototype.copyRules = function(other, context, urls, type) {
|
||||
var changed = false;
|
||||
var url, otherOwn, thisOwn;
|
||||
var i = urls.length;
|
||||
while ( i-- ) {
|
||||
url = urls[i];
|
||||
other.evaluateZ(context, url, type);
|
||||
otherOwn = other.context === context && other.url === url && other.type === type;
|
||||
this.evaluateZ(context, url, type);
|
||||
thisOwn = this.context === context && this.url === url && this.type === type;
|
||||
if ( otherOwn && !thisOwn ) {
|
||||
this.setRule(context, url, type, other.r);
|
||||
changed = true;
|
||||
}
|
||||
if ( !otherOwn && thisOwn ) {
|
||||
this.removeRule(context, url, type);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// "url-filtering:" hostname url action
|
||||
|
||||
URLNetFiltering.prototype.toString = function() {
|
||||
|
|
Loading…
Reference in a new issue