Skip to content

Commit a7aa755

Browse files
committed
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/
1 parent 27a72b8 commit a7aa755

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/js/urlskip.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
* `&i`: extract the name of the parameter at position `i` as the current
4040
* string. The position is 1-based.
4141
*
42+
* `#`: extract the hash as the current string.
43+
*
4244
* `/.../`: extract the first capture group of a regex as the current string.
4345
*
4446
* `+https`: prepend the current string with `https://`.
@@ -77,6 +79,12 @@ export function urlSkip(url, blocked, steps, directive = {}) {
7779
for ( const step of steps ) {
7880
const urlin = urlout;
7981
const c0 = step.charCodeAt(0);
82+
// Extract from hash
83+
if ( c0 === 0x23 && step === '#' ) { // #
84+
const pos = urlin.indexOf('#');
85+
urlout = pos !== -1 ? urlin.slice(pos+1) : '';
86+
continue;
87+
}
8088
// Extract from URL parameter name at position i
8189
if ( c0 === 0x26 ) { // &
8290
const i = (parseInt(step.slice(1)) || 0) - 1;
@@ -88,14 +96,14 @@ export function urlSkip(url, blocked, steps, directive = {}) {
8896
continue;
8997
}
9098
// Enforce https
91-
if ( c0 === 0x2B && step === '+https' ) {
99+
if ( c0 === 0x2B && step === '+https' ) { // +
92100
const s = urlin.replace(/^https?:\/\//, '');
93101
if ( /^[\w-]:\/\//.test(s) ) { return; }
94102
urlout = `https://${s}`;
95103
continue;
96104
}
97105
// Decode
98-
if ( c0 === 0x2D ) {
106+
if ( c0 === 0x2D ) { // -
99107
// Base64
100108
if ( step === '-base64' ) {
101109
urlout = self.atob(urlin);

0 commit comments

Comments
 (0)