12h to 24h time

Convert time from 12-hour format into 24-hour format

  1. // ==UserScript==
  2. // @name 12h to 24h time
  3. // @namespace http://twitter.com/
  4. // @version 0.2.0
  5. // @description Convert time from 12-hour format into 24-hour format
  6. // @author Bogudan
  7. // @match https://twitter.com/*
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14. function update (xpath, regex, match) {
  15. const ee = document.evaluate (xpath, document, null, 0, null);
  16. const aa = [];
  17. for (;;) {
  18. const e = ee.iterateNext ();
  19. if (!e)
  20. break;
  21. aa.push (e);
  22. }
  23. for (const e of aa)
  24. e.nodeValue = e.nodeValue.replace (regex, function (m, ph, pm, pt) {
  25. ph = parseInt (ph) % 12;
  26. if (pt === match)
  27. ph += 12;
  28. return ('0' + ph).slice (-2) + pm;
  29. });
  30. }
  31. setInterval (function () {
  32. update ('//text()[contains(.,":")][contains(.," AM") or contains(.," PM")]', /(\d{1,2})(:\d\d) ([AP]M)/g, 'PM'); // english
  33. update ('//text()[contains(.,":")][contains(.," am") or contains(.," pm")]', /(\d{1,2})(:\d\d) ([ap]m)/g, 'pm'); // british english
  34. update ('//text()[contains(.,":")][contains(.," a. m.") or contains(.," p. m.")]', /(\d{1,2})(:\d\d) ([ap]\. m\.)/g, 'p. m.'); // spanish
  35. }, 1000);
  36. }) ();