WebProgram/Tistory

[ Tistory ] 블로그 단축키 설정하기

Total Fix! 2016. 3. 31. 06:06

블로그 단축키 설정하기

 

일부 기능의 단축키를 설정하는 스크립트입니다.

 

 

이 스크립트를 사용 시 필요 사항

이 스크립트에서는 페이지 이동 시 1페이지 일 때는 최근 글 목록에서 다음 페이지를 뽑아오게 됩니다.

따라서 최근 글 목록이 필요합니다.

 

 

필요에 따라서 단축키를 추가하세요.

 

 

 

 

javascript
//단축키 설정
var this_page_num = $('.pagination > .numbox > a > span.selected').text().replace( /(\s*)/g, "" );
var last_page_num = $('.pagination > .numbox > a').last().text().replace( /(\s*)/g, "" );
this_page_num *= 1;
last_page_num *= 1;
var key = new Array();
if (this_page_num > 1 && this_page_num < last_page_num) { 
	key['a'] = $('.pagination > .numbox > a > span.selected').parent().prev().attr('href'); // < 이전페이지 (페이지 네이션에서 뽑아옴)
	key['s'] = $('.pagination > .numbox > a > span.selected').parent().next().attr('href'); // > 다음 페이지 (페이지 네이션에서 뽑아옴)
} else if (this_page_num > 1 && this_page_num === last_page_num){
	key['a'] = $('.pagination > .numbox > a > span.selected').parent().prev().attr('href'); // < 이전페이지 (페이지 네이션에서 뽑아옴)
} else { key['s'] = $('.recentPost li').eq(1).children('a').attr('href'); } // > 다음 페이지 (최근글에서 뽑아옴)
key['l'] = "https://www.tistory.com/login"; // 로그인
key['f'] = "/"; // 처음으로
key['w'] = "https://slic.tistory.com/m/manage/entry/post"; // 글쓰기
function getKey(keyStroke) {
	if ((event.srcElement.tagName != 'INPUT') && (event.srcElement.tagName != 'TEXTAREA')){
		isNetscape=(document.layers);
		eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
		which = String.fromCharCode(eventChooser).toLowerCase();
		for (var i in key)
		if (which == i) window.location = key[i];
	}
}
document.onkeypress = getKey;