mirror of
https://github.com/gorhill/uBlock.git
synced 2025-01-31 12:11:36 +01:00
Improve urlskip=
filter option
New step: `#`, to extract the hash part of a URL. Example, URL: https://example.com/#aHR0cHM6Ly9naXRodWIuY29tL3VCbG9ja09yaWdpbi8= Filter: ||example.com^$urlskip=# -base64 As a result, navigate to https://github.com/uBlockOrigin/
This commit is contained in:
parent
27a72b8eef
commit
a7aa755f18
@ -39,6 +39,8 @@
|
||||
* `&i`: extract the name of the parameter at position `i` as the current
|
||||
* string. The position is 1-based.
|
||||
*
|
||||
* `#`: extract the hash as the current string.
|
||||
*
|
||||
* `/.../`: extract the first capture group of a regex as the current string.
|
||||
*
|
||||
* `+https`: prepend the current string with `https://`.
|
||||
@ -77,6 +79,12 @@ export function urlSkip(url, blocked, steps, directive = {}) {
|
||||
for ( const step of steps ) {
|
||||
const urlin = urlout;
|
||||
const c0 = step.charCodeAt(0);
|
||||
// Extract from hash
|
||||
if ( c0 === 0x23 && step === '#' ) { // #
|
||||
const pos = urlin.indexOf('#');
|
||||
urlout = pos !== -1 ? urlin.slice(pos+1) : '';
|
||||
continue;
|
||||
}
|
||||
// Extract from URL parameter name at position i
|
||||
if ( c0 === 0x26 ) { // &
|
||||
const i = (parseInt(step.slice(1)) || 0) - 1;
|
||||
@ -88,14 +96,14 @@ export function urlSkip(url, blocked, steps, directive = {}) {
|
||||
continue;
|
||||
}
|
||||
// Enforce https
|
||||
if ( c0 === 0x2B && step === '+https' ) {
|
||||
if ( c0 === 0x2B && step === '+https' ) { // +
|
||||
const s = urlin.replace(/^https?:\/\//, '');
|
||||
if ( /^[\w-]:\/\//.test(s) ) { return; }
|
||||
urlout = `https://${s}`;
|
||||
continue;
|
||||
}
|
||||
// Decode
|
||||
if ( c0 === 0x2D ) {
|
||||
if ( c0 === 0x2D ) { // -
|
||||
// Base64
|
||||
if ( step === '-base64' ) {
|
||||
urlout = self.atob(urlin);
|
||||
|
Loading…
x
Reference in New Issue
Block a user