From 597dfc2febb5b2de676267dab45ef2e0fd6d5918 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20B=C3=B8rnes?= Date: Wed, 23 Oct 2024 14:46:16 +0200 Subject: [PATCH] Update topdesk-highlight-summary.user.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (Hopefully) fixed accidentally tampering (pun intended) with Øyvind's tampermonkey script. --- topdesk-highlight-summary.user.js | 36 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/topdesk-highlight-summary.user.js b/topdesk-highlight-summary.user.js index e356516..776fc22 100644 --- a/topdesk-highlight-summary.user.js +++ b/topdesk-highlight-summary.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name TOPdesk - Highlight Summary // @namespace http://tampermonkey.net/ -// @version 1.1 +// @version 1.2 // @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/* @@ -16,8 +16,8 @@ // Function to highlight the summary function highlightSummary() { - // Find all div elements - const divs = document.querySelectorAll('div'); + // Find all div elements with specific class or attribute + const divs = document.querySelectorAll('div[guielement="crt-content-label"]'); divs.forEach(div => { // Get the inner HTML of the div @@ -49,20 +49,22 @@ }); } - // Run the function to highlight the summary - highlightSummary(); + // Run the function to highlight the summary after the DOM is fully loaded + document.addEventListener('DOMContentLoaded', () => { + highlightSummary(); - // Debounce function to limit the frequency of highlightSummary calls - function debounce(func, wait) { - let timeout; - return function(...args) { - clearTimeout(timeout); - timeout = setTimeout(() => func.apply(this, args), wait); - }; - } + // Debounce function to limit the frequency of highlightSummary calls + function debounce(func, wait) { + let timeout; + return function(...args) { + clearTimeout(timeout); + timeout = setTimeout(() => func.apply(this, args), wait); + }; + } - // Reapply the highlighting 1 second after the window is resized - window.addEventListener('resize', debounce(() => { - highlightSummary(); - }, 1000)); + // Reapply the highlighting 1 second after the window is resized + window.addEventListener('resize', debounce(() => { + highlightSummary(); + }, 1000)); + }); })();