Skip to content

Instantly share code, notes, and snippets.

@seanf
Created January 20, 2019 05:25
Show Gist options
  • Save seanf/1179f9648428bf8b4097338b0ab13dd3 to your computer and use it in GitHub Desktop.
Save seanf/1179f9648428bf8b4097338b0ab13dd3 to your computer and use it in GitHub Desktop.
GitLab real time user script
// ==UserScript==
// @name GitLab real time
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Replace GitLab's relative times (from timeago.js) with real timestamps
// @author Sean Flanigan
// @match https://gitlab.com/*
// ==/UserScript==
(function() {
'use strict';
// Select the node that will be observed for mutations
var targetNode = document.getElementById('content-body');
function fixTime(elem) {
var absTime = elem.getAttribute('data-original-title');
var relTime = elem.innerText;
elem.innerText = absTime;
elem.setAttribute('data-original-title', relTime);
elem.setAttribute('sf-time', 'swapped');
}
var selector = 'time[data-original-title]:not([sf-time])';
targetNode.querySelectorAll(selector).forEach(fixTime);
// Options for the observer (which mutations to observe)
var config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
var callback = function(mutationsList, observer) {
for (var mutation of mutationsList) {
if (mutation.type == 'childList') {
mutation.target.querySelectorAll(selector).forEach(fixTime);
}
}
};
// Create an observer instance linked to the callback function
var observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment