Last active
August 29, 2015 14:01
-
-
Save azu/aee6f04ea346dc883e63 to your computer and use it in GitHub Desktop.
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== | |
// @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