Last active
April 9, 2025 12:45
-
-
Save fanuch/1511dd5423e0c68bb9d66f63b3a9c875 to your computer and use it in GitHub Desktop.
Block Click to Edit on Jira Issue
This file contains hidden or 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 Disable Jira Click Edit | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Disable click edit in Jira issue descriptions | |
// @author fanuch | |
// @match https://*.atlassian.net/browse/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=atlassian.net | |
// @grant none | |
// ==/UserScript== | |
/** | |
* Toggles the double-click-to-edit functionality in Jira issue descriptions. | |
* The script creates a toggle button that allows the user to enable or disable editing. | |
* The button uses emoji icons to represent the current state: | |
* - π (locked) indicates that editing is disabled | |
* - βοΈ (pencil) indicates that editing is enabled | |
*/ | |
(function() { | |
'use strict'; | |
let isDoubleClickEnabled = false; // Set initial value to false | |
/** | |
* Creates the toggle button and inserts it into the Jira issue description UI. | |
*/ | |
function createToggleButton() { | |
const listDivs = document.querySelectorAll('div[role="list"]'); | |
if (listDivs.length >= 2 && listDivs[1].firstElementChild) { | |
const toggleButton = listDivs[1].firstElementChild.cloneNode(true); | |
toggleButton.textContent = 'π'; | |
toggleButton.id = 'toggle-button'; | |
toggleButton.addEventListener('click', toggleDoubleClickEdit); | |
listDivs[1].insertBefore(toggleButton, listDivs[1].firstChild); | |
} | |
} | |
/** | |
* Toggles the double-click-to-edit functionality when the toggle button is clicked. | |
* Updates the button icon and adds/removes the event listener on the description element. | |
*/ | |
function toggleDoubleClickEdit() { | |
isDoubleClickEnabled = !isDoubleClickEnabled; | |
const button = document.getElementById('toggle-button'); | |
const descriptionElement = document.querySelector('.ak-renderer-document'); | |
if (isDoubleClickEnabled) { | |
button.textContent = 'βοΈ'; | |
descriptionElement.removeEventListener('click', handleClick, true); | |
} else { | |
button.textContent = 'π'; | |
descriptionElement.addEventListener('click', handleClick, true); | |
} | |
} | |
/** | |
* Handles the click event on the Jira issue description element. | |
* Stops the event propagation to prevent the default double-click-to-edit behavior. | |
* @param {Event} e - The click event object. | |
*/ | |
function handleClick(e) { | |
e.stopPropagation(); | |
console.log("Blocked click-edit of Jira issue description. You're welcome."); | |
} | |
// Wait for the Jira issue description UI to load before creating the toggle button | |
setTimeout(function() { | |
createToggleButton(); | |
const descriptionElement = document.querySelector('.ak-renderer-document'); | |
if (descriptionElement) { | |
descriptionElement.addEventListener('click', handleClick, true); | |
} | |
}, 200); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this!