CSGL TimeZone Changer

Change CSGO timezones.

2014-09-26 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        CSGL TimeZone Changer
// @version     1.3
// @description Change CSGO timezones.
// @match       http://csgolounge.com/*
// @match 		http://dota2lounge.com/*
// @require     http://code.jquery.com/jquery-2.1.1.js
// @copyright   Josh Hubbard
// @namespace 	https://greasyfork.org/users/5596
// ==/UserScript==

// TODO: Dry up the code. Things need to be speeded up.

$(function () {
    var dt = new Date(),
        tzOffset = (dt.getTimezoneOffset()/60) + 2,
        AMorPM = "";
    
    $timeBox = $('.gradient').first().find('.half:eq(2)');
    
    // Converts CEST to local on match page.
    if ($timeBox.length) {
        var timeInCEST = $timeBox.text(),
            hour = timeInCEST.split(" ")[0].split(":")[0],
            minute = timeInCEST.split(" ")[0].split(":")[1];
        
        hour = hour - tzOffset;
        
        if (hour < 0) hour = 24 + hour;  
        
        if (hour == 12) {
            AMorPM = "PM";
        } else if (hour > 12) {
            hour = hour - 12;
            AMorPM = "PM";      
        } else {
            AMorPM = "AM";
        }
        
        $timeBox.html("(" + hour + ":" + minute + " " + AMorPM + ") " + $timeBox.html());
        
    }
    
    // Gets match information for all upcoming matches and converts time.
    $boxes = $(".matchmain:has(.whenm:contains('hour'):contains('from now'),.whenm:contains('minute'):contains('from now'))");
    
    $boxes.each(function(i) {
        console.log("2");
        var $this = $(this),
            link = $this.find("a[href*='match']").attr("href"),
            $whenBox =  $this.find(".whenm:first");
        
  		console.log($this);
        
        $.get(link, function(data) {
            var response = $('<html />').html(data),
                $box = response.find('.gradient').first(),
                $timeBox = $box.find('.half:eq(2)'),
                timeInCEST = $timeBox.text(),
                hour = timeInCEST.split(" ")[0].split(":")[0] - tzOffset,
                minute = timeInCEST.split(" ")[0].split(":")[1];
            
            if (hour < 0) hour = 24 + hour;  
            
            if (hour == 12) {
                AMorPM = "PM";
            } else if (hour > 12) {
                hour = hour - 12;
                AMorPM = "PM";      
            } else {
                AMorPM = "AM";
            }
            
            $whenBox.html($whenBox.html() + " (" + hour + ":" + minute + " " + AMorPM + ")");
        });
        
    });
});