diff --git a/topdesk.user.js b/topdesk.user.js
index d1ed5b0..e50f5f6 100644
--- a/topdesk.user.js
+++ b/topdesk.user.js
@@ -1,9 +1,9 @@
// ==UserScript==
// @name TopDesk - Copy Issuenumber
// @namespace https://git.ntnu.no/M365-Drift/MonkeyMagic/
-// @version 1.1.4
+// @version 1.2.0
// @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.
+// @description Copies the issue number if you click it in TopDesk or with the hotkey `ctrl` + `alt` + `c`. 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/*
// @grant none
// @icon https://www.google.com/s2/favicons?sz=64&domain=topdesk.com
@@ -64,6 +64,43 @@
}, 900);
}
+ function copyIssueNumber() {
+ // Get the content from the target div when the function is called
+ const firstDiv = document.querySelector('div');
+ if (!firstDiv || !firstDiv.id) return;
+
+ const modifiedId = firstDiv.id.slice(0, -1) + '8';
+ const targetDiv = document.getElementById(modifiedId);
+ if (!targetDiv) return;
+
+ const content = targetDiv.textContent || targetDiv.innerText;
+ let newContent = content;
+
+ // 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}`;
+ });
+ }
+
+ // 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!');
+ }
+
+
// Find the first div tag
const firstDiv = document.querySelector('div');
@@ -76,32 +113,25 @@
// 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 change matches
- if (changeRegex.test(content)) {
- newContent = newContent.replace(changeRegex, (match) => {
- return `${match}`;
- });
- }
+ targetDiv.addEventListener('click', copyIssueNumber);
- // Only update and copy if there were changes
- if (newContent !== content) {
- // Copy the updated content to clipboard
- copyToClipboard(newContent, content);
- } else {
- copyToClipboard(null, content);
+ // Add keyboard event listener for Ctrl+Alt+C
+ document.addEventListener('keydown', function(event) {
+ if (event.ctrlKey && event.altKey && event.key === 'c') {
+ // Check if there's an issue number to copy
+ const firstDiv = document.querySelector('div');
+ if (firstDiv && firstDiv.id) {
+ const modifiedId = firstDiv.id.slice(0, -1) + '8';
+ const targetDiv = document.getElementById(modifiedId);
+ if (targetDiv) {
+ const content = targetDiv.textContent || targetDiv.innerText;
+ if (incidentRegex.test(content) || changeRegex.test(content)) {
+ event.preventDefault(); // Prevent default behavior
+ copyIssueNumber();
+ }
+ }
}
- showMessage('\'' + content + '\' copied to clipboard!');
+ }
});
}
}