mirror of https://github.com/gorhill/uBlock.git
Add basic compatibility with ABP's `rewrite` option
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/857 The recognized resources are: - abp-resource:blank-mp3 - abp-resource:blank-js ABP's tokens are excluded from auto-complete so as to not get in the way of uBO's filter list maintainers.
This commit is contained in:
parent
b553a66f70
commit
0b5f53923f
|
@ -185,7 +185,7 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
|
|||
// Warn about unknown redirect tokens.
|
||||
if (
|
||||
string.charCodeAt(pos - 1) === 0x3D /* '=' */ &&
|
||||
/[$,]redirect(-rule)?=$/.test(string.slice(0, pos))
|
||||
/[$,](redirect(-rule)?|rewrite)=$/.test(string.slice(0, pos))
|
||||
) {
|
||||
style = 'value';
|
||||
const end = parser.skipUntil(
|
||||
|
@ -418,6 +418,12 @@ const initHints = function() {
|
|||
return (item[1] & 0b01) !== 0;
|
||||
})
|
||||
);
|
||||
const excludedHints = new Set([
|
||||
'genericblock',
|
||||
'object-subrequest',
|
||||
'rewrite',
|
||||
'webrtc',
|
||||
]);
|
||||
|
||||
const pickBestHints = function(cursor, seedLeft, seedRight, hints) {
|
||||
const seed = (seedLeft + seedRight).trim();
|
||||
|
@ -471,6 +477,7 @@ const initHints = function() {
|
|||
const isException = parser.isException();
|
||||
const hints = [];
|
||||
for ( let [ text, bits ] of parser.netOptionTokenDescriptors ) {
|
||||
if ( excludedHints.has(text) ) { continue; }
|
||||
if ( isNegated && (bits & parser.OPTCanNegate) === 0 ) { continue; }
|
||||
if ( isException ) {
|
||||
if ( (bits & parser.OPTBlockOnly) !== 0 ) { continue; }
|
||||
|
@ -488,6 +495,7 @@ const initHints = function() {
|
|||
const getNetRedirectHints = function(cursor, seedLeft, seedRight) {
|
||||
const hints = [];
|
||||
for ( const text of redirectNames.keys() ) {
|
||||
if ( text.startsWith('abp-resource:') ) { continue; }
|
||||
hints.push(text);
|
||||
}
|
||||
return pickBestHints(cursor, seedLeft, seedRight, hints);
|
||||
|
@ -495,7 +503,10 @@ const initHints = function() {
|
|||
|
||||
const getNetHints = function(cursor, line) {
|
||||
const beg = cursor.ch;
|
||||
if ( parser.optionsSpan.len === 0 ) {
|
||||
if (
|
||||
parser.optionsAnchorSpan.len === 0 &&
|
||||
line.endsWith('$') === false
|
||||
) {
|
||||
if ( /[^\w\x80-\xF4#,.-]/.test(line) === false ) {
|
||||
return getOriginHints(cursor, line);
|
||||
}
|
||||
|
@ -511,7 +522,7 @@ const initHints = function() {
|
|||
if ( assignPos === -1 ) {
|
||||
return getNetOptionHints(cursor, matchLeft[0], matchRight[0]);
|
||||
}
|
||||
if ( /^redirect(-rule)?=/.test(matchLeft[0]) ) {
|
||||
if ( /^(redirect(-rule)?|rewrite)=/.test(matchLeft[0]) ) {
|
||||
return getNetRedirectHints(
|
||||
cursor,
|
||||
matchLeft[0].slice(assignPos + 1),
|
||||
|
|
|
@ -377,16 +377,15 @@ const PageStore = class {
|
|||
setFrameURL(frameId, frameURL) {
|
||||
let frameStore = this.frames.get(frameId);
|
||||
if ( frameStore !== undefined ) {
|
||||
if ( frameURL !== frameStore.rawURL ) {
|
||||
frameStore.init(frameURL);
|
||||
}
|
||||
} else {
|
||||
frameStore = FrameStore.factory(frameURL);
|
||||
this.frames.set(frameId, frameStore);
|
||||
this.frameAddCount += 1;
|
||||
if ( (this.frameAddCount & 0b111111) === 0 ) {
|
||||
this.pruneFrames();
|
||||
}
|
||||
return frameURL === frameStore.rawURL
|
||||
? frameStore
|
||||
: frameStore.init(frameURL);
|
||||
}
|
||||
frameStore = FrameStore.factory(frameURL);
|
||||
this.frames.set(frameId, frameStore);
|
||||
this.frameAddCount += 1;
|
||||
if ( (this.frameAddCount & 0b111111) === 0 ) {
|
||||
this.pruneFrames();
|
||||
}
|
||||
return frameStore;
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ const redirectableResources = new Map([
|
|||
data: 'text',
|
||||
} ],
|
||||
[ 'noop-0.1s.mp3', {
|
||||
alias: 'noopmp3-0.1s',
|
||||
alias: [ 'noopmp3-0.1s', 'abp-resource:blank-mp3' ],
|
||||
data: 'blob',
|
||||
} ],
|
||||
[ 'noop-1s.mp4', {
|
||||
|
@ -132,7 +132,7 @@ const redirectableResources = new Map([
|
|||
alias: 'noopframe',
|
||||
} ],
|
||||
[ 'noop.js', {
|
||||
alias: 'noopjs',
|
||||
alias: [ 'noopjs', 'abp-resource:blank-js' ],
|
||||
data: 'text',
|
||||
} ],
|
||||
[ 'noop.txt', {
|
||||
|
@ -461,7 +461,12 @@ RedirectEngine.prototype.loadBuiltinResources = function() {
|
|||
params: details.params,
|
||||
});
|
||||
this.resources.set(name, entry);
|
||||
if ( details.alias !== undefined ) {
|
||||
if ( details.alias === undefined ) { return; }
|
||||
if ( Array.isArray(details.alias) ) {
|
||||
for ( const alias of details.alias ) {
|
||||
this.aliases.set(alias, name);
|
||||
}
|
||||
} else {
|
||||
this.aliases.set(details.alias, name);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2183,6 +2183,7 @@ const netOptionTokenDescriptors = new Map([
|
|||
[ 'queryprune', OPTTokenQueryprune | OPTMayAssign | OPTModifierType | OPTNonCspableType | OPTNonRedirectableType ],
|
||||
[ 'removeparam', OPTTokenQueryprune | OPTMayAssign | OPTModifierType | OPTNonCspableType | OPTNonRedirectableType ],
|
||||
[ 'redirect', OPTTokenRedirect | OPTMustAssign | OPTAllowMayAssign | OPTModifierType ],
|
||||
[ 'rewrite', OPTTokenRedirect | OPTMustAssign | OPTAllowMayAssign | OPTModifierType ],
|
||||
[ 'redirect-rule', OPTTokenRedirectRule | OPTMustAssign | OPTAllowMayAssign | OPTModifierType | OPTNonCspableType ],
|
||||
[ 'script', OPTTokenScript | OPTCanNegate | OPTNetworkType | OPTModifiableType | OPTRedirectableType | OPTNonCspableType ],
|
||||
[ 'shide', OPTTokenShide | OPTNonNetworkType | OPTNonCspableType | OPTNonRedirectableType ],
|
||||
|
@ -2241,6 +2242,7 @@ Parser.netOptionTokenIds = new Map([
|
|||
[ 'queryprune', OPTTokenQueryprune ],
|
||||
[ 'removeparam', OPTTokenQueryprune ],
|
||||
[ 'redirect', OPTTokenRedirect ],
|
||||
[ 'rewrite', OPTTokenRedirect ],
|
||||
[ 'redirect-rule', OPTTokenRedirectRule ],
|
||||
[ 'script', OPTTokenScript ],
|
||||
[ 'shide', OPTTokenShide ],
|
||||
|
|
Loading…
Reference in New Issue