From b4f17124a914db496b4563404da7751c097f501d Mon Sep 17 00:00:00 2001 From: turtlebasket Date: Fri, 10 Feb 2023 11:31:21 -0800 Subject: [PATCH] add regex urlpath filters --- github-distractionless/distractionless.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/github-distractionless/distractionless.js b/github-distractionless/distractionless.js index f476b5f..79bcc04 100644 --- a/github-distractionless/distractionless.js +++ b/github-distractionless/distractionless.js @@ -13,6 +13,7 @@ let hideEls = []; let focusing = false; +let urlPath = new URL(window.location.href).pathname; // title bar links - custom behavior for now const titleBarExclude = ["Explore", "Marketplace", "Codespaces"]; @@ -27,17 +28,19 @@ for (let i = 0; i < titleBarEls.length; i++) { // general exclusion list [ - ["mail-status unread", [0], /.*/], + ["mail-status unread", [0], /^.*$/], ["UnderlineNav-item", [1], /^\/$/], ] -.forEach(([className, hideIndices, pageRegex]) => { +.forEach(([className, hideIndices, pathRegex]) => { hideIndices.forEach(i => { - let el = document.getElementsByClassName(className)[i]; - if (typeof el === 'undefined') { - console.log(`focus mode: unable to find element ${className} [ ${i} ]`) - } - else { - hideEls.push(el); + if (urlPath.search(pathRegex) > -1) { + let el = document.getElementsByClassName(className)[i]; + if (typeof el === 'undefined') { + console.log(`focus mode: unable to find element ${className} [ ${i} ]`) + } + else { + hideEls.push(el); + } } }); })