Created
April 7, 2009 12:39
-
-
Save Griever/91215 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 keyconfig for Chrome | |
// @namespace http://d.hatena.ne.jp/Griever/ | |
// @description keyconfig for google chrome | |
// @author Griever | |
// @version 1.0 | |
// ==/UserScript== | |
var func = { | |
goToParent: function(){ | |
var uri = top.location.href; | |
var path = uri.replace(/^.*?\w(?:\/)/,'/'); | |
if (path == "/") | |
return; | |
var prePath = uri.substr(0, uri.length - path.length); | |
var pathList = path.split("/"); | |
if (!pathList.pop()) | |
pathList.pop(); | |
top.location.href = prePath + pathList.join("/") + "/"; | |
}, | |
fastForward : function(){ | |
var previousDomains = ['d.hatena.ne.jp']; | |
var domain = document.domain; | |
if (previousDomains.some(function(d){ return d == domain })){ | |
var navi = 'prev'; | |
var reg = /前[へにの]|戻る|prev|<</i | |
}else{ | |
var navi = 'next'; | |
var reg = /次[へにの]|進む|next|>>/i | |
} | |
var link = document.evaluate('//link[contains(@rel, "' + navi + '")]', document, null, 7, null).snapshotItem(0); | |
if (link){ | |
location.href = link.href; | |
return true; | |
} | |
var elements = document.links; | |
for (var i = elements.length-1; i >= 0; i--){ | |
var elem = elements[i]; | |
if (reg.test(elem.innerHTML)){ | |
elem.style.outline = '3px red solid'; | |
location.href = elem.href; | |
return true; | |
} | |
} | |
this.incrementURL(); | |
}, | |
hatenaBookmark : function(){ | |
top.location.href = 'http://b.hatena.ne.jp/add?mode=confirm&title='+escape(document.title)+'&url='+ escape(top.location.href); | |
}, | |
googleBookmarks : function(){ | |
var sel = window.getSelection().toString(); | |
top.location.href = 'http://www.google.co.jp/bookmarks/mark?op=add&bkmk=' + encodeURI(top.location.href) + '&title=' + encodeURIComponent(document.title) + (sel? '&annotation=' + encodeURIComponent(sel):''); | |
}, | |
livedoorClip : function(){ | |
top.location.href = 'http://clip.livedoor.com/clip/add?link='+encodeURIComponent(top.location.href)+'&title='+encodeURIComponent(document.title); | |
}, | |
livedoorReader : function(){ | |
top.location.href = 'http://reader.livedoor.com/subscribe/' + top.location.href; | |
}, | |
fastladder : function(){ | |
top.location.href='http://fastladder.com/subscribe/' + top.location.href; | |
}, | |
exciteENJA : function(){ | |
var sel = getSelection().toString(); | |
if (sel) window.open('http://www.excite.co.jp/world/english/?wb_lp=ENJA&before=' + encodeURIComponent(sel)); | |
}, | |
seachGoogle: function(){ | |
var sel = getSelection().toString(); | |
if (sel) window.open('http://www.google.co.jp/search?hl=ja&q=' + encodeURIComponent(sel)); | |
}, | |
seachYahooDictionary : function(){ | |
var sel = getSelection().toString(); | |
if (sel) window.open('http://dic.yahoo.co.jp/dsearch?enc=UTF-8&dtype=2&stype=0&p=' + encodeURIComponent(sel)); | |
}, | |
anchor : function(){ | |
var anc = '<a href="'+ top.location.href +'" target="_blank">'+ document.title +'</a>'; | |
prompt(anc, anc); | |
}, | |
openAllImages : function(){ | |
var sel = 'a[href$=".png"], a[href$=".gif"], a[href$=".jpg"], a[href$=".jpeg"], a[href$=".PNG"], a[href$=".GIF"], a[href$=".JPG"], a[href$=".JPEG"]'; | |
var l = Array.prototype.map.call(document.querySelectorAll(sel), function(elem){ | |
return '<img src="' + elem.href + '">'; | |
}).join(''); | |
var g = Array.prototype.map.call(document.images, function(elem){ | |
return '<img src="' + elem.src + '">'; | |
}).join(''); | |
window.open().document.write(l + '<hr>' + g); | |
}, | |
noRedirect : function(){ | |
Array.prototype.forEach.call(document.querySelectorAll('a[href*="=http"], a[href*="?http"]'), function(elem){ | |
elem.href = decodeURIComponent(elem.href).replace(/http.*(http[^&]*).*$/,'$1'); | |
elem.style.borderBottom = '1px dashed red'; | |
}); | |
var list = [ | |
'http://ime.nu/' | |
,'http://pinktower.com/' | |
,'http://goto.dtiblog.com/' | |
].map(function(elem){ | |
return 'a[href^="'+ elem +'"]'; | |
}); | |
Array.prototype.forEach.call(document.querySelectorAll(list.join(',')), function(elem){ | |
elem.href = elem.href.replace(/http\:\/\/.*?\//,'http://'); | |
elem.style.borderBottom = '1px dashed red'; | |
}); | |
}, | |
incrementURL : function(){ | |
if (!/\d/.test(location.href)) | |
return false; | |
function fillZero(t,n){return (t.toString().length < n)? (new Array(n).join('0')+t).substr(-n): t;} | |
location.href = location.href.replace(/^(.*[^\d])(\d+)($|[^\d]+)$/,function(str, first, num, last){ | |
return first + fillZero(parseInt(num,10)+1, num.length) + last; | |
}); | |
}, | |
decrementURL : function(){ | |
if (!/\d/.test(location.href)) | |
return false; | |
function fillZero(t,n){return (t.toString().length < n)? (new Array(n).join('0')+t).substr(-n): t;} | |
location.href = location.href.replace(/^(.*[^\d])(\d+)($|[^\d]+)$/,function(str, first, num, last){ | |
return first + fillZero(parseInt(num,10)-1, num.length) + last; | |
}); | |
}, | |
toggleCSS: function(){ | |
Array.prototype.forEach.call(document.styleSheets, function(elem){ | |
elem.disabled = !elem.disabled; | |
}); | |
}, | |
toggleCheck: function(){ | |
Array.prototype.forEach.call(document.querySelectorAll('input[type="checkbox"], input[type="radio"]'), function(elem){ | |
elem.checked = !elem.checked; | |
}); | |
}, | |
TheEnd : function(){ | |
Array.prototype.forEach.call(document.querySelectorAll('a,b,s,i,img,span,font,input:not([type="hidden"]),select,em,strong,cite,hr'), function(elem){ | |
elem.style.webkitTransform = 'rotate('+ Math.round(Math.random() * 36) + '0deg)'; | |
elem.style.webkitTransformOrigin = Math.round(Math.random() * 10) + '0% ' + Math.round(Math.random() * 10) + '0%'; | |
}); | |
}, | |
TheEnd2 : function(){ | |
document.body.innerHTML = document.body.innerHTML.replace(/>((.|\s)*?)</gi,function(p0,p1){return '>'+p1.split('').reverse().join('')+'<';}); | |
}, | |
}; | |
var keyconfig = { | |
keymap : { | |
'8':'backspace','9':'tab','13':'enter','27':'esc','32':' ', | |
'33':'pageup','34':'pagedown','35':'end','36':'home', | |
'37':'left','38':'up','39':'right','40':'down','45':'insert','46':'delete', | |
'48':'0','49':'1','50':'2','51':'3','52':'4','53':'5','54':'6','55':'7','56':'8','57':'9','59':':','61':';', | |
'65':'a','66':'b','67':'c','68':'d','69':'e','70':'f','71':'g','72':'h','73':'i', | |
'74':'j','75':'k','76':'l','77':'m','78':'n','79':'o','80':'p','81':'q','82':'r', | |
'83':'s','84':'t','85':'u','86':'v','87':'w','88':'x','89':'y','90':'z', | |
'96':'0','97':'1','98':'2','99':'3','100':'4','101':'5','102':'6','103':'7','104':'8','105':'9', | |
'106':'*','107':'+','109':'-','110':'.','111':'/', | |
'112':'f1','113':'f2','114':'f3','115':'f4','116':'f5','117':'f6', | |
'118':'f7','119':'f8','120':'f9','121':'f10','122':'f11','123':'f12', | |
'188':',','190':'.','191':'/','192':'@','219':'[','220':'\\','221':']','222':'^','226':'\\' | |
}, | |
init : function(){ | |
document.addEventListener('keydown', this, false); | |
}, | |
handleEvent : function(event){ | |
var target = event.target; | |
if (!event.altKey && | |
(target instanceof HTMLTextAreaElement || | |
target instanceof HTMLSelectElement || | |
(target instanceof HTMLInputElement && (!target.hasAttribute('type') || target.type == 'text' || target.type == 'password')))) | |
return; | |
var keycode = event.keyCode; | |
if (!keycode in this.keymap) | |
return; | |
var command = this.keymap[keycode] + (event.ctrlKey?'+ctrl':'') + (event.shiftKey?'+shift':'') + (event.altKey?'+alt':''); | |
switch(command){ | |
case 'h' : window.scrollBy(-30, 0); break; | |
case 'j' : window.scrollBy(0, 120); break; | |
case 'k' : window.scrollBy(0, -120); break; | |
case 'l' : window.scrollBy(30, 0); break; | |
case 'z' : history.back(); break; | |
case 'x' : history.forward(); break; | |
case '0+alt' : top.location.href = 'http://www.google.co.jp/'; break; | |
case '1+alt' : top.location.href = 'http://www.google.co.jp/bookmarks/'; break; | |
case '2+alt' : top.location.href = 'http://www.yahoo.co.jp/'; break; | |
case '3+alt' : top.location.href = 'http://reader.livedoor.com/'; break; | |
case 'backspace+alt' : func.goToParent(); break;// 上の階層に移動 | |
case 'a+shift' : func.anchor(); break; // アンカー作成 | |
case 'd+shift' : func.googleBookmarks(); break; // Google Bookmarks に登録 | |
case 'e+shift' : func.exciteENJA(); break; // excite 英和翻訳 | |
case 'f+shift' : func.fastForward(); break; // Fast Forward | |
case 'g+shift' : func.seachGoogle(); break; // 選択文字列を Google で検索 | |
case 'i+shift' : func.openAllImages(); break; // 画像とリンク先の画像を表示する | |
case 'y+shift' : func.seachYahooDictionary(); break; // 選択文字列を Yahoo! 辞書で検索 | |
case 'r+shift' : func.noRedirect(); break; // ime.nu などのリダイレクトを削除する | |
case '++shift' : func.incrementURL(); break; // URL の数字を増やす | |
case '-+shift' : func.decrementURL(); break; // URL の数字を減らす | |
case 'end+alt' : func.TheEnd(); break; | |
case 'pagedown+alt' : func.TheEnd2(); break; | |
case ' ' : | |
var html = document.documentElement; | |
if (html.scrollHeight - (html.scrollTop || document.body.scrollTop) == window.innerHeight) | |
func.fastForward(); | |
else return; | |
break; // スクロールできなかったら Fast Forward | |
default : return; | |
} | |
event.preventDefault(); | |
}, | |
}; | |
keyconfig.init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment