Pagetual

Perpetual pages - powerful auto-pager script. Auto fetching next paginated web pages and inserting into current page for infinite scroll. Support thousands of web sites without any rule.

< Feedback on Pagetual

Review: Good - script works

§
Posted: 15-10-2022

建議nextLinkByUrl增加第3種lastpage的判斷

測試在nextLinkByUrl添加以下代碼,可透過頁碼元素文字判斷是否已經是最後一頁。

let isLast = this.curSiteRule.nextLinkByUrl[4];
if (isLast) {
        let num = getElement(isLast, doc).textContent;
        let match = num.match(/(\d+)\/(\d+)/);
        if (match[1] == match[2]) {
            this.nextLinkHref = false;
            return null
        }
}

供測試的規則

    {
        "name": "無限動漫手機版 - 漫畫閱讀",
        "example": "https://8.twobili.com/comic/insurance_1475.html?ch=1",
        "url": "^https?://8\\.twobili\\.com/comic/\\w+\\.html\\?ch=\\d+(-\\d+)?$",
        "nextLinkByUrl": [
            "(ch=\\d+)(-(\\d+))?$",
            "$1-{($3.0||1)+1}",
            "",
            "",
            "#pagenum"
        ],
        "pageElement": "#TheImg",
        "replaceElement": "#pagenum,#pageindex",
        "pageAction": "document.querySelector('.pagetual_pageBar').remove();setTimeout(()=>{let ul=document.querySelector('#TheTable li');let h=ul.offsetHeight;let p=document.querySelector('.pinch-zoom-container');p.style.height=h+'px'},1000)",
        "rate": 3
    },
    {
        "name": "無限動漫 - 漫畫閱讀2",
        "example": "https://www.comicabc.com/online/new-18722.html?ch=26-1",
        "url": "^https?://www\\.comicabc\\.com/online/new-\\d+\\.html\\?ch=\\d+(-\\d+)?$",
        "nextLinkByUrl": [
            "(ch=\\d+)(-(\\d+))?$",
            "$1-{($3.0||1)+1}",
            "#next:not([style])",
            "",
            "#pagenum"
        ],
        "pageElement": "#TheImg",
        "replaceElement": "#pageindex,#pagenum",
        "css": "img[name='TheImg'] {max-width: 100% !important;display: block !important;margin: 0 auto !important;}#TheTable td:nth-child(1),#TheTable td:nth-child(3),.comment_block,#prevnext2,#prev,#next{display:none!important}",
        "pageAction": "document.querySelector('.pagetual_pageBar').remove();"
    },
    {
        "name": "無限動漫 - 漫畫閱讀",
        "example": "https://www.comicabc.com/ReadComic/103/1/1_FU4_LD9_7.html",
        "url": "^https?://www\\.comicabc\\.com/ReadComic/\\d+/\\d+/\\w+\\.html",
        "nextLinkByUrl": [
            "html(\\?p=(\\d+))?$",
            "html?p={($2.0||1)+1}",
            "#next:not([style])",
            "",
            "#pagenum"
        ],
        "pageElement": "#TheImg",
        "replaceElement": "#pageindex,#pagenum",
        "css": "img[name='TheImg'] {max-width: 100% !important;display: block !important;margin: 0 auto !important;}#TheTable td:nth-child(1),#TheTable td:nth-child(3),.comment_block,#prevnext2,#prev,#next{display:none!important}",
        "pageAction": "document.querySelector('.pagetual_pageBar').remove();"
    }

還有一種可能maxpage和currentpage處在兩個不同的元素位置
let maxpage = getElement(maxpage, doc).textContent;
let current = getElement(current, doc).textContent;
if (current == maxpage) {
this.nextLinkHref = false;
return null
}
不過目前還沒遇到需要這種情況的判斷

最後附上自用的自定義完整規則
https://raw.githubusercontent.com/skofkyo/AutoPager/main/pagetualRules_EX.json
折騰了快一個月,一個代碼小白參考了一堆代碼,東拼西湊的總算快弄完規則了。

hoothinAuthor
§
Posted: 15-10-2022

十分感謝分享。

我添加了一個stopSign,來判定停止條件,有4種用法

  1. stopSign: ["必定存在的元素選擇器", "需要排除的元素選擇器"]
  2. stopSign: [["當前頁碼的元素選擇器","對抓取到的元素内容進行正則篩選,取第一個分組"], ["最大頁碼的元素選擇器","對抓取到的元素内容進行正則篩選,取第一個分組"]]
  3. 結合1、2,stopSign: ["必定存在的元素選擇器", "需要排除的元素選擇器", ["當前頁碼的元素選擇器","對抓取到的元素内容進行正則篩選,取第一個分組"], ["最大頁碼的元素選擇器","對抓取到的元素内容進行正則篩選,取第一個分組"]]
  4. 傳入doc與nextLink,透過執行代碼,返回true則停止

例子:

    {
        "name": "無限動漫手機版 - 漫畫閱讀",
        "example": "https://8.twobili.com/comic/insurance_1475.html?ch=1",
        "url": "^https?://8\\.twobili\\.com/comic/\\w+\\.html\\?ch=\\d+(-\\d+)?$",
        "nextLinkByUrl": [
            "(ch=\\d+)(-(\\d+))?$",
            "$1-{($3.0||1)+1}"
        ],
        "stopSign": [
            [
                "#pagenum",
                "(\\d+)"
            ],
            [
                "#pagenum",
                "\\/(\\d+)"
            ]
        ],
        "pageElement": "#TheImg",
        "replaceElement": "#pagenum,#pageindex",
        "pageBar": 0,
        "css": ".pinch-zoom-container{height: auto; display: contents;}",
        "rate": 3
    }

如果可以的話,歡迎你把規則直接pr到主倉庫。

§
Posted: 15-10-2022

高手出手就是不一樣,直接適用多種情況,厲害厲害。
主倉庫是指https://github.com/hoothin/UserScripts/issues這邊嗎?

還有一個奇怪的問題,想不通為什麼這個規則在手機kiwi瀏覽器無效。

    {
        "name": "嗨皮漫畫 - 更新頁",
        "example": "https://m.happymh.com/latest",
        "url": "^https://m\\.happymh\\.com/latest$",
        "loadMore": ".more-div-btn"
    }

手機目前唯獨就這個站loadMore無效,其他的都正常,偏偏這個站又是手機上最常用的。
測試在電腦chrome主控台運行以下代碼是有效的
document.querySelector('.more-div-btn').click()
可是在手機kiwi上的開發人員工具主控台運行就沒有效果
運行移除有效document.querySelector('.more-div-btn').remove()
就很奇怪為什麼點擊的代碼沒有效果

hoothinAuthor
§
Posted: 15-10-2022

感謝反饋錯誤,已經兼容了。

沒料到這個站會單獨監聽觸摸。

是的,主倉庫是https://github.com/hoothin/UserScripts。fork一下之後修改pagetualRule.json,然後pull request,就可以合并到主分支了。

§
Posted: 25-10-2022
Edited: 25-10-2022

stopSign在xHamster這個站遇到了問題

下一頁元素沒有href屬性是透過腳本自動運行的,點擊下一頁元素到最後一頁,繼續點會從第1頁重新開始無限循環。
stopSign填寫反覆確認應該是沒有錯誤,但還是沒有判斷到已達最後一頁。
有用代碼在主控台測試過,獲取的元素數字正確。
document.querySelector('.photo-amounts-info').innerText.match(/^(\d+)/)[1];
document.querySelector('.photo-amounts-info').innerText.match(/(\d+)$/)[1];
當前頁數在前最大頁數在後

    {
        "name": "xHamster gallery",
        "example": "https://zh.xhamster.com/photos/gallery/15952229/513274272",
        "url": "^https?://([a-z]{2}\\.)?xhamster\\.com/photos/gallery/",
        "nextLink": ".fotorama__arr--next",
        "stopSign": [
            [
                ".photo-amounts-info",
                "^(\\d+)"
            ],
            [
                ".photo-amounts-info",
                "(\\d+)$"
            ]
        ],
        "pageElement": ".fotorama__active>img",
        "replaceElement": ".gallery-thumbs,.photo-amounts-info",
        "pageBar": 0,
        "initRun": 1,
        "autoLoadNum": "0",
        "css": "#photo_slider *{overflow: initial !important;position: initial !important;}.fotorama__stage{height:auto!important;}.fotorama__loaded--img:not(.fotorama__active){display:none!important}.fotorama__img {max-width: 98% !important;display: block !important;margin: 0 auto !important;}"
    }

另一個同樣會無限循環的例子,stopSign可以正常判斷已達最後一頁。
下一頁元素有href屬性
.itemCount當前頁數在後最大頁數在前

    {
        "name": "PornHub photo",
        "example": "https://cn.pornhub.com/photo/825175581",
        "url": "^https?://([a-z]{2}\\.)?pornhub\\.com/photo/\\d+",
        "init": "document.querySelector('.centerImage>a:nth-child(3)').removeAttribute('href')",
        "nextLink": ".arrowRight",
        "stopSign": [
            [
                ".itemCount",
                "(\\d+)$"
            ],
            [
                ".itemCount",
                "^(\\d+)"
            ]
        ],
        "pageElement": ".centerImage img",
        "replaceElement": ".arrowLeft,.arrowRight,.thumbSliderButtons,.thumbSliderContent,.itemCount",
        "pageBar": 0,
        "initRun": 1,
        "autoLoadNum": "0",
        "css": ".arrowLeft,.arrowRight{display:none!important}#photoImageSection img{margin:0!important}"
    }

所以不會停止的問題,是規則錯誤還是腳本BUG,麻煩大大看一下。

hoothinAuthor
§
Posted: 25-10-2022

感謝反饋,修復了

Post reply

Sign in to post a reply.