CSGL TimeZone Changer

Change CSGO timezones.

当前为 2014-09-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        CSGL TimeZone Changer
// @version     1.2
// @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==

$(function () {
  var $box = $('.gradient').first(),
      $timeBox = $box.find('.half:eq(2)'),
   	  dt = new Date(),
      theHour = dt.getHours(),
      theMinutes = dt.getMinutes(),
      tzOffset = (dt.getTimezoneOffset()/60) + 2,
      hour = parseInt(hour) - tzOffset,
      AMorPM = "";

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

  // Shows times on front page.
  $boxes = $( ".whenm:contains('hour'):contains('from now'),.whenm:contains('minute'):contains('from now')" ); 
    
  if ($boxes.length) {
    $boxes.each(function(i) {
      ($(this).text().indexOf("hour") > 0) ? multiplier = 60 : multiplier = 1;
      (window.location.href.indexOf("mybets") > 0) ? hourText = $(this).text() : hourText = $(this).text().substring(1);
        
      var offset = parseInt(hourText),
          gameTime = new Date(dt.getTime() + (offset*60000*multiplier)),
          gameHour = gameTime.getHours(),
          gameMinute = gameTime.getMinutes();
        
        console.log(offset);
        
      if ($(this).text().indexOf("hour") > 0) {
        if (theMinutes > 30) gameHour = gameHour + 1;
        gameMinute = "00";
      } else {
        (gameMinute === 0) ? gameMinute = "00" : gameMinute = gameMinute;
      }
        
      (gameHour >= 12) ? AMorPM = "PM" : AMorPM = "AM";
      if (gameHour > 12) gameHour = gameHour - 12;   
         
      thisHTML = $(this).html();
      $(this).html(thisHTML + " (" + gameHour + ":" + gameMinute + " " + AMorPM + ")");
    });
  }
  
});