JackboxReminder

notifies you when jackbox-game ends

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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)
})();