-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJackboxReminder.user.js
111 lines (105 loc) · 3.54 KB
/
JackboxReminder.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// ==UserScript==
// @name JackboxReminder
// @name:ru JackboxReminder
// @name:en JackboxReminder
// @namespace yes
// @version 1.1
// @description notifies you when jackbox-game ends
// @description:ru Показывает вам уведомление, когда игра в Jackbox закончена.
// @author lenchik-lox
// @include http*://jackbox.*/*
// @include http*://jackbox.fun/*
// @icon https://www.google.com/s2/favicons?domain=jackbox.fun
// @grant GM_notification
// @grant GM_openInTab
// ==/UserScript==
(function() {
var interval;
var labeltext;
var isTVhost = location.host == "jackbox.tv";
if (isTVhost) {
labeltext = "Notify me when game ends";
}
else {
labeltext = "Уведомить меня когда игра закончится";
}
function CheckGameState() {
let code = document.querySelector('#roomcode').value;
let req = new XMLHttpRequest();
req.open('GET','https://blobcast.jackboxgames.com/room/'+code);
req.responseType = "json";
req.onreadystatechange = function () {
console.log('e');
if (req.readyState == XMLHttpRequest.DONE) {
var resp = req.response
if (resp.success == false) {
GM_notification(`Click to open ${location.host} tab`,`Game ${code} has ended`,'https://www.google.com/s2/favicons?domain=jackbox.fun',openJackboxTab);
clearInterval(interval)
document.querySelector('#chkbx').checked = false;
}
}
}
req.send();
}
function openJackboxTab() {
GM_openInTab(location.href,{
active:true
})
}
setTimeout(()=>{
'use strict';
var style = document.createElement('style');
style.type = "text/css";
style.innerText = `
.CGSContainer {
margin-top:10px;
}
.CGSContainer .label {
user-select:none;
padding-left:20px !important;
}
.CGSContainer .checkbox {
position:absolute;
}
`;
var chkbx = document.createElement('input');
chkbx.type = "checkbox";
chkbx.className = "checkbox";
chkbx.id = "chkbx";
var label = document.createElement('label');
label.className = "label text-signin jbg";
label.innerText = labeltext;
label.setAttribute('for',chkbx.id);
label.setAttribute('data-v-2ba6adc4','');
var div = document.createElement('div');
div.className = "CGSContainer";
div.style.display = "none";
if (isTVhost) {
div.style.marginTop = "-5px";
}
else {
div.style.marginTop = "10px";
}
chkbx.onchange = (e) => {
if (e.target.checked) {
interval = setInterval(CheckGameState,1000);
}
else {
clearInterval(interval);
}
}
document.querySelector('#roomcode').oninput = (e) => {
if (document.querySelector('#roomcode').value.length != 4) {
div.style.display = "none";
}
else {
div.style.display = "";
}
document.querySelector('#chkbx').checked = false;
clearInterval(interval)
}
div.append(chkbx,label);
document.head.append(style)
document.querySelector('#roomcode').after(div);
},500)
})();