From a7aa755f1884acbf4a34e947c90129a3ddd0fa2f Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 24 Dec 2024 08:59:28 -0500 Subject: [PATCH] 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/ --- src/js/urlskip.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/js/urlskip.js b/src/js/urlskip.js index 31af869ad680b..66109f301afa9 100644 --- a/src/js/urlskip.js +++ b/src/js/urlskip.js @@ -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);