javdb 重排序

根据评分人数降序排列,且会自动加载十页的内容

目前為 2022-10-15 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         javdb 重排序
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  根据评分人数降序排列,且会自动加载十页的内容
// @author       You
// @match        https://javdb.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=javdb.com
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    let peoplePattern = /由(\d+)人/;
    let pagePattern = /page=(\d+)/;
    let movieList = $('.movie-list')[0]
    let maxPageOffset = 0;
    let paginationNext = $('.pagination-next')
    let curPage = getCurPage()
    if (paginationNext && paginationNext.length) {
        paginationNext = paginationNext[0]
        maxPageOffset = 9;
        paginationNext.href = getPageUrl(curPage+maxPageOffset+1)
        paginationNext.textContent = `下${maxPageOffset+1}页`
    }
    main()
    function main(){
        reSortByPeopleCnt()
        for (let pageOffset = 0; pageOffset < maxPageOffset; pageOffset++) {
            let newPage = curPage + pageOffset + 1;
            loadPage(newPage, newList => {
                reSortByPeopleCnt(newList)
                console.log(`load page:${newPage}`)
            })
        }
    }


    function reSortByPeopleCnt(newList) {
        let curList = $('.item', movieList);
        let allList = []
        for (let i of curList) {
            allList.push(i)
        }
        if (newList && newList.length) {
            for (let i of newList) {
                allList.push(i)
            }
        }
        for (let item of allList) {
            let score = $('.score', item)[0]
            let searchRes = peoplePattern.exec(score.textContent)
            let peopleCnt = searchRes[1]
            peopleCnt = Number.parseInt(peopleCnt)
            item.peopleCnt = peopleCnt
            score.innerHTML = score.innerHTML.replace(/由(\d+)人/, '由<span style="color:red">$1</span>人')
        }
        allList.sort((a, b) => b.peopleCnt - a.peopleCnt)
        allList = allList.slice(0, 100)
        movieList.innerHTML = ""
        for (let item of allList) {
            movieList.append(item)
        }
    }
    function getCurPage() {
        let curPath = window.location.href;
        let searchRes = pagePattern.exec(curPath)
        if (searchRes && searchRes.length > 1) {
            return Number.parseInt(searchRes[1])
        }
        return 1
    }

    function getPageUrl(page) {
        let curPath = window.location.href;
        let pageIdx = curPath.indexOf('page');
        if (pageIdx > 0) {
            return curPath.replace(pagePattern, `page=${page}`)
        } else {
            if (curPath.indexOf('?') > 0) {
                return curPath + `&page=${page}`
            } else {
                return curPath + `?page=${page}`
            }
        }
    }
    function loadPage(page, cb) {
        let pageUrl = getPageUrl(page)
        getdata(pageUrl, data => {
            let container = document.createElement('div');
            container.style.display = 'none'
            container.innerHTML = data
            let newList = $('.movie-list .item', container)
            cb(newList)
        })
    }

    function getdata(pageUrl, cb) {
        $.get(pageUrl, function (data, status) {
            cb(data)
        });
    }



})();