Skip to content

Commit

Permalink
Update topdesk-highlight-summary.user.js.
Browse files Browse the repository at this point in the history
Highlight dates and some formatting.
  • Loading branch information
magnborn authored and GitHub Enterprise committed Oct 23, 2024
1 parent 0175812 commit 6496127
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions topdesk-highlight-summary.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name TOPdesk - Highlight Summary
// @namespace http://tampermonkey.net/
// @version 1.0
// @version 1.1
// @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/*
Expand All @@ -26,15 +26,22 @@
// Match the summary text
const summaryMatch = html.match(/<br>Summary: (.*?)\.<br><br>/);

if (summaryMatch) {
// Extract the summary text
const summaryText = summaryMatch[0];
if (summaryMatch && !div.querySelector('.highlighted-summary')) {
// Extract the summary text without "Summary: "
let summaryText = summaryMatch[1];

// 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>`;
// Make all dates bold
summaryText = summaryText.replace(/(\b(?:early|mid|late)?-?\s?(?:January|February|March|April|May|June|July|August|September|October|November|December)\s?\d{0,4}(?:\s\(\w+\s\d{4}\))?\b)/g, '<strong>$1</strong>');

// Create a highlighted box with a heading
const highlightedBox = `
<div class="highlighted-summary" style="border: 1px solid #000; border-radius: 10px; background-color: #fff; padding: 10px; margin: 10px 0; max-width: 600px;">
<h3>Summary</h3>
<p>${summaryText}.</p>
</div>`;

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

// Update the div's inner HTML
div.innerHTML = html;
Expand All @@ -44,4 +51,18 @@

// Run the function to highlight the summary
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);
};
}

// Reapply the highlighting 1 second after the window is resized
window.addEventListener('resize', debounce(() => {
highlightSummary();
}, 1000));
})();

0 comments on commit 6496127

Please sign in to comment.