Created
July 30, 2011 01:24
-
-
Save suvene/1115074 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== | |
// @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: |
Author
suvene
commented
Jul 30, 2011
- Google+ の時間表示を YYYY/MM/DD hh:mm(曜日) みたくする
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment