Created
June 7, 2010 07:40
-
-
Save mattn/428343 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 hatena service link | |
// @namespace http://mattn.kaoriya.net/ | |
// @description hatena service link | |
// @include http://*.hatena.ne.jp/* | |
// ==/UserScript== | |
(function() { | |
// http://gist.github.com/raw/3238/dollarX.js | |
// extend version of $X | |
// $X(exp); | |
// $X(exp, context); | |
// $X(exp, type); | |
// $X(exp, context, type); | |
function $X (exp, context, type /* want type */) { | |
if (typeof context == "function") { | |
type = context; | |
context = null; | |
} | |
if (!context) context = document; | |
exp = (context.ownerDocument || context).createExpression(exp, function (prefix) { | |
var o = document.createNSResolver(context)(prefix); | |
if (o) return o; | |
return (document.contentType == "application/xhtml+xml") ? "http://www.w3.org/1999/xhtml" : ""; | |
}); | |
switch (type) { | |
case String: return exp.evaluate(context, XPathResult.STRING_TYPE, null).stringValue; | |
case Number: return exp.evaluate(context, XPathResult.NUMBER_TYPE, null).numberValue; | |
case Boolean: return exp.evaluate(context, XPathResult.BOOLEAN_TYPE, null).booleanValue; | |
case Array: | |
var result = exp.evaluate(context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (var ret = [], i = 0, len = result.snapshotLength; i < len; i++) { | |
ret.push(result.snapshotItem(i)); | |
} | |
return ret; | |
case undefined: | |
var result = exp.evaluate(context, XPathResult.ANY_TYPE, null); | |
switch (result.resultType) { | |
case XPathResult.STRING_TYPE : return result.stringValue; | |
case XPathResult.NUMBER_TYPE : return result.numberValue; | |
case XPathResult.BOOLEAN_TYPE: return result.booleanValue; | |
case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: | |
// not ensure the order. | |
var ret = [], i = null; | |
while ((i = result.iterateNext())) ret.push(i); | |
return ret; | |
} | |
return null; | |
default: throw(TypeError("$X: specified type is not valid type.")); | |
} | |
} | |
const services = [{ letter: 'a', title: 'アンテナ' }, { letter: 'b', title: 'ブックマーク' }, { letter: 'c', title: 'ココ' }, { letter: 'd', title: 'ダイアリー' }, { letter: 'f', title: 'フォトライフ' }, { letter: 'g', title: 'グループ' }, { letter: 'i', title: 'アイデア' }, { letter: 'm', title: 'メッセージ' }, { letter: 'q', title: '人力検索' }, { letter: 's', title: 'スター' }] | |
var letter = location.host.replace(/\.hatena\.ne\.jp/, ''); | |
for (var n = 0; n < services.length; n++) { | |
if (services[n].letter == letter) { | |
if (n == services.length) n == 0; | |
else n++; | |
var a = document.createElement('a'); | |
a.href = location.href.replace(/^https?:\/\/(?:[^\.]+)(\.hatena\.ne\.jp\/)([^\/]+).*/, 'http://' + services[n].letter + '$1$2'); | |
var img = document.createElement('img'); | |
img.src = '/images/tri_de.gif'; | |
img.title = services[n].title; | |
img.border = '0px'; | |
img.style.marginTop = '0px !important'; | |
a.appendChild(img); | |
var node = $X('//a[@href="/" or @href="http://' + location.host + '/"]')[0]; | |
if (node) node.parentNode.insertBefore(a, node.nextSibling); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment