RyuFive / Chain Watcher

// ==UserScript==
// @namespace    https://openuserjs.org/users/RyuFive
// @name         Chain Watcher
// @version      0.3
// @description  Open a torn page and click a few times on the background then Press NUM_LOCK to check if sound is playing, it should then be working and will ding if timer gets below 2mins
// @license MIT
// @match        *.torn.com/*
// @include      https://www.torn.com/*
// @grant none
// ==/UserScript==


// ==OpenUserJS==
// @author RyuFive
// ==/OpenUserJS==


var player = document.createElement('audio');
player.src = 'https://proxy.notificationsounds.com/free-jingles-and-logos/smile-ringtone/download/file-sounds-1325-smile.mp3';
player.preload = 'auto';

function refreshData()
{
    var x = 1; // 1 Seconds

    // Do your thing here
    var chain = parseInt(document.querySelector("#barChain").text.split('k')[1].split(':')[0]);
    if (chain == 0 || chain == 1) {
        player.play();
    }

    setTimeout(refreshData, x*1000);
}

refreshData()

window.addEventListener ("keydown", keyboardHandler, false);

function keyboardHandler (zEvent) {
    var bBlockDefaultAction = false;

    //--- Assume we want only the plain keys, not the modified versions.
    if (zEvent.pKey || zEvent.ctrlKey || zEvent.shiftKey) {
        //-- Do nothing (most user-friendly option, in most cases).
    }
    else {
        if (zEvent.keyCode == 144) {
            player.play();
        }
    }

    if (bBlockDefaultAction) {
        zEvent.preventDefault ();
        zEvent.stopPropagation ();
    }
}