Created
July 12, 2010 10:43
-
-
Save satoruk/472351 to your computer and use it in GitHub Desktop.
MMORPGのIMO for iPhone のまとめwiki の自動で検索リンクを作るbookmarklet.
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
javascript:%28function%28%29%7bvar%20d%3dfunction%28k%2cj%29%7bvar%20b%3dk%2echildNodes%2elength%3bfor%28var%20g%3db%2d1%3bg%3e%3d0%3bg%2d%2d%29%7bvar%20h%3dk%2echildNodes%5bg%5d%2cf%3dh%2enodeType%2cl%3dh%2enodeName%3bif%28f%3d%3d3%29%7bj%28h%29%7delse%7bif%28f%3d%3d1%29%7bif%28%21%28l%3d%3d%22A%22%7c%7cl%3d%3d%22IMG%22%7c%7cl%3d%3d%22INPUT%22%29%29%7bd%28h%2cj%29%7d%7d%7d%7d%7d%3bvar%20c%3dwindow%2elocation%2ce%3dc%2ehref%2esubstring%280%2cc%2ehref%2elength%2dc%2esearch%2elength%29%3be%2b%3d%22%3fencode_hint%3d%e3%81%b7%26cmd%3dsearch%26type%3dAND%26word%3d%22%3bvar%20a%3ddocument%2egetElementById%28%22body%22%29%3bd%28a%2cfunction%28f%29%7bif%28f%2enodeValue%2esearch%28%2f%5cS%2b%2fi%29%3d%3d%2d1%29%7breturn%7dvar%20b%3ddocument%2ecreateElement%28%22span%22%29%3bb%2einnerHTML%3df%2enodeValue%2ereplace%28%2f%28%5b%5e%5cs%ef%bd%a4%e3%80%81%2c%e3%80%9c%c3%97%5c%28%5c%29%5d%7b2%2c%7d%28%20%5b%5e%5cs%ef%bd%a4%e3%80%81%2c%e3%80%9c%c3%97%5c%28%5c%29%5d%7b2%2c%7d%29%2a%29%2fg%2cfunction%28h%2cg%29%7bif%28g%2esearch%28%2f%5e%5ba%2dz%5d%2b%28%20%5ba%2dz%5d%2b%29%2a%24%2fi%29%3d%3d%2d1%26%26g%2elength%3e11%29%7breturn%20g%7delse%7bif%28g%2esearch%28%2f%5e%5b%5cd%5d%2bG%3f%24%2fi%29%21%3d%2d1%29%7breturn%20g%7delse%7breturn%28%27%3ca%20href%3d%22%27%2be%2bg%2b%27%22%3e%27%2bg%2b%22%3c%2fa%3e%22%29%7d%7d%7d%29%3bf%2eparentNode%2ereplaceChild%28b%2cf%29%7d%29%7d%29%28%29%3b |
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
// http://wikiwiki.jp/iphone_imo/ の自動検索リンク for safari | |
// bookmarkletに変換する場合はこのまま、YUI Compressor(http://refresh-sf.com/yui/)等で圧縮して | |
// URLエンコーディングをUTF8(http://www.tagindex.com/tool/url.html)で変換して使ってください. | |
// javascript: | |
(function(){ | |
var recursiveSearch = function(elem, func){ | |
var len = elem.childNodes.length; | |
for(var i=len-1; i>=0 ;i-- ){ | |
var node = elem.childNodes[i], nodeType = node.nodeType, nodeName = node.nodeName; | |
if(nodeType == 3){// text node | |
func(node); | |
}else if(nodeType == 1){// element node | |
if(!( | |
nodeName == 'A' || | |
nodeName == 'IMG' || | |
nodeName == 'INPUT' | |
)){ | |
recursiveSearch(node, func); | |
} | |
} | |
} | |
} | |
var location = window.location, base = location.href.substring(0, location.href.length-location.search.length); | |
base += '?encode_hint=ぷ&cmd=search&type=AND&word='; | |
var b = document.getElementById('body'); | |
recursiveSearch(b,function(node){ | |
if(node.nodeValue.search(/\S+/i) == -1){ return; } | |
var elem = document.createElement('span'); | |
elem.innerHTML = node.nodeValue.replace(/([^\s、、,~×\(\)]{2,}( [^\s、、,~×\(\)]{2,})*)/g, | |
function(str, p1) { | |
if(p1.search(/^[a-z]+( [a-z]+)*$/i) == -1 && p1.length>11){ | |
return p1; | |
}else if(p1.search(/^[\d]+G?$/i) != -1){ | |
return p1; | |
}else{ | |
return('<a href="'+base+p1+'">'+p1+'</a>'); | |
} | |
}); | |
node.parentNode.replaceChild(elem, node); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment