From 48e5dc02b7d1c042998718318d935e3ae8c47f60 Mon Sep 17 00:00:00 2001 From: HCLonely Date: Mon, 3 Jan 2022 17:18:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5js=E4=BD=BF=E7=94=A8=E5=B1=80?= =?UTF-8?q?=E9=83=A8=E5=8F=98=E9=87=8F=EF=BC=8C=E9=98=B2=E6=AD=A2=E6=B1=A1?= =?UTF-8?q?=E6=9F=93=E5=85=A8=E5=B1=80=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/templates/bangumi.ejs | 2 +- lib/templates/index.js | 4 +- lib/templates/pagination.js | 4 +- package.json | 2 +- src/lib/templates/index.js | 60 ++++++++-------- src/lib/templates/pagination.js | 118 ++++++++++++++++---------------- 6 files changed, 97 insertions(+), 93 deletions(-) diff --git a/lib/templates/bangumi.ejs b/lib/templates/bangumi.ejs index 9c9740b..a6c32de 100644 --- a/lib/templates/bangumi.ejs +++ b/lib/templates/bangumi.ejs @@ -39,6 +39,6 @@ diff --git a/lib/templates/index.js b/lib/templates/index.js index e89f015..44863aa 100644 --- a/lib/templates/index.js +++ b/lib/templates/index.js @@ -1,2 +1,2 @@ -"use strict";Element.prototype.siblings=function(){for(var a=[],b=this.parentNode.children,c=0;c 0) { - currNum-- + function previousBtn() { + const sibs = this.parentNode.siblings() + let currNum = this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText + currNum = currNum.substr(0, currNum.indexOf('/') - 1) + currNum = parseInt(currNum, 10) - 1 + if (currNum > 0) { + currNum-- + } + displayPage(sibs, currNum) + this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(currNum, sibs) } - displayPage(sibs, currNum) - this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(currNum, sibs) -} -function nextBtn () { - var sibs = this.parentNode.siblings() - var currNum = this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText - currNum = currNum.substr(0, currNum.indexOf('/') - 1) - currNum = parseInt(currNum, 10) - 1 - if (currNum < Math.ceil(sibs.length / 10) - 1) { - currNum++ + function nextBtn() { + const sibs = this.parentNode.siblings() + let currNum = this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText + currNum = currNum.substr(0, currNum.indexOf('/') - 1) + currNum = parseInt(currNum, 10) - 1 + if (currNum < Math.ceil(sibs.length / 10) - 1) { + currNum++ + } + displayPage(sibs, currNum) + this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(currNum, sibs) } - displayPage(sibs, currNum) - this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(currNum, sibs) -} -function lastBtn () { - var sibs = this.parentNode.siblings() - displayPage(sibs, Math.ceil(sibs.length / 10) - 1) - this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(Math.ceil(sibs.length / 10) - 1 === -1 ? 0 : Math.ceil(sibs.length / 10) - 1, sibs) -} + function lastBtn() { + const sibs = this.parentNode.siblings() + displayPage(sibs, Math.ceil(sibs.length / 10) - 1) + this.parentNode.getElementsByClassName('bangumi-pagenum')[0].innerText = makePageNum(Math.ceil(sibs.length / 10) - 1 === -1 ? 0 : Math.ceil(sibs.length / 10) - 1, sibs) + } -function displayPage (arr, num) { - for (var i = 0; i < arr.length; i++) { - if (Math.floor(i / 10) === num) { - arr[i].classList.remove('bangumi-hide') - var img = arr[i].getElementsByTagName('img')[0] - img.src = img.getAttribute('data-src') - } else { - arr[i].classList.add('bangumi-hide') + function displayPage(arr, num) { + for (let i = 0; i < arr.length; i++) { + if (Math.floor(i / 10) === num) { + arr[i].classList.remove('bangumi-hide') + const img = arr[i].getElementsByTagName('img')[0] + img.src = img.getAttribute('data-src') + } else { + arr[i].classList.add('bangumi-hide') + } } } -} -for (var i = 0; i < firstpages.length; i++) { - // add listener - firstpages[i].onclick = firstBtn - previouspages[i].onclick = previousBtn - nextpages[i].onclick = nextBtn - lastpages[i].onclick = lastBtn + for (let i = 0; i < firstpages.length; i++) { + // add listener + firstpages[i].onclick = firstBtn + previouspages[i].onclick = previousBtn + nextpages[i].onclick = nextBtn + lastpages[i].onclick = lastBtn - // set page num - var size = pagenums[i].parentNode.siblings().length - pagenums[i].innerText = '1 / ' + (Math.ceil(size / 10) === 0 ? 1 : Math.ceil(size / 10)) - firstpages[i].click() -} + // set page num + const size = pagenums[i].parentNode.siblings().length + pagenums[i].innerText = '1 / ' + (Math.ceil(size / 10) === 0 ? 1 : Math.ceil(size / 10)) + firstpages[i].click() + } +})()