Last active
June 30, 2022 12:35
-
-
Save divinity76/88c3ca5f7d58b2eb62c3f8b6bcdb5091 to your computer and use it in GitHub Desktop.
bitbucket ignore pull request userscript for GreaseMonkey / ViolentMonkey / TamperMonkey
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bitbucket ignore pull request - bitbucket.org | |
// @namespace divinity76 | |
// @include /^https\:\/\/bitbucket\.org\// | |
// @grant none | |
// @version 1.0 | |
// @author - | |
// @description screenshot: https://user-images.githubusercontent.com/1874996/175759481-27eb41c5-6874-44f1-a428-d195a7bcbab8.png - 6/26/2022, 1:10:55 AM | |
// ==/UserScript== | |
if (1 || window.location.href.split("#")[0].split("?")[0].match(/pull\-requests\/?$/)) { | |
// Todo: figure out how to run this code after the PRs are loaded, instead of this setInterval hack... | |
setInterval(function() { | |
try{ | |
let ignoredPrs = localStorage.getItem('ignoredPrs') | |
if (ignoredPrs) { | |
ignoredPrs = JSON.parse(ignoredPrs) | |
document | |
.querySelectorAll("tr[data-qa*='pull-request-row']") | |
.forEach(ele => { | |
const prId = Number( | |
ele | |
.querySelector('a') | |
.getAttribute('href') | |
.match(/pull-requests\/(?<prId>\d+)/)[1] | |
) | |
ele.style['text-decoration'] = | |
ignoredPrs.indexOf(prId) === -1 ? | |
'' : | |
'line-through' | |
}) | |
} | |
}catch(ex){ | |
// ...??? | |
} | |
}, 1000); | |
} | |
if (1 || window.location.href.split("#")[0].split("?")[0].match(/pull\-requests\/\d+$/)) { | |
// I can't figure out how to execute this *at the right time*, seems bitbucket first creates the entire page | |
// then proceed to remove the entire page, then create the entire page again... | |
// so i made this setInterval hack that works, but is a waste of cpu cycles | |
setInterval(function() { | |
try{ | |
if (document.querySelector('#pull-requests-button')) { | |
return | |
} | |
const pullRequestButton = document.createElement('span') | |
pullRequestButton.id = 'pull-requests-button' | |
pullRequestButton.innerHTML = | |
'<div class="css-z25nd1"><button aria-pressed="false" aria-label="Ignore this pull request" tabindex="0" type="button" class="css-1v2ovpy"><span class="css-j8fq0c"><span class="css-8xpfx5"><span role="presentation" aria-hidden="true" style="--icon-primary-color: white; --icon-secondary-color: var(--ds-surface, #FFFFFF);" class="css-pxzk9z"><svg width="24" height="24" viewBox="0 0 24 24" role="presentation"><g fill-rule="evenodd"><circle fill="currentColor" cx="12" cy="12" r="10"></circle><path d="M9.707 11.293a1 1 0 10-1.414 1.414l2 2a1 1 0 001.414 0l4-4a1 1 0 10-1.414-1.414L11 12.586l-1.293-1.293z" fill="inherit"></path></g></svg></span></span><span class="css-mu6jxl"><span id="ignore-this-pr-inner-span">Ignore this pull request</span></span></span></button></div>' | |
$(pullRequestButton).on('click', () => { | |
const prId = Number( | |
document.location | |
.toString() | |
.match(/pull-requests\/(?<prId>\d+)/)[1] | |
) | |
let ignoredPrs = localStorage.getItem('ignoredPrs') | |
if (ignoredPrs) { | |
ignoredPrs = JSON.parse(ignoredPrs) | |
} else { | |
ignoredPrs = [] | |
} | |
const ignoreKey = ignoredPrs.indexOf(prId) | |
// Todo find a better way to send the message.. also eslint-disable something | |
const fixme = window.alert.bind(window) | |
if (ignoreKey === -1) { | |
ignoredPrs.push(prId) | |
localStorage.setItem( | |
'ignoredPrs', | |
JSON.stringify(ignoredPrs) | |
) | |
fixme('added to ignoredPrs') | |
} else { | |
ignoredPrs.splice(ignoreKey, 1) | |
localStorage.setItem( | |
'ignoredPrs', | |
JSON.stringify(ignoredPrs) | |
) | |
fixme('removed from ignoredPrs') | |
} | |
}) | |
$('.css-vxcmzt:first').prepend(pullRequestButton) | |
}catch(ex){ | |
// ...??? | |
} | |
}, 1000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment