Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function replaceAllTimestamps() {
	if (location.href.includes("/Talk") || location.href.includes("/Wikipedia") ||
		location.href.includes("/User_talk") || location.href.includes("/Wikipedia_talk") ||
		location.href.includes("/Template") || location.href.includes("/Template_talk")) {
		let list = Array.prototype.slice.call(document.querySelectorAll("span[data-mw-comment-end]"));

		for (let elem of list) {
			try {
				if (typeof elem.previousSibling.tagName === "undefined") {
					continue;
				}
				let value = elem.previousSibling.previousSibling.nodeValue;
				if (value === null) {
					continue;
				}
				elem.previousSibling.previousSibling.remove();
				let newElem = document.createElement("span");
	
				newElem.innerHTML = value.replaceAll(/(\d\d\:\d\d,? \d\d? \w+ \d{4}) \(UTC\)/g, function(match, p1) {
					let time = new Date(p1.replace(",", "") + " utc").getTime();
					let diff = Math.floor((new Date().getTime() - time) / 60000);
					let title = " minutes ago";
			
					if (diff >= 60) {
						diff = Math.floor(diff / 60);
						title = " hours ago";
	
						if (diff >= 48) {
							diff = Math.floor(diff / 24);
							title = " days ago";
	
							if (diff >= 365 * 3) {
								diff = Math.floor(diff / 365);
								title = " years ago";
							}
						}
					}
	
					if (diff === 1) {
						title = title.replace("s ", " ");
					}
			
					return `<span title="${match}">${diff + title}</span>`;
				});
				elem.parentNode.insertBefore(newElem, elem.previousSibling);
			} catch (e) {}
		}
	}
	console.log("Added timestamps");
}

if (document.readyState === "complete") {
	replaceAllTimestamps();
} else {
	window.addEventListener("load", replaceAllTimestamps);
}