CSGL TimeZone Changer

Change CSGO timezones.

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

  1. // ==UserScript==
  2. // @name CSGL TimeZone Changer
  3. // @version 1.1
  4. // @description Change CSGO timezones.
  5. // @match http://csgolounge.com/*
  6. // @match http://dota2lounge.com/*
  7. // @require http://code.jquery.com/jquery-2.1.1.js
  8. // @copyright Josh Hubbard
  9. // @namespace https://greasyfork.org/users/5596
  10. // ==/UserScript==
  11.  
  12. $(function () {
  13. var $box = $('.gradient').first(),
  14. $timeBox = $box.find('.half:eq(2)'),
  15. dt = new Date(),
  16. theHour = dt.getHours(),
  17. theMinutes = dt.getMinutes(),
  18. tzOffset = (dt.getTimezoneOffset()/60) + 2,
  19. hour = parseInt(hour) - tzOffset,
  20. AMorPM = "";
  21.  
  22. // Converts CEST to local on match page.
  23. if ($timeBox.length) {
  24. var timeInCEST = $timeBox.text(),
  25. hour = timeInCEST.split(" ")[0].split(":")[0],
  26. minute = timeInCEST.split(" ")[0].split(":")[1];
  27. hour = hour - tzOffset;
  28. if (hour < 0) hour = 24 + hour;
  29. if (hour == 12) {
  30. AMorPM = "PM";
  31. } else if (hour > 12) {
  32. hour = hour - 12;
  33. AMorPM = "PM";
  34. } else {
  35. AMorPM = "AM";
  36. }
  37. $timeBox.html("(" + hour + ":" + minute + " " + AMorPM + ") " + $timeBox.html());
  38. }
  39.  
  40. // Shows times on front page.
  41. $boxes = $( ".whenm:contains('hour'):contains('from now'),.whenm:contains('minute'):contains('from now')" );
  42. if ($boxes.length) {
  43. $boxes.each(function(i) {
  44. ($(this).text().indexOf("hour") > 0) ? multiplier = 60 : multiplier = 1;
  45. var offset = parseInt(parseInt($(this).text().substring(1))),
  46. gameTime = new Date(dt.getTime() + (offset*60000*multiplier)),
  47. gameHour = gameTime.getHours(),
  48. gameMinute = gameTime.getMinutes();
  49. if ($(this).text().indexOf("hour") > 0) {
  50. if (theMinutes > 30) gameHour = gameHour + 1;
  51. gameMinute = "00";
  52. } else {
  53. (gameMinute === 0) ? gameMinute = "00" : gameMinute = gameMinute;
  54. }
  55. (gameHour >= 12) ? AMorPM = "PM" : AMorPM = "AM";
  56. if (gameHour > 12) gameHour = gameHour - 12;
  57. thisHTML = $(this).html();
  58. $(this).html(thisHTML + " (" + gameHour + ":" + gameMinute + " " + AMorPM + ")");
  59. });
  60. }
  61. });