UserScript
Scrapbox用のUserScriptを置いておく
pagetrans.js
//
// 矢印キーなどで次のページに移動
// location.href = 次ページ だとリロードになるので遅くなるのでリンククリックをシミュレートしている
// ページのどこかに [99] [101] みたいなリンクを書いておく
//
$(function(){
//if(scrapbox.Page.title.match(/^\d{3}/)){
/*
if(location.href.match(/^\d{3}/)){
$('.navbar').css('display','none');
$('.container').css('display','none')
$('.line-title').css('display','none')
//$('.line-title').css('height','1')
$('.page').css('padding','0')
}
*/
});
function find_links(){ // 前のページと次のページへのリンク (e.g. [123] [125]) を探す
var links = [];
var text = $('.text');
for(var i=0;text[i] && text[i].children;i++){
for(var j=0;text[i].children[j] && text[i].children[j].children;j++){
for(var k=0;text[i].children[j].children[k] && text[i].children[j].children[k].children;k++){
for(var l=0;text[i].children[j].children[k].children[l];l++){
if(text[i].children[j].children[k].children[l].href){
if(text[i].children[j].children[k].children[l].href.match(/\d\d\d$/)){
links.push(text[i].children[j].children[k].children[l]);
}
}
}
}
}
}
return links;
}
var touchstartx, touchendx, touchstarty, touchendy;
$('body').on('touchstart',function(e){
touchstartx = e.changedTouches[0].pageX;
touchstarty = e.changedTouches[0].pageY;
});
$('body').on('touchend',function(e){ // スワイプでページ移動
var title = scrapbox.Page.title;
if(!title.match(/^\d{3}/)) return;
var links = find_links();
var pageno = Number(title);
touchendx = e.changedTouches[0].pageX;
touchendy = e.changedTouches[0].pageY;
var moved = false;
if(touchendx - touchstartx > 100){
links[1].click(); // 次ページへのリンクのクリックをシミュレート
moved = true;
}
if(touchendx - touchstartx < -100){
links[0].click();
moved = true;
}
if(touchendy - touchstarty < -100 || touchendy - touchstarty > 100){
location.href = location.href.replace(/\d{3}/,'');
}
if(moved){
$('.navbar').css('display','none');
$('.quick-launch').css('display','none');
$('.container').css('display','none')
setTimeout(function(){
$('.line-title').css('height','1')
//scrollTo(0,50);
},1500);
$('.page').css('padding','0')
}
});
$('body').on('keydown',function(e){ // 左右矢印キーで次のページ/前のページに移動
var links = find_links();
var title = scrapbox.Page.title;
if(!title.match(/^\d{3}/)) return;
var pageno = Number(title);
var move = false;;
if(e.target.tagName == "TEXTAREA" || e.target.tagName == "INPUT") return;
if(e.key == 'ArrowRight' || e.key == 'f'){
links[1].click();
move = true;
/*
var nextpage = pageno + 1;
var nexttitle = ('000' + nextpage).slice(-3);
nextloc = location.href.replace(/\d{3}/,nexttitle);
*/
}
if(e.key == 'ArrowLeft' || e.key == 'b'){
if(e.target.tagName == "TEXTAREA" || e.target.tagName == "INPUT") return;
links[0].click();
move = true;
/*
var nextpage = pageno - 1;
var nexttitle = ('000' + nextpage).slice(-3);
nextloc = location.href.replace(/\d{3}/,nexttitle);
*/
}
if(e.key == 't'){ // リスト画面に戻る
location.href = location.href.replace(/\d{3}/,'');
}
if(move){
//location.href = nextloc;
$('.quick-launch').css('display','none');
$('.navbar').css('display','none');
$('.container').css('display','none')
setTimeout(function(){
// $('.line-title').css('height','1')
scrollTo(0,100);
},1500);
//$('.line-title').css('height','1')
//$('.section-title').css('display','none')
$('.page').css('padding','0')
//scrollTo(0,100);
}
});