Skip to content

Instantly share code, notes, and snippets.

@paulera
Last active January 23, 2025 11:48
Show Gist options
  • Save paulera/caa0af70b103ddc1620aa8735d9a40b4 to your computer and use it in GitHub Desktop.
Save paulera/caa0af70b103ddc1620aa8735d9a40b4 to your computer and use it in GitHub Desktop.
Userscript that adds custom buttons, to automate clicking on Custom Filters in a Jira board.
// ==UserScript==
// @name Custom Filters quick shortcut
// @namespace http://tampermonkey.net/
// @version 2024-12-18
// @description Add custom buttons that automate clicking on Custom Filters in a Jira board
// @author Paulo
// @match https://*.atlassian.net/jira/software/projects/*/boards/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=atlassian.net
// @grant none
// ==/UserScript==
(function() {
'use strict';
function clickCustomFilter(filterName) {
// function to find buttons by text content
function findButtonByText(text) {
return Array.from(document.querySelectorAll('button')).find(button =>
button.textContent.includes(text)
);
}
// Step 1: Click the "More" button
const moreButton = findButtonByText('More');
if (moreButton) {
moreButton.click();
} else {
console.error('More button not found');
return;
}
// Step 2: Wait briefly, then click "Custom filters"
setTimeout(() => {
const customFiltersButton = findButtonByText('Custom filters');
if (customFiltersButton) {
customFiltersButton.click();
} else {
console.error('Custom Filters button not found');
return;
}
// Step 3: Wait again, then select the provided custom filter
setTimeout(() => {
const filterOption = Array.from(document.querySelectorAll('div[role="option"]'))
.find(option => option.textContent.includes(filterName));
if (filterOption) {
filterOption.click();
} else {
console.error(`Filter option "${filterName}" not found`);
return;
}
// Step 4: Simulate pressing the ESC key to close the dialog
setTimeout(() => {
document.dispatchEvent(new KeyboardEvent('keydown', {
key: 'Escape',
code: 'Escape',
keyCode: 27,
which: 27,
bubbles: true
}));
}, 500);
}, 500); // Wait 500ms for the filter list to appear
}, 500); // Wait 500ms for the "More" menu to open
}
function injectCustomFilterButtons() {
// Create a container to hold the buttons
const buttonContainer = document.createElement('div');
// Define button details
const buttons = [
{ name: 'Alex', filter: 'QA Alexander Mikov' },
{ name: 'TG', filter: 'QA ThankGod Oboh' }
];
// Function to create a simple button
function createButton(text, filterName) {
const button = document.createElement('button');
button.textContent = text;
button.addEventListener('click', () => {
clickCustomFilter(filterName);
});
return button;
}
// Append buttons to the container
buttons.forEach(btn => {
const newButton = createButton(btn.name, btn.filter);
buttonContainer.appendChild(newButton);
});
// Inject the container at a specific location
const targetElement = document.querySelector('fieldset');
if (targetElement) {
targetElement.prepend(buttonContainer);
} else {
console.error('Target fieldset not found.');
}
}
setTimeout(injectCustomFilterButtons, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment