diff --git a/bas-search.user.js b/bas-search.user.js
index eee8f8a..3a4dbbd 100644
--- a/bas-search.user.js
+++ b/bas-search.user.js
@@ -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/*
@@ -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=';
@@ -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 = `${objectType} ${objectName}`;
h1Element.addEventListener('click', function(event) {
event.preventDefault();
@@ -97,10 +106,13 @@
const htmlLink = `${objectName}`;
- copyToClipboard(null, objectName);
+ copyToClipboard(htmlLink, objectName);
showMessage(objectName);
});
+
+ // Mark that the handler is attached
+ h1Element.setAttribute('data-click-handler-attached', 'true');
}
}
diff --git a/doc/bas-search.md b/doc/bas-search.md
index f3a9129..8e82d13 100644
--- a/doc/bas-search.md
+++ b/doc/bas-search.md
@@ -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.