TopCoder TimeZone UserScript

convert the timezone used in TopCoder from EST/EDT to your local time

  1. // ==UserScript==
  2. // @name TopCoder TimeZone UserScript
  3. // @namespace https://github.com/kmyk
  4. // @version 1.2
  5. // @description convert the timezone used in TopCoder from EST/EDT to your local time
  6. // @author Kimiyuki Onaka
  7. // @match *://apps.topcoder.com/forums/
  8. // @match *://apps.topcoder.com/forums/?*module=Category*
  9. // @match *://apps.topcoder.com/forums/?*module=History*
  10. // @match *://apps.topcoder.com/forums/?*module=Thread*
  11. // @match *://apps.topcoder.com/forums/?*module=ThreadList*
  12. // @match *://apps.topcoder.com/*
  13. // @match *://community.topcoder.com/longcontest/?*module=ViewStandings*
  14. // @match *://community.topcoder.com/longcontest/?*module=ViewSubmissionHistory*
  15. // @match *://community.topcoder.com/longcontest/?*module=ViewExampleHistory*
  16. // @match *://community.topcoder.com/tc?*module=MatchDetails*
  17. // @match *://community.topcoder.com/*
  18. // @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment-with-locales.min.js
  19. // @require https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.16/moment-timezone-with-data-2012-2022.min.js
  20. // ==/UserScript==
  21. function convert(text, html) {
  22. const zone = "America/Indiana/Indianapolis";
  23. let t = undefined;
  24. const match = text.match(/^\s*(?:\w+,? )?(\w+ \d+,? 20\d\d at \d+:\d\d [AP]M) (E[SD]T)\s*$/);
  25. if (match) {
  26. // example: "Wed, Apr 25, 2018 at 9:04 PM EDT" (https://apps.topcoder.com/forums/?module=Thread&threadID=916943&start=0)
  27. // example: "Thu, Jun 29 2017 at 12:42 AM EDT" (https://apps.topcoder.com/forums/)
  28. // example: "Apr 27, 2018 at 12:26 AM EDT" (https://apps.topcoder.com/forums/?module=History)
  29. const format = "MMM DD YYYY hh:mm A";
  30. t = moment.tz(match[1], format, zone); // I want to use `match[2]` instead of `zone`, but moment-timezone say "Moment Timezone has no data for EDT". EST is accpeted.
  31. }
  32. else if (/^\s*\d\d.\d\d.20\d\d \d\d+:\d\d:\d\d\s*$/.test(text)) {
  33. // example: "04.22.2018 09:42:47" (https://community.topcoder.com/longcontest/?module=ViewStandings&rd=17143)
  34. // example: "04.25.2018 14:33:17" (https://community.topcoder.com/longcontest/?module=ViewSubmissionHistory&rd=17143&pm=14889&cr=40099108)
  35. const format = "MM.DD.YYYY HH:mm:ss";
  36. t = moment.tz(text, format, zone);
  37. }
  38. else if (/^\s*\d\d.\d\d.20\d\d\s*\d\d:\d\d E[SD]T\s*$/.test(text)) {
  39. // "<strong>04.25.2018</strong><br>21:00 EDT" (https://community.topcoder.com/tc?module=MatchDetails&rd=17143)
  40. const format = "MM.DD.YYYYHH:mm"; // NOTE: don't add space. it fails if "...YYYY HH..."
  41. t = moment.tz(text, format, zone);
  42. }
  43. else {
  44. return "";
  45. }
  46. return html + " <small>(" + t.local().format() + ")</small>";
  47. }
  48. function main() {
  49. const tags = Array.prototype.slice.call(document.getElementsByTagName("*"));
  50. tags.reverse(); // to visit leaves at first
  51. for (const tag of tags) {
  52. const converted = convert(tag.textContent, tag.innerHTML);
  53. if (converted) {
  54. tag.innerHTML = converted;
  55. }
  56. }
  57. }
  58. main();