Skip to content

Commit

Permalink
Added 2 new scripts
Browse files Browse the repository at this point in the history
"TOPdesk Highlight summary" and "Custom CSS and Text Removal for innsida.ntnu.no"
  • Loading branch information
magnborn authored and GitHub Enterprise committed Oct 23, 2024
1 parent 595d089 commit fe8cc5c
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 0 deletions.
111 changes: 111 additions & 0 deletions innsida-custom-css.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// ==UserScript==
// @name Custom CSS and Text Removal for innsida.ntnu.no
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Apply custom CSS and remove text in innsida.ntnu.no
// @author Magnus Børnes (magnborn@ntnu.no)
// @match https://innsida.ntnu.no/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=ntnu.no
// @grant none
// @updateURL https://git.ntnu.no/M365-Drift/MonkeyMagic/raw/main/innsida-custom-css.user.js
// @downloadURL https://git.ntnu.no/M365-Drift/MonkeyMagic/raw/main/innsida-custom-css.user.js
// ==/UserScript==

(function() {
'use strict';

// Function to apply custom CSS
function applyCustomCSS() {
var css = `
.content-width {
max-width: 100% !important;
}
/* Åpnede saker */
.svelte-1y4o19j {
margin:0 !important;
border: 0 0 0 10px #F00 solid;
}
article a {
font-weight: 100 !important;
}
.floating-iframe {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 600px;
border: none;
}
aside {
position: relative;
}
`;
var style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
document.head.appendChild(style);
}

// Function to remove text content after delimiters
function removeTextContent() {
var links = document.querySelectorAll('article a');
links.forEach(function(link) {
var text = link.textContent;
var patterns = [
' / ', ' | ',
' \u00A0/\u00A0 ', ' \u00A0|\u00A0 ',
' /\u00A0', '\u00A0/ ',
' |\u00A0', '\u00A0| '
];
var removed = false;
patterns.forEach(function(pattern) {
var index = text.indexOf(pattern);
if (index !== -1 && !removed) {
link.textContent = text.substring(0, index);
removed = true;
}
});
});
}

// New function to insert iframe
function insertIframe() {
setTimeout(function() {
var iframe = document.createElement('iframe');
iframe.src = 'https://copilotstudio.microsoft.com/environments/Default-09a10672-822f-4467-a5ba-5bb375967c05/bots/cre79_ntnuCopilot/webchat?__version__=2';
iframe.className = 'floating-iframe';

var targetElement = document.evaluate('/html/body/div/div[2]/aside', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (targetElement) {
targetElement.appendChild(iframe);
console.log('XPath found: iframe inserted.');
} else {
document.body.appendChild(iframe);
console.log('XPath not found: iframe added to body.');
}
}, 2000); // Delay of 2000 milliseconds
}

// Function to observe DOM changes
function observeDOMChanges() {
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes.length) {
applyCustomCSS();
removeTextContent();
}
});
});

observer.observe(document.body, { childList: true, subtree: true });
}

// Initial application of custom CSS and text removal
applyCustomCSS();
removeTextContent();
insertIframe();

// Start observing DOM changes
observeDOMChanges();
})();
47 changes: 47 additions & 0 deletions topdesk-highlight-summary.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ==UserScript==
// @name TOPdesk - Highlight Summary
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Highlight the summary section in a box with rounded corners and white background
// @author Magnus Børnes (magnborn@ntnu.no)
// @match https://hjelp.ntnu.no/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=topdesk.com
// @grant none
// @updateURL https://git.ntnu.no/M365-Drift/MonkeyMagic/raw/main/topdesk-highlight-summary.user.js
// @downloadURL https://git.ntnu.no/M365-Drift/MonkeyMagic/raw/main/topdesk-highlight-summary.user.js
// ==/UserScript==

(function() {
'use strict';

// Function to highlight the summary
function highlightSummary() {
// Find all div elements
const divs = document.querySelectorAll('div');

divs.forEach(div => {
// Get the inner HTML of the div
let html = div.innerHTML;

// Match the summary text
const summaryMatch = html.match(/<br>Summary: (.*?)\.<br><br>/);

if (summaryMatch) {
// Extract the summary text
const summaryText = summaryMatch[0];

// Create a highlighted box
const highlightedBox = `<div style="border: 2px solid #000; border-radius: 10px; background-color: #fff; padding: 10px; margin: 10px 0;">${summaryText}</div>`;

// Replace the summary text with the highlighted box
html = html.replace(summaryText, highlightedBox);

// Update the div's inner HTML
div.innerHTML = html;
}
});
}

// Run the function to highlight the summary
highlightSummary();
})();

0 comments on commit fe8cc5c

Please sign in to comment.