Skip to content

Commit

Permalink
YR: added author. Topdesk: Added userscript that copies the issue num…
Browse files Browse the repository at this point in the history
…ber to clipboard if you click it
  • Loading branch information
on committed Aug 19, 2024
1 parent 36bc8c9 commit 6bb7466
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
64 changes: 64 additions & 0 deletions topdesk.user.js
Original file line number Diff line number Diff line change
@@ -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!');
});
}
}
})();
2 changes: 1 addition & 1 deletion yr.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6bb7466

Please sign in to comment.