Skip to content

Instantly share code, notes, and snippets.

@suvene
Created July 30, 2011 01:24
Show Gist options
  • Save suvene/1115074 to your computer and use it in GitHub Desktop.
Save suvene/1115074 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name G+ FormatDate
// @author suVene
// @version 0.1.0
// @namespace https://gist.github.com/raw/1115074/3a9327ed58907df0db1b755361875fedac87e682/G+.FormatDate.user.js
// @description formate date for post date
// @include https://plus.google.com/*
// @match https://plus.google.com/*
// ==/UserScript==
(function() {
// User Options start//{{{
// User Options end//}}}
// utilities start//{{{
function hasClass(elem, clazz) {
if (/ /.test(clazz)) {
if (elem.className == clazz) return true;
} else {
if (elem.className) {
if (elem.className == clazz) return true;
var zz = elem.className.split(/\s+/g);
for (var m = 0; m < zz.length; m++) {
if (zz[m] == clazz) return true;
}
}
}
return false;
}
function getElementsByTagAndClassName(tag, clazz, node) {
var retval = [];
var elems = (node || document).getElementsByTagName(tag);
for (var i = 0, I = elems.length; i < I; ++i) {
var e = elems[i];
if (hasClass(e, clazz)) {
retval.push(e);
}
}
return retval;
}
// utilities functinos start//}}}
// private functions start//{{{
// private functions end//}}}
// events start//{{{
function install() {
var elems = getElementsByTagAndClassName('a', 'a-Ja-h a-b-h-Jb a-f-i-Ad');
elems = elems.concat(getElementsByTagAndClassName('span', 'a-f-i-Ad'));
for (var n = 0; n < elems.length; n++) {
var elem = elems[n];
if (hasClass('setymd')) continue;
var t = elem.title;
var m = t.match('([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})(\n.*\(.*?: ([0-9]{4})/([0-9]{2})/([0-9]{2}) ([0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})\))?');
if (m) {
var d = new Date(m[1] + '/' + (m[2]) + '/' + m[3] + ' ' + m[4])
elem.innerHTML =
d.getFullYear() + '/' + (d.getMonth()+1) + '/' + d.getDate() + '(' + WEEKS[d.getDay()] + ') '
+ (d.getHours()<10?'0':'') + d.getHours() + ':' + (d.getMinutes()<10?'0':'') + d.getMinutes();
if (m[5]) {
d = new Date(m[7] + '/' + (m[8]) + '/' + m[9] + ' ' + m[10])
elem.innerHTML +=
' (編集: '
+ d.getFullYear() + '/' + (d.getMonth()+1) + '/' + d.getDate() + '(' + WEEKS[d.getDay()] + ') '
+ (d.getHours()<10?'0':'') + d.getHours() + ':' + (d.getMinutes()<10?'0':'') + d.getMinutes()
+ ')';
}
elem.className += ' setymd';
}
}
}
// events end//}}}
const WEEKS = ['日', '月', '火', '水', '木', '金', '土'];
window.setInterval(install, 1000);
})()
// vim: set fdm=marker sw=2 ts=2 sts=0 et:
@suvene
Copy link
Author

suvene commented Aug 2, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment