Created
January 20, 2019 05:25
-
-
Save seanf/1179f9648428bf8b4097338b0ab13dd3 to your computer and use it in GitHub Desktop.
GitLab real time user script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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