From 40dea4df3b3dac17a8c6d3c155035f8c22ac1423 Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 14 Nov 2020 23:34:46 +0300 Subject: [PATCH] fixup! directly install usercss from raw github links --- background/usercss-install-helper.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/background/usercss-install-helper.js b/background/usercss-install-helper.js index 73d0af2d..5bf61fdb 100644 --- a/background/usercss-install-helper.js +++ b/background/usercss-install-helper.js @@ -33,23 +33,26 @@ return code; }; + // `glob`: pathname match pattern for webRequest + // `rx`: pathname regex to verify the URL really looks like a raw usercss const maybeDistro = { // https://github.com/StylishThemes/GitHub-Dark/raw/master/github-dark.user.css 'github.com': { glob: '/*/raw/*', - rx: /^https:\/\/github\.com\/[^/]+\/[^/]+\/raw\/[^/]+\/[^/]+?\.user\.(css|styl)([#?].*)?$/, + rx: /^\/[^/]+\/[^/]+\/raw\/[^/]+\/[^/]+?\.user\.(css|styl)$/, }, // https://raw.githubusercontent.com/StylishThemes/GitHub-Dark/master/github-dark.user.css 'raw.githubusercontent.com': { glob: '/*', - rx: /^https:\/\/raw\.githubusercontent\.com(\/[^/]+?){4}\.user\.(css|styl)([#?].*)?$/, + rx: /^(\/[^/]+?){4}\.user\.(css|styl)$/, }, }; // Faster installation on known distribution sites to avoid flicker of css text chrome.webRequest.onBeforeSendHeaders.addListener(({tabId, url}) => { - const m = maybeDistro[new URL(url).hostname]; - if (!m || m.rx.test(url)) { + const u = new URL(url); + const m = maybeDistro[u.hostname]; + if (!m || m.rx.test(u.pathname)) { openInstallerPage(tabId, url, {}); // Silently suppress navigation. // Don't redirect to the install URL as it'll flash the text!