12h to 24h time

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         12h to 24h time
// @namespace    http://twitter.com/
// @version      0.2.0
// @description  Convert time from 12-hour format into 24-hour format
// @author       Bogudan
// @match        https://twitter.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';
	function update (xpath, regex, match) {
		const ee = document.evaluate (xpath, document, null, 0, null);
		const aa = [];
		for (;;) {
			const e = ee.iterateNext ();
			if (!e)
				break;
			aa.push (e);
			}
		for (const e of aa)
			e.nodeValue = e.nodeValue.replace (regex, function (m, ph, pm, pt) {
				ph = parseInt (ph) % 12;
				if (pt === match)
					ph += 12;
				return ('0' + ph).slice (-2) + pm;
				});
		}
	setInterval (function () {
		update ('//text()[contains(.,":")][contains(.," AM") or contains(.," PM")]', /(\d{1,2})(:\d\d) ([AP]M)/g, 'PM');	// english
		update ('//text()[contains(.,":")][contains(.," am") or contains(.," pm")]', /(\d{1,2})(:\d\d) ([ap]m)/g, 'pm');	// british english
		update ('//text()[contains(.,":")][contains(.," a. m.") or contains(.," p. m.")]', /(\d{1,2})(:\d\d) ([ap]\. m\.)/g, 'p. m.');	// spanish
		}, 1000);
	}) ();