-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| })(); |