Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// -*- coding: utf-8 -*-
// ==UserScript==
// @name They are all 17 years old
// @author HIRATA Yasuyuki <yasu@asuka.net>
// @namespace http://yasu.asuka.net/
// @version 1.1.0
// @include http://www.google.tld/search?*
// @include https://www.google.tld/search?*
// @released 2013-04-23
// @updated 2013-04-30
// ==/UserScript==
(function(){
var members = {
"井上喜久子": 17,
"田村ゆかり": 17,
"野川さくら": 17,
"佐藤利奈": 17,
"堀江由衣": 17,
"石田燿子": 17,
"松澤由美": 17,
"こやまきみこ": 17,
"池澤春菜": 17,
"田中敦子": 17,
"たかはし智秋": 23
};
var subjectNodes =
document.evaluate(
'//div[contains(concat(" ", normalize-space(@class), " "), " answer_subject ")]',
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
).snapshotItem(0);
var predicateNodes =
document.evaluate(
'//div[contains(concat(" ", normalize-space(@class), " "), " answer_predicate ")]',
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
).snapshotItem(0);
if(subjectNodes && predicateNodes) {
var subjectNode = subjectNodes.childNodes[0];
var predicateNode = predicateNodes.childNodes[0];
if(subjectNode.nodeValue.match(/(.*)\s*,\s*年齢/)) {
var age = members[RegExp.$1];
if(age && predicateNode.nodeValue.match(/(\d+)年(\d+)月(\d+)日/)) {
var baseBirthday =
new Date(
Number(RegExp.$1) + age,
Number(RegExp.$2) - 1,
Number(RegExp.$3)
);
var today = Date.now();
var days = Math.floor((today - baseBirthday)/(60*60*24*1000));
predicateNode.nodeValue =
predicateNode.nodeValue.replace(/^\d+/, age + "歳と" + days + "");
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.