Skip to content

Fixed issue where a blank issue was copied when you clicked the refre… #21

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 30 additions & 26 deletions topdesk.user.js
Original file line number Diff line number Diff line change
@@ -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/*
Expand Down Expand Up @@ -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 `<a href="https://hjelp.ntnu.no/tas/secure/incident?action=lookup&lookup=naam&lookupValue=${match}" target="_blank">${match}</a>`;
});
}
// Replace incident matches
if (incidentRegex.test(content)) {
newContent = newContent.replace(incidentRegex, (match) => {
return `<a href="https://hjelp.ntnu.no/tas/secure/incident?action=lookup&lookup=naam&lookupValue=${match}" target="_blank">${match}</a>`;
});
}

// Replace change matches
if (changeRegex.test(content)) {
newContent = newContent.replace(changeRegex, (match) => {
return `<a href="https://hjelp.ntnu.no/tas/secure/newchange?action=lookup&lookup=number&lookupValue=${match}" target="_blank">${match}</a>`;
});
}
// Replace change matches
if (changeRegex.test(content)) {
newContent = newContent.replace(changeRegex, (match) => {
return `<a href="https://hjelp.ntnu.no/tas/secure/newchange?action=lookup&lookup=number&lookupValue=${match}" target="_blank">${match}</a>`;
});
}

// 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!');
});
}
}
}
})();