From 7e6aaeffa028a8e83a1eaaab257d25e3d2e3faf7 Mon Sep 17 00:00:00 2001 From: DBX12 Date: Thu, 29 Sep 2022 16:33:42 +0200 Subject: [PATCH] Add "load all commits" and "stop loading commits" buttons No more loading for 30 minutes! --- bitbucket-show-approvers.user.js | 46 +++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/bitbucket-show-approvers.user.js b/bitbucket-show-approvers.user.js index 1ebc5e7..93ed12e 100644 --- a/bitbucket-show-approvers.user.js +++ b/bitbucket-show-approvers.user.js @@ -26,6 +26,8 @@ let settings = {}; let alreadyProcessedParticipants = {}; + let inhibitLoading = false; + const API_BASE = "https://bitbucket.org/api/2.0/"; @@ -33,6 +35,7 @@ const COMMIT_TABLE_HEADLINE_SELECTOR = 'section[data-qa="commit-list-styles"] h2'; const COMMIT_TABLE_SELECTOR = 'section[data-qa="commit-list-styles"] table'; + const LOAD_MORE_COMMITS_SELECTOR = 'button > span:contains("Load more commits")'; const SVG_CHECKMARK_GREEN = ''; const SVG_CHECKMARK_GREY = ''; @@ -200,6 +203,44 @@ headline.append(button); } + function addLoadAllCommitsButton() { + let headline = $(COMMIT_TABLE_HEADLINE_SELECTOR).parent().parent().parent(); + let button = $(''); + button.click( + function (ev) { + inhibitLoading = false; + loadMoreCommits(); + ev.stopPropagation(); + }); + headline.append(button); + } + + function addStopLoadingCommitsButton() { + let headline = $(COMMIT_TABLE_HEADLINE_SELECTOR).parent().parent().parent(); + let button = $(''); + button.click( + function (ev) { + inhibitLoading = true; + ev.stopPropagation(); + }); + headline.append(button); + } + + function loadMoreCommits(){ + if (inhibitLoading === true) { + debugOutput("Loading inhibited"); + return; + } + let span = $(LOAD_MORE_COMMITS_SELECTOR); + if (span.length === 0) { + debugOutput("No more commits to load"); + return; + } + span.parent().click(); + debugOutput("Clicked the load more button"); + setTimeout(loadMoreCommits, settings.loadMoreDelay); + } + function refreshApprovers() { debugOutput("Started to load / refresh approvers") loadCommitHashes().then(hashList => { @@ -219,7 +260,8 @@ bb_appPassword: '', activationDelay: 5000, removeEmptyTds: true, - debugOutput: false + debugOutput: false, + loadMoreDelay: 1000, } for (let key in DEFAULT_SETTINGS) { let value = GM_getValue(key, '!unset!'); @@ -236,6 +278,8 @@ identifyPrData(); registerMutationObserver(); addRefreshButton(); + addLoadAllCommitsButton(); + addStopLoadingCommitsButton(); refreshApprovers(); }