Your turn to move notification

Ok. Here’s a script. I don’t know JavaScript so this is probably not that great coding. It croaks on each increment and once an hour if it’s above base level, and only if it’s on home page.

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://online-go.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var base_level = 7;
    var current_level = base_level;
    var croak_audio = new Audio("https://notificationsounds.com/soundfiles/74071a673307ca7459bcf75fbd024e09/file-f0_bullfrog.mp3");

    function croak() {
        croak_audio.play();
    }

    function get_value() {
        var location = window.location.href
        var elements = $('.active.count span')
        if (elements.length && (location == "https://online-go.com/overview" || location == "https://online-go.com/")) {
            return parseInt(elements[0].textContent);
        } else {
            return -1;
        }
    }

    function increment_checker() {
        setTimeout(increment_checker, 5*1000);
        var v = get_value();
        if (v < 0) {
            return;
        }
        if (v > current_level) {
            croak();
        }
        current_level = v;
    }

    function base_checker() {
        setTimeout(base_checker, 60*60*1000);
        var v = get_value();
        if (v < 0) {
            return;
        }
        if (v > base_level) {
            croak();
        }
    }

    setTimeout(increment_checker, 60*1000);
    setTimeout(base_checker, 60*60*1000);
})();

I run it on separate computer I have turned on most of the time. So I can hear croaks at 3 am.

5 Likes