From 82098744f1b45c63fd409213dbf59ec510eb13cf Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Sat, 3 Jul 2021 09:53:15 -0400 Subject: [PATCH] Implement skip repos option --- webext/data/contentscript.js | 9 +++++++++ webext/options_ui/js/main.js | 6 ++++++ webext/options_ui/options.html | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/webext/data/contentscript.js b/webext/data/contentscript.js index 9950098..ec8eab2 100644 --- a/webext/data/contentscript.js +++ b/webext/data/contentscript.js @@ -3,6 +3,7 @@ const _logName = 'lovely-forks:' const STAR_THRES_KEY = 'STAR_THRES_KEY' +const SKIP_REPOS_KEY = 'SKIP_REPOS_KEY' const INDENT_KEY = 'INDENT_KEY' const LF_PREF_KEY = 'LF_PREF_KEY' const DAYS_THRES_KEY = 'DAYS_THRES_KEY' @@ -20,6 +21,7 @@ function getPreferences () { x = x[LF_PREF_KEY] || {} pref[STAR_THRES_KEY] = x[STAR_THRES_KEY] || 1 + pref[SKIP_REPOS_KEY] = x[SKIP_REPOS_KEY] || "" pref[DAYS_THRES_KEY] = x[DAYS_THRES_KEY] || 0 pref[INDENT_KEY] = x[INDENT_KEY] || false @@ -218,6 +220,13 @@ function isQuotaExceeded (e) { function processWithData (user, repo, remoteDataStr, selfDataStr, isFreshData, pref) { try { + /* Skip displaying if the repo is in the skip list */ + const skipRepos = pref[SKIP_REPOS_KEY].split(/[\s\n,]+/) + const inSkipList = skipRepos.some(val => val.indexOf(user + "/" + repo) > -1) + if (inSkipList) { + return + } + /* Parse fork data */ /* Can either be just one data element, * or could be the list of all forks. */ diff --git a/webext/options_ui/js/main.js b/webext/options_ui/js/main.js index aaff5d3..876b215 100644 --- a/webext/options_ui/js/main.js +++ b/webext/options_ui/js/main.js @@ -3,6 +3,7 @@ const DEBUG = false const STAR_THRES_KEY = 'STAR_THRES_KEY' +const SKIP_REPOS_KEY = 'SKIP_REPOS_KEY' const INDENT_KEY = 'INDENT_KEY' const LF_PREF_KEY = 'LF_PREF_KEY' const DAYS_THRES_KEY = 'DAYS_THRES_KEY' @@ -10,20 +11,24 @@ const DAYS_THRES_KEY = 'DAYS_THRES_KEY' chrome.storage.local.get(LF_PREF_KEY, x => { x = x[LF_PREF_KEY] || {} const thres = x[STAR_THRES_KEY] || 1 + const skipRepos = x[SKIP_REPOS_KEY] || "" const dayThres = x[DAYS_THRES_KEY] || 0 const indent = x[INDENT_KEY] || false $('.js-star-threshold').val(thres) + $('.js-skip-repos').val(skipRepos) $('.js-days-threshold').val(dayThres) $('.js-to-indent').checkbox(indent ? 'set checked' : 'set unchecked') }) function savePref () { const thres = $('.js-star-threshold').val() || 0 + const skipRepos = $('.js-skip-repos').val() || "" const dayThres = $('.js-days-threshold').val() || 0 const indent = $('.js-to-indent').checkbox('is checked') || false const pref = { [INDENT_KEY]: indent, [STAR_THRES_KEY]: thres, + [SKIP_REPOS_KEY]: skipRepos, [DAYS_THRES_KEY]: dayThres } chrome.storage.local.set({ [LF_PREF_KEY]: pref }, () => { @@ -39,4 +44,5 @@ function savePref () { $('.js-to-indent.ui.checkbox').checkbox({ onChange: savePref }) $('.js-star-threshold').on('change', savePref) +$('.js-skip-repos').on('change', savePref) $('.js-days-threshold').on('change', savePref) diff --git a/webext/options_ui/options.html b/webext/options_ui/options.html index daa226f..74bb42e 100644 --- a/webext/options_ui/options.html +++ b/webext/options_ui/options.html @@ -30,6 +30,16 @@

+
+

Repos on which to skip showing forks (comma, space, or newline separated list)

+
+
+ +