Bookie Alert

Add an alert to Bookie page if there is a bet which closes in less than 24h

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Bookie Alert
// @namespace    https://www.torn.com/profiles.php?XID=2063442
// @version      0.1.1
// @description  Add an alert to Bookie page if there is a bet which closes in less than 24h
// @author       dgumf
// @match        *.torn.com/bookie.php
// @grant        none
// ==/UserScript==

var debug = true;
var initialTimeout = 500;
var interval = 2000;

setTimeout(handleBets, initialTimeout);
setInterval(handleBets, interval);

function handleBets () {

    log_debug('in > handleBets');

    var jNode = $('#back');

    var greenItem;
    var countDown;

    // console.log(jNode.text());
    var backText = jNode.text();

    if (backText == 'Back'){
        log_debug('single bet page');
        greenItem = $('li.bg-green');
        //console.log(greenItem);
        if (greenItem.html()){
            countDown = $('.hasCountdown');
        }
    }
    else if (backText == 'Back to Casino'){
        log_debug('all bets page');
        greenItem = $('li.bg-green').eq(0);
        //console.log(greenItem);
        if (greenItem.html()){
            countDown = greenItem.find('span.hasCountdown');
        }
    }
    else {
        log_debug('No Back button yet');
    }

    var vl;
    if (countDown){
        vl = countDown.text();
    }

    log_debug(vl);

    var infoBox = $('div.right-round');

    if (vl && vl.length > 0 && (vl.indexOf('d') == -1 || vl.indexOf(' 0d') > 0) ){
        $('.dgumf').remove();
        var addedAlert = '<div class="info-msg border-round dgumf" style="background-color: #ff5050"><i class="info-icon"></i><div class="delimiter"><div class="msg right-round">You have a bet which locks in less than 24 hours: ' + vl + '</div></div></div>';
        infoBox.append(addedAlert);
        greenItem.attr("style", "background-color: #ff5050");
    }
}

function log_debug(message){
    if (debug){
        console.log('[DEBUG] ' + message);
    }
}

function log_info(message){
    console.log('[INFO] ' + message);
}