UserScript
code: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;texti && texti.children;i++){ for(var j=0;texti.childrenj && texti.childrenj.children;j++){ for(var k=0;texti.childrenj.childrenk && texti.childrenj.childrenk.children;k++){ for(var l=0;texti.childrenj.childrenk.childrenl;l++){ if(texti.childrenj.childrenk.childrenl.href){ if(texti.childrenj.childrenk.childrenl.href.match(/\d\d\d$/)){ links.push(texti.childrenj.childrenk.childrenl); }
}
}
}
}
}
return links;
}
var touchstartx, touchendx, touchstarty, touchendy;
$('body').on('touchstart',function(e){
touchstartx = e.changedTouches0.pageX; touchstarty = e.changedTouches0.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.changedTouches0.pageX; touchendy = e.changedTouches0.pageY; var moved = false;
if(touchendx - touchstartx > 100){
links1.click(); // 次ページへのリンクのクリックをシミュレート moved = true;
}
if(touchendx - touchstartx < -100){
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'){
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;
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);
}
});