From 6bb7466d31186f7cb44fdbd9bf4d26c4b7efce4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Andreas=20Nilsen?= Date: Mon, 19 Aug 2024 13:37:14 +0200 Subject: [PATCH] YR: added author. Topdesk: Added userscript that copies the issue number to clipboard if you click it --- topdesk.user.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ yr.user.js | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 topdesk.user.js diff --git a/topdesk.user.js b/topdesk.user.js new file mode 100644 index 0000000..94639f8 --- /dev/null +++ b/topdesk.user.js @@ -0,0 +1,64 @@ +// ==UserScript== +// @name TopDesk - Copy Issuenumber +// @namespace http://tampermonkey.net/ +// @version 1.0 +// @author on@ntnu.no +// @description Copies the issue number if you click it in TopDesk +// @match *://*/* +// @grant none +// @updateURL https://git.ntnu.no/M365-Drift/MonkeyMagic/raw/main/topdesk.user.js +// @downloadURL https://git.ntnu.no/M365-Drift/MonkeyMagic/raw/main/topdesk.user.js +// ==/UserScript== + +(function() { + 'use strict'; + + // Function to copy text to clipboard + function copyToClipboard(text) { + const textarea = document.createElement('textarea'); + textarea.value = text; + document.body.appendChild(textarea); + textarea.select(); + document.execCommand('copy'); + document.body.removeChild(textarea); + } + + // Function to show a fading message box + function showMessage(message) { + const messageBox = document.createElement('div'); + messageBox.textContent = message; + messageBox.style.position = 'fixed'; + messageBox.style.bottom = '20px'; + messageBox.style.left = '50%'; + messageBox.style.transform = 'translateX(-50%)'; + messageBox.style.backgroundColor = '#333'; + messageBox.style.color = '#fff'; + messageBox.style.padding = '10px 20px'; + messageBox.style.borderRadius = '5px'; + messageBox.style.zIndex = '10000'; + messageBox.style.opacity = '1'; + messageBox.style.transition = 'opacity 2s ease-out'; + document.body.appendChild(messageBox); + + setTimeout(() => { + messageBox.style.opacity = '0'; + setTimeout(() => { + document.body.removeChild(messageBox); + }, 2000); + }, 2000); + } + + // Find the first div tag and modify its id + const firstDiv = document.querySelector('div'); + if (firstDiv && firstDiv.id) { + const modifiedId = firstDiv.id.slice(0, -1) + '8'; + const targetDiv = document.getElementById(modifiedId); + if (targetDiv) { + targetDiv.addEventListener('click', function() { + const content = targetDiv.textContent || targetDiv.innerText; + copyToClipboard(content); + showMessage('\'' + content + '\' copied to clipboard!'); + }); + } + } +})(); \ No newline at end of file diff --git a/yr.user.js b/yr.user.js index 5f2d601..f3bb6d2 100644 --- a/yr.user.js +++ b/yr.user.js @@ -3,7 +3,7 @@ // @namespace http://tampermonkey.net/ // @version 1.1.1 // @description Hotkeys 'alt+l', 'alt+r', or 'alt+v' for yr.no -// @author Your Name +// @author on@ntnu.no // @match https://www.yr.no/* // @grant none // @updateURL https://git.ntnu.no/M365-Drift/MonkeyMagic/raw/main/yr.user.js