Last active
November 8, 2024 03:31
-
-
Save hirataya/5442881 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
// -*- coding: utf-8 -*- | |
// ==UserScript== | |
// @name They are all 17 years old | |
// @author HIRATA Yasuyuki <[email protected]> | |
// @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