forked from Sharparam/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KAURandomExam.user.js
54 lines (43 loc) · 1.63 KB
/
KAURandomExam.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// ==UserScript==
// @name KAURandomExam
// @namespace http://sharparam.com/
// @description Gives the option to open a random exam from the list of exams on KAU
// @include https://www3.kau.se/minsida/sips.php
// @version 1.0.0
// @grant none
// @license MIT; http://opensource.org/licenses/MIT
// @copyright 2016, Sharparam (http://sharparam.com/)
// @homepageURL https://github.com/Sharparam/UserScripts
// @supportURL https://github.com/Sharparam/UserScripts/issues
// @downloadURL https://github.com/Sharparam/UserScripts/raw/master/KAURandomExam.user.js
// @updateURL https://github.com/Sharparam/UserScripts/raw/master/KAURandomExam.meta.js
// ==/UserScript==
var div = document.createElement('div');
div.style = 'clear:both;';
var a = document.createElement('a');
a.href = '#';
var text = document.createTextNode('Open random exam.');
a.appendChild(text);
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
function openRandomExam() {
var links = document.querySelectorAll('div#testList > table > tbody > tr > td:first-child > a');
if (links.length == 0) {
alert('Load some exams first!');
return;
}
var link = links[getRandomInt(0, links.length - 1)].href;
window.open(link, '_blank');
};
a.onclick = function(event) {
console.log('onclick entered');
event.preventDefault();
event.stopPropagation();
openRandomExam();
console.log('onclick exiting');
};
div.appendChild(a);
var content = document.querySelector('div#content div.content');
var insertPoint = content.querySelector('div:nth-child(3)');
content.insertBefore(div, insertPoint);