[英]How do I add next/previous button pagination on tampermonkey script?
I have the following Tampermonkey script我有以下 Tampermonkey 脚本
// ==UserScript==
// @name easyEye
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Read your web novel easily on mobile with paginated content
// @author Zimorok
// @match *://boxnovel.com/*
// @require http://code.jquery.com/jquery-latest.js
// @grant none
// ==/UserScript==
var $ = window.jQuery
$(document).ready(function() {
'use strict';
var chapterText = $("div.reading-content p").each(function(){
$(this).clone().wrap('<p>').parent().html();
});
//--div.read-container
//--replace the whole div text with only the chapterText
$('div.text-left').wrap('<div id="story">').html(chapterText);
//--https://stackoverflow.com/questions/12202324/split-text-into-pages-and-present-separately-html5
var contentBox = $('div.text-left');
var words = contentBox.html().split(' ');
function paginate() {
var newPage = $('<div class="page">').css({'border':'1px solid black','text-align':'justify','padding':'5px'});
contentBox.empty().append(newPage);
var pageText = null;
for(var i = 0; i < words.length; i++) {
var betterPageText;
if(pageText) {
betterPageText = pageText + ' ' + words[i];
} else {
betterPageText = words[i];
}
newPage.html(betterPageText);
if(newPage.height() > $(window).height()) {
newPage.html(pageText);
newPage.clone().insertBefore(newPage)
pageText = null;
} else {
pageText = betterPageText;
}
}
}
$(window).resize(paginate).resize();
$('html, body').animate({ scrollTop: $('#story').offset().top }, 'slow'); //--focus to the story
//--debug
console.log('')
});
This renders the site for an easy reading of the novel on mobile.这使得该网站可以在移动设备上轻松阅读小说。 How to add the next/previous button so I don't have to scroll to the next page?
如何添加下一个/上一个按钮,这样我就不必滚动到下一页?
Or is it possible to add touch-to-next page?或者是否可以添加触摸到下一页? Thanks!
谢谢!
i have manage to do the button but now it is blocking the div below.我已经设法做按钮,但现在它阻止了下面的 div。
// ==UserScript==
// @name easyEye
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Read your web novel easily on mobile with paginated content
// @author Zimorok
// @match *://boxnovel.com/*
// @require http://code.jquery.com/jquery-latest.js
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle("#navbar{overflow:hidden;background-color:#333}#navbar a{float:left;display:block;color:#f2f2f2;text-align:center;padding:14px;text-decoration:none}.content{padding:16px}.sticky{position:fixed;top:0;width:100%}.sticky+.content{padding-top:60px}");
var $ = window.jQuery
$(document).ready(function() {
'use strict';
var chapterText = $("div.reading-content p").each(function(){
$(this).clone().wrap('<p>').parent().html();
});
//--div.read-container
//--replace the whole div text with only the chapterText
$('div.text-left').wrap('<div id="story">').html(chapterText);
//--https://stackoverflow.com/questions/12202324/split-text-into-pages-and-present-separately-html5
var contentBox = $('div.text-left');
var words = contentBox.html().split(' ');
function paginate() {
var newPage = $('<div class="page">').css({'border':'1px solid black','text-align':'justify','padding':'5px'});
contentBox.empty().append(newPage);
var pageText = null;
for(var i = 0; i < words.length; i++) {
var betterPageText;
if(pageText) {
betterPageText = pageText + ' ' + words[i];
} else {
betterPageText = words[i];
}
newPage.html(betterPageText);
if(newPage.height() > $(window).height()) {
newPage.html(pageText);
newPage.clone().insertBefore(newPage)
pageText = null;
} else {
pageText = betterPageText;
}
}
//--create the page ID and add the div.page
$('div.page').each(function(index){
$(this).prop('id','page_'+index);
});
//--creating next/previous button
//--append the next/previous button
var nav = $('<div id="navbar">');
contentBox.prepend(nav);
for(var pn = 0; pn < $('div.page').length; pn++)
{
nav.append('<a href="#page_'+pn+'">'+pn+'</a>');
}
//--simple numbering and scroll-to
$("a[href^='#']").click(function(e) {
e.preventDefault();
var position = $($(this).attr("href")).offset().top;
$("body, html").animate({
scrollTop: position
} /* speed */ );
});
}
$(window).resize(paginate).resize();
$('html, body').animate({ scrollTop: $('#story').offset().top }, 'slow'); //--focus to the story
//fixed page button
var num = 200; //number of pixels before modifying styles
$(window).bind('scroll', function () {
if ($(window).scrollTop() > num) {
$('#navbar').addClass('sticky');
} else {
$('#navbar').removeClass('sticky');
}
});
//--debug
console.log('Pages: '+$('div.page').length);
});
my #navbar
will block a part of the top page
.我的
#navbar
将阻止page
的一部分。 how to avoid it so that when i click on the #navbar
, it will show the top div?如何避免它,以便当我点击
#navbar
时,它会显示顶部 div?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.