-
Notifications
You must be signed in to change notification settings - Fork 4
/
userscript.js
66 lines (61 loc) · 1.81 KB
/
userscript.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
54
55
56
57
58
59
60
61
62
63
64
65
66
// ==UserScript==
// @name $USERSCRIPT_NAME
// @namespace http://www.margonem.pl/
// @version 4.0.0
// @description Addon for the Nerthus game server in Margonem
// @author Kris Aphalon, Aldi
// @match https://nerthus.margonem.pl/
// @icon $USERSCRIPT_ICON_URL
// ==/UserScript==
(function ()
{
function start(version)
{
const gameInterface = document.cookie
.split('; ')
.find((row) => row.startsWith('interface='))
?.split('=')[1]
if (!gameInterface)
{
setTimeout(() => start(version), 500)
return
}
let logText = 'Nerthus addon version: ' + version
let src
switch (gameInterface)
{
case 'ni':
{
src = NI_VERSION_URL
break
}
case 'si':
{
src = SI_VERSION_URL
logText = `<span style="color:lime">${logText}</span>`
break
}
default:
{
const errorMsg =
'Nerthus addon couldn\'t detect your interface. ' +
'Try restarting your game or clearing cookies. ' +
'If this error persists, submit a bug on Nerthus\'s forum.'
this.error?.(errorMsg)
console.error(errorMsg)
return
}
}
this.log?.(logText)
const script = document.createElement('script')
script.src = src.replace('$VERSION', version)
document.head.appendChild(script)
}
fetch(VERSION_URL)
.then((res) => res.text())
.then(start)
.catch((error) =>
{
console.error('Unable to load nerthus addon: ', error)
})
})()