Skip to content

Commit

Permalink
added fuglane script
Browse files Browse the repository at this point in the history
  • Loading branch information
on committed Aug 14, 2024
1 parent 5aa7f5b commit 6d19771
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions fuglane.user.js
Original file line number Diff line number Diff line change
@@ -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 `<a href="${url}" target="_blank">${match}</a>`;
});

replacedText = replacedText.replace(changeRegex, (match) => {
const url = `https://hjelp.ntnu.no/tas/secure/newchange?action=lookup&lookup=number&lookupValue=${match}`;
return `<a href="${url}" target="_blank">${match}</a>`;
});

replacedText = replacedText.replace(emailRegex, (match, p1) => {
const url = `https://bas02.it.ntnu.no/account/search/?name=${p1}`;
return `<a href="${url}" target="_blank">${match}</a>`;
});

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);
})();

0 comments on commit 6d19771

Please sign in to comment.