Skip to content

Commit

Permalink
added author to bas-search. Made script to quicksearch innsida
Browse files Browse the repository at this point in the history
  • Loading branch information
on committed Aug 15, 2024
1 parent 32f82a8 commit 0aa6cd8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bas-search.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @namespace http://tampermonkey.net/
// @version 1.4.1
// @description Show a textbox on "/" key press and redirect to Cereweb search on Enter key press. Supports group search with "g:" prefix and accounts if you use no prefix or "a:" prefix.
// @author Your Name
// @author on@ntnu.no
// @match https://bas.ntnu.no/*
// @grant none
// @icon https://www.google.com/s2/favicons?sz=64&domain=ntnu.no
Expand Down
49 changes: 49 additions & 0 deletions innsida-search.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ==UserScript==
// @name Innsida Quick Search
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Show a textbox on "/" key press and redirect to Innsida search on Enter key press.
// @author on@ntnu.no
// @match https://innsida.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();
const url = `https://innsida.ntnu.no/sok?q=${encodeURIComponent(searchQuery)}&pageSize=10&curPage=1`;
window.location.href = url;
}
});

// Hide the input box when it loses focus
inputBox.addEventListener('blur', function() {
inputBox.style.display = 'none';
});
})();

0 comments on commit 0aa6cd8

Please sign in to comment.