-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script for quick cereweb searches
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // ==UserScript== | ||
| // @name BAS Quick Search | ||
| // @namespace http://tampermonkey.net/ | ||
| // @version 1.4 | ||
| // @description Show a textbox on "/" key press and redirect to NTNU search on Enter key press. Supports group search with "g:" prefix and accounts if you use no prefix or "a:" prefix. | ||
| // @author Your Name | ||
| // @match https://bas.ntnu.no/* | ||
| // @grant none | ||
| // ==/UserScript== | ||
|
|
||
| (function() { | ||
| 'use strict'; | ||
|
|
||
| // Create and style the input box | ||
| const inputBox = document.createElement('input'); | ||
| inputBox.type = 'text'; | ||
| inputBox.style.position = 'fixed'; | ||
| inputBox.style.top = '10px'; | ||
| inputBox.style.left = '50%'; | ||
| inputBox.style.transform = 'translateX(-50%)'; | ||
| inputBox.style.zIndex = '10000'; | ||
| inputBox.style.display = 'none'; | ||
| inputBox.style.padding = '5px'; | ||
| inputBox.style.fontSize = '16px'; | ||
| document.body.appendChild(inputBox); | ||
|
|
||
| // Show the input box when "/" is pressed | ||
| document.addEventListener('keydown', function(event) { | ||
| if (event.key === '/') { | ||
| event.preventDefault(); | ||
| inputBox.style.display = 'block'; | ||
| inputBox.focus(); | ||
| } | ||
| }); | ||
|
|
||
| // Redirect to the search URL when Enter is pressed | ||
| inputBox.addEventListener('keydown', function(event) { | ||
| if (event.key === 'Enter') { | ||
| const searchQuery = inputBox.value.trim(); | ||
| let url; | ||
| if (searchQuery.toLowerCase().startsWith('g:')) { | ||
| const groupName = searchQuery.substring(2).trim(); | ||
| url = `https://bas.ntnu.no/group/search/?name=${encodeURIComponent(groupName)}`; | ||
| } else { | ||
| const accountName = searchQuery.toLowerCase().startsWith('a:') ? searchQuery.substring(2).trim() : searchQuery; | ||
| url = `https://bas.ntnu.no/account/search/?name=${encodeURIComponent(accountName)}`; | ||
| } | ||
| window.location.href = url; | ||
| } | ||
| }); | ||
|
|
||
| // Hide the input box when it loses focus | ||
| inputBox.addEventListener('blur', function() { | ||
| inputBox.style.display = 'none'; | ||
| }); | ||
| })(); |