Skip to content

Commit

Permalink
A tiny edit to avoid some errors in the console and to optimalize the…
Browse files Browse the repository at this point in the history
… script a little bit
  • Loading branch information
on committed Oct 24, 2024
1 parent 3f3fab2 commit 66dd1c3
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions topdesk.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'text/plain': textBlob
})
];

navigator.clipboard.write(data).then(() => {
console.log(html ? 'HTML and text copied to clipboard' : 'Text copied to clipboard');
}).catch(err => {
Expand Down Expand Up @@ -64,14 +64,15 @@
}, 900);
}

// Find the first div tag and modify its id
// Find the first div tag
const firstDiv = document.querySelector('div');

if (firstDiv && firstDiv.id) {
const modifiedId = firstDiv.id.slice(0, -1) + '8';
const targetDiv = document.getElementById(modifiedId);
targetDiv.style.cursor = "copy";
if (targetDiv) {

if (targetDiv) {
targetDiv.style.cursor = "copy";
targetDiv.addEventListener('click', function() {
const content = targetDiv.textContent || targetDiv.innerText;
let newContent = content;
Expand All @@ -82,16 +83,16 @@
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>`;
});
}

// Only update and copy if there were changes
if (newContent !== content) {
if (newContent !== content) {
// Copy the updated content to clipboard
copyToClipboard(newContent, content);
} else {
Expand Down

0 comments on commit 66dd1c3

Please sign in to comment.