From e724a06435e91fe50d60c6c913f1805ae32f83bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Andreas=20Nilsen?= Date: Wed, 26 Feb 2025 10:14:01 +0100 Subject: [PATCH] Fixed issue where a blank issue was copied when you clicked the refresh button on the Bookmark page --- topdesk.user.js | 56 ++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/topdesk.user.js b/topdesk.user.js index 822d09b..d1ed5b0 100644 --- a/topdesk.user.js +++ b/topdesk.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name TopDesk - Copy Issuenumber // @namespace https://git.ntnu.no/M365-Drift/MonkeyMagic/ -// @version 1.1.3 +// @version 1.1.4 // @author Øyvind Nilsen (on@ntnu.no) // @description Copies the issue number if you click it in TopDesk. It copies plain text and a clickable HTML version. So if the place you paste supports HTML, you can paste a clickable link to the issue. // @match https://hjelp.ntnu.no/tas/secure/mango/window/* @@ -72,34 +72,38 @@ const targetDiv = document.getElementById(modifiedId); if (targetDiv) { - targetDiv.style.cursor = "copy"; - targetDiv.addEventListener('click', function() { - const content = targetDiv.textContent || targetDiv.innerText; - let newContent = content; + const content = targetDiv.textContent || targetDiv.innerText; + // Only add the event listener if the content contains an incident or change number: + if (incidentRegex.test(content) || changeRegex.test(content)) { + targetDiv.style.cursor = "copy"; + targetDiv.addEventListener('click', function() { + + let newContent = content; - // Replace incident matches - if (incidentRegex.test(content)) { - newContent = newContent.replace(incidentRegex, (match) => { - return `${match}`; - }); - } + // Replace incident matches + if (incidentRegex.test(content)) { + newContent = newContent.replace(incidentRegex, (match) => { + return `${match}`; + }); + } - // Replace change matches - if (changeRegex.test(content)) { - newContent = newContent.replace(changeRegex, (match) => { - return `${match}`; - }); - } + // Replace change matches + if (changeRegex.test(content)) { + newContent = newContent.replace(changeRegex, (match) => { + return `${match}`; + }); + } - // Only update and copy if there were changes - if (newContent !== content) { - // Copy the updated content to clipboard - copyToClipboard(newContent, content); - } else { - copyToClipboard(null, content); - } - showMessage('\'' + content + '\' copied to clipboard!'); - }); + // Only update and copy if there were changes + if (newContent !== content) { + // Copy the updated content to clipboard + copyToClipboard(newContent, content); + } else { + copyToClipboard(null, content); + } + showMessage('\'' + content + '\' copied to clipboard!'); + }); + } } } })(); \ No newline at end of file