Created
January 12, 2013 03:54
-
-
Save taizooo/4515968 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Hatena Diary: append datetime to ins/del | |
// @namespace http://lowreal.net | |
// @include http://d.hatena.ne.jp/* | |
// @include http://*.g.hatena.ne.jp/* | |
// @include https://*.g.hatena.ne.jp/* | |
// ==/UserScript== | |
// cf. http://coderepos.org/share/browser/lang/javascript/userscripts/hatena.diary.appendinsdeldatetime.user.js? | |
// cf. http://subtech.g.hatena.ne.jp/cho45/20080409/1207672776 | |
location.href = "javascript:(" + ( | |
function () { | |
if (!(Hatena && Hatena.Diary && Hatena.Diary.Section)) return; | |
var orig_update = Hatena.Diary.Section.prototype.update; | |
Hatena.Diary.Section.prototype.update = function (data, obj, meth) { | |
if (data.body) { | |
data.body = data.body.replace(/<(ins|del)>/g, function (_, n) { | |
return '<' + n + ' datetime="' + w3cdtf(new Date) + '">'; | |
}); | |
} | |
orig_update.apply(this, arguments); | |
}; | |
function w3cdtf(d) { | |
var date = [ | |
String(10000 + d.getFullYear()).slice(1), | |
String(100 + d.getMonth() + 1).slice(1), | |
String(100 + d.getDate()).slice(1)].join("-"); | |
var time = [ | |
String(100 + d.getHours()).slice(1), | |
String(100 + d.getMinutes()).slice(1), | |
String(100 + d.getSeconds()).slice(1)].join(":"); | |
var offset = d.getTimezoneOffset(); | |
var plsmns = (offset < 0) ? "+" : "-", | |
offset = Math.abs(offset); | |
var zone = plsmns + String(100 + offset / 60).slice(1) + ":" + String(100 + offset % 60).slice(1); | |
return date + "T" + time + zone; | |
} | |
} | |
).toString() + ")()"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment