-
-
Save syoichi/1118072 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 G+ FormatDate | |
// @name G+ FormatDate | |
// @namespace https://raw.github.com/gist/1115074/G+.FormatDate.user.js | |
// @author suVene | |
// @version 0.2.1.20110805182249 | |
// @description formate date for post date | |
// @include https://plus.google.com/* | |
// @run-at document-end | |
// @priority 0 | |
// @compatibility Firefox 5.0(Scriptish 0.1.3), Chrome 13.0.782.107, Safari 5.1(NinjaKit 0.8) on Windows 7 Enterprise 32bit | |
// @charset UTF-8 | |
// @note Opera 11.50だと何故かGoogle+上でUser Scriptを実行することができない? | |
// ==/UserScript== | |
/* jslint browser: true, maxerr: 50, maxlen: 80, indent: 4 */ | |
// Edition 2011-08-03 | |
(function (doc) { | |
'use strict'; | |
var postLinkList = doc.querySelectorAll( | |
'span > [title]:not([role]):not([id])' | |
), | |
postLinkListLen, | |
contentPane, | |
dayWeek, | |
normalizeRegExp, | |
dayWeekRegExp, | |
timeReplace; | |
if (!postLinkList) { | |
return; | |
} | |
postLinkListLen = postLinkList.length; | |
contentPane = doc.getElementById('contentPane'); | |
dayWeek = ['日', '月', '火', '水', '木', '金', '土']; | |
normalizeRegExp = /(|)|編集:/g; | |
dayWeekRegExp = /\d(?=\s)/g; | |
timeReplace = function timeReplace(postLink) { | |
var postTimeList = postLink.title.replace( | |
normalizeRegExp, | |
'' | |
).split('\n '), | |
postTimeListlen = postTimeList.length, | |
postTime; | |
if (postTimeListlen > 1) { | |
while (postTimeListlen) { | |
postTime = postTimeList[postTimeListlen -= 1]; | |
postTimeList[postTimeListlen] = postTime.replace( | |
dayWeekRegExp, | |
'$&(' + dayWeek[(new Date(postTime)).getDay()] + ')' | |
); | |
} | |
postLink.textContent = | |
postTimeList[0] + ' (編集: ' + postTimeList[1] + ')'; | |
} else { | |
postTime = String(postTimeList); | |
postLink.textContent = postTime.replace( | |
dayWeekRegExp, | |
'$&(' + dayWeek[(new Date(postTime)).getDay()] + ')' | |
); | |
} | |
}; | |
while (postLinkListLen) { | |
timeReplace(postLinkList[postLinkListLen -= 1]); | |
} | |
if (contentPane) { | |
contentPane.addEventListener('DOMNodeInserted', function (event) { | |
var target = event.target; | |
if ( | |
target && | |
target.title && | |
!target.id && | |
target.parentNode.tagName === 'SPAN' | |
) { | |
timeReplace(target); | |
} | |
}, false); | |
} | |
}(document)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment