Skip to content

Instantly share code, notes, and snippets.

@azu
Last active August 29, 2015 14:01
Show Gist options
  • Save azu/aee6f04ea346dc883e63 to your computer and use it in GitHub Desktop.
Save azu/aee6f04ea346dc883e63 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @id github.com-ff599db1-47d8-b14f-83b4-3e345f6d67e3@http://efcl.info/
// @name Github:time-format-changer
// @version 1.0
// @namespace http://efcl.info/
// @author azu
// @description
// @include https://github.com/*
// @run-at document-end
// @grant none
// ==/UserScript==
var $ = unsafeWindow.$;
var titleFormat = "%Y-%m-%d %H:%M";
var toArray = Function.prototype.call.bind(Array.prototype.slice);
var relative = /ago/i;
function _update(body){
var times = body.getElementsByTagName("time");
toArray(times).forEach(function(timeElement){
if(!relative.test(timeElement.textContent)){
timeElement.setAttribute("is","");
timeElement.setAttribute("title-format",titleFormat);
var title = timeElement.getAttribute("title").split(":");
title.pop();
timeElement.textContent = title.join(":");
}
});
}
function update(body){
requestAnimationFrame(function(){ _update(body); });
}
$(document).on('pjax:end', function pjaxEnd() {
update(document.body);
});
var addFilterHandler = function(evt){
var node = evt.target;
update(node);
}
document.body.addEventListener('AutoPagerize_DOMNodeInserted', addFilterHandler, false);
// MAIN =
update(document.body);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment