diff --git a/fuglane.user.js b/fuglane.user.js new file mode 100644 index 0000000..551fe3e --- /dev/null +++ b/fuglane.user.js @@ -0,0 +1,52 @@ +// ==UserScript== +// @name Fuglane - Issue links +// @namespace http://tampermonkey.net/ +// @version 1.3 +// @description Replace NTNU issue numbers, change numbers and upn's with clickable links to TopDesk +// @author on@ntnu.no +// @match https://fuglane.it.ntnu.no/* +// @grant none +// @icon https://www.google.com/s2/favicons?sz=64&domain=ntnu.no +// ==/UserScript== + +(function() { + 'use strict'; + + // Function to replace text with links + function replaceTextWithLinks(node) { + if (node.nodeType === Node.TEXT_NODE) { + const incidentRegex = /(NTNU[0-9]{7})/gi; + const changeRegex = /(NTNU_C[0-9]{7})/gi; + const emailRegex = /([a-z0-9-_]{2,40})(?:@ntnu\.no)/gi; + const text = node.textContent; + + let replacedText = text.replace(incidentRegex, (match) => { + const url = `https://hjelp.ntnu.no/tas/secure/incident?action=lookup&lookup=naam&lookupValue=${match}`; + return `${match}`; + }); + + replacedText = replacedText.replace(changeRegex, (match) => { + const url = `https://hjelp.ntnu.no/tas/secure/newchange?action=lookup&lookup=number&lookupValue=${match}`; + return `${match}`; + }); + + replacedText = replacedText.replace(emailRegex, (match, p1) => { + const url = `https://bas02.it.ntnu.no/account/search/?name=${p1}`; + return `${match}`; + }); + + if (replacedText !== text) { + const span = document.createElement('span'); + span.innerHTML = replacedText; + node.parentNode.replaceChild(span, node); + } + } else if (node.nodeType === Node.ELEMENT_NODE && node.nodeName !== 'SCRIPT' && node.nodeName !== 'STYLE') { + for (let i = 0; i < node.childNodes.length; i++) { + replaceTextWithLinks(node.childNodes[i]); + } + } + } + + // Run the function on the entire document body + replaceTextWithLinks(document.body); +})(); \ No newline at end of file