CSGL TimeZone Changer

Change CSGO timezones.

  1. // ==UserScript==
  2. // @name CSGL TimeZone Changer
  3. // @version 1.6
  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. // @require http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js
  9. // @copyright Josh Hubbard
  10. // @namespace https://greasyfork.org/users/5596
  11. // ==/UserScript==
  12.  
  13. // TODO: Dry up the code. Things need to be speeded up.
  14.  
  15. $(function () {
  16. var dt = new Date(),
  17. tzOffset = (dt.getTimezoneOffset()/60) + 1,
  18. AMorPM = "",
  19. hour12 = true;
  20. if ($.cookie("showTwelve") == undefined) {
  21. $.cookie("showTwelve", true);
  22. } else {
  23. if ($.cookie("showTwelve") == 'true') {
  24. hour12 = true;
  25. } else {
  26. hour12 = false;
  27. }
  28. }
  29.  
  30. // Insert 12/24 hours box
  31. if (hour12) {
  32. $('#submenu > nav').append('<a id="hour-option">Switch to 24 Hours</a>');
  33. } else {
  34. $('#submenu > nav').append('<a id="hour-option">Switch to 12 Hours</a>');
  35. }
  36. $('#hour-option').click(function() {
  37. if (hour12) {
  38. $.cookie("showTwelve", false);
  39. } else {
  40. $.cookie("showTwelve", true);
  41. }
  42. location.reload();
  43. });
  44. $timeBox = $('.half:contains("CET")');
  45. // Converts CEST to local on match page.
  46. if ($timeBox.length) {
  47. var timeInCEST = $timeBox.text(),
  48. hour = timeInCEST.split(" ")[0].split(":")[0],
  49. minute = timeInCEST.split(" ")[0].split(":")[1];
  50. hour = hour - tzOffset;
  51. if (hour < 0) hour = 24 + hour;
  52. if (hour12) {
  53. console.log('2');
  54. if (hour == 12) {
  55. AMorPM = "PM";
  56. } else if (hour > 12) {
  57. hour = hour - 12;
  58. AMorPM = "PM";
  59. } else {
  60. AMorPM = "AM";
  61. }
  62. }
  63. if (hour12) {
  64. $timeBox.html("(" + hour + ":" + minute + " " + AMorPM + ") " + $timeBox.html());
  65. } else {
  66. $timeBox.html("(" + hour + ":" + minute + ") " + $timeBox.html());
  67. }
  68. }
  69. // Gets match information for all upcoming matches and converts time.
  70. $boxes = $(".matchmain:has(.whenm:contains('hour'):contains('from now'),.whenm:contains('minute'):contains('from now'))");
  71. $boxes.each(function(i) {
  72. var $this = $(this),
  73. link = $this.find("a[href*='match']").attr("href"),
  74. $whenBox = $this.find(".whenm:first");
  75. $.get(link, function(data) {
  76. var response = $('<html />').html(data),
  77. $timeBox = response.find('.half:contains("CET")'),
  78. timeInCEST = $timeBox.text(),
  79. hour = timeInCEST.split(" ")[0].split(":")[0] - tzOffset,
  80. minute = timeInCEST.split(" ")[0].split(":")[1];
  81. if (hour < 0) hour = 24 + hour;
  82. if (hour12) {
  83. if (hour == 12) {
  84. AMorPM = "PM";
  85. } else if (hour > 12) {
  86. hour = hour - 12;
  87. AMorPM = "PM";
  88. } else {
  89. AMorPM = "AM";
  90. }
  91. }
  92. if (hour12) {
  93. $whenBox.html($whenBox.html() + " (" + hour + ":" + minute + " " + AMorPM + ")");
  94. } else {
  95. $whenBox.html($whenBox.html() + " (" + hour + ":" + minute + ")");
  96. }
  97. });
  98. });
  99. });