From 490bbf82ec88e5d94b210349d0e025fb890656e3 Mon Sep 17 00:00:00 2001 From: wukko Date: Wed, 29 May 2024 12:57:26 +0600 Subject: [PATCH] processing/url: clean up cleanURL query exceptions --- src/modules/processing/url.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/modules/processing/url.js b/src/modules/processing/url.js index a006402c..1a8bb927 100644 --- a/src/modules/processing/url.js +++ b/src/modules/processing/url.js @@ -78,19 +78,30 @@ function aliasURL(url) { function cleanURL(url) { assert(url instanceof URL); const host = psl.parse(url.hostname).sld; + let stripQuery = true; - if (host === 'pinterest') { - url.hostname = 'pinterest.com' - } else if (host === 'vk' && url.pathname.includes('/clip')) { - if (url.searchParams.get('z')) - url.search = '?z=' + encodeURIComponent(url.searchParams.get('z')); - stripQuery = false; - } else if (host === 'youtube' && url.searchParams.get('v')) { - url.search = '?v=' + encodeURIComponent(url.searchParams.get('v')); + const limitQuery = (param) => { + url.search = `?${param}=` + encodeURIComponent(url.searchParams.get(param)); stripQuery = false; } + switch (host) { + case "pinterest": + url.hostname = 'pinterest.com'; + break; + case "vk": + if (url.pathname.includes('/clip') && url.searchParams.get('z')) { + limitQuery('z') + } + break; + case "youtube": + if (url.searchParams.get('v')) { + limitQuery('v') + } + break; + } + if (stripQuery) { url.search = '' }