From 66dd1c34811156c04b324f4185b2ac2b2fc40c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Andreas=20Nilsen?= Date: Thu, 24 Oct 2024 07:31:27 +0200 Subject: [PATCH] A tiny edit to avoid some errors in the console and to optimalize the script a little bit --- topdesk.user.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/topdesk.user.js b/topdesk.user.js index daa1657..cd476e3 100644 --- a/topdesk.user.js +++ b/topdesk.user.js @@ -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 => { @@ -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; @@ -82,16 +83,16 @@ 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) { + if (newContent !== content) { // Copy the updated content to clipboard copyToClipboard(newContent, content); } else {