Skip to content

Commit

Permalink
fixed problem when click-listener was added two times. Edited styling…
Browse files Browse the repository at this point in the history
… on titles. Html data in clipboard now works
  • Loading branch information
on committed Sep 5, 2025
1 parent a4d933b commit 688e7fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions bas-search.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name BAS Quick Search
// @namespace http://tampermonkey.net/
// @version 1.7.8
// @version 1.7.9
// @description Quick search using `Ctrl` + `Shift` + `F` hotkey, group search with "g:" and person search with "p:" prefix. Navigate tabs with Ctrl + Left/Right keys. Navigate search results with up and down keys.
// @author Øyvind Nilsen (on@ntnu.no)
// @match https://bas.ntnu.no/*
Expand Down Expand Up @@ -68,12 +68,17 @@
const h1Element = titleDiv.querySelector('h1');
if (!h1Element) return;

// Check if handler is already attached
if (h1Element.hasAttribute('data-click-handler-attached')) {
return;
}

const titleText = h1Element.textContent.trim();

// Check if it's a group or account page
if (titleText.startsWith('Group ') || titleText.startsWith('Account ') || titleText.startsWith('Person ')) {
const objectType = titleText.split(' ')[0].toLowerCase();
const objectName = titleText.split(' ')[1];
var objectType = titleText.split(' ')[0].toLowerCase();
const objectName = titleText.substring(titleText.indexOf(' ') + 1);

if (objectType === 'group') {
var baseUrl = 'https://bas.ntnu.no/group/view?id=';
Expand All @@ -83,8 +88,12 @@
var baseUrl = 'https://bas.ntnu.no/person/view?id=';
}

//Set the first letter in objectType to uppercase
objectType = objectType.charAt(0).toUpperCase() + objectType.slice(1);

h1Element.style.cursor = 'copy';
h1Element.style.userSelect = 'none';
h1Element.innerHTML = `<span>${objectType}</span><span style="font-weight:normal;"> ${objectName}</span>`;

h1Element.addEventListener('click', function(event) {
event.preventDefault();
Expand All @@ -97,10 +106,13 @@

const htmlLink = `<a href="${objectUrl}" target="_blank">${objectName}</a>`;

copyToClipboard(null, objectName);
copyToClipboard(htmlLink, objectName);

showMessage(objectName);
});

// Mark that the handler is attached
h1Element.setAttribute('data-click-handler-attached', 'true');
}
}

Expand Down
1 change: 1 addition & 0 deletions doc/bas-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Press `Ctrl` + `Shift` + `F` to open the search box/menu. Use `` and `` to navigate. And press `Enter` to select.
- For group search, use the prefix `g:` followed by the group name (e.g., `g:groupname`)
- Person search with the prefix `p:` followed by the person's name (e.g., `p:personname`). If you write a iso date (e.g., `1990-01-01`), it will search for persons with that birthdate.
- Click on Person/Account/Group titles to copy the name to clipboard. A link to the profile is also included if destination supports html data.
- In the search result pages, use `` and `` to navigate through the results. And press `Enter` to open the selected result.
- Press `Ctrl` + `` / `` to navigate to the next/previous tab.
- On the login page, the username field is automatically focused.
Expand Down

0 comments on commit 688e7fb

Please sign in to comment.