Automatically get name

Get the species name and Latin name

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Automatically get name
// @namespace    http://tampermonkey.net/
// @version      2024-11-15
// @description  Get the species name and Latin name
// @author       wokao2333
// @match        https://ppbc.iplant.cn/userspecials/54439/3941
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    alert("请不要操作页面,点击确定开始下载")
    let DIV = document.createElement("div");
    DIV.style.position = 'fixed';
    DIV.style.top = '10px';
    DIV.style.left = '20px';
     DIV.style.backgroundColor = 'pink';
    DIV.style.fontSize = '22px';
     DIV.style.fontWeight = '600';
    document.body.appendChild(DIV);
    window.addEventListener('load', function() {
        let title3 = document.querySelector(".title3");
        if (title3) {
            let totalPages = parseInt(title3.innerHTML.match(/\d+/)[0], 10);
            downloadAllPages(parseInt(totalPages/19));
        }
    });

    function downloadAllPages(totalPages) {
        let allNames = [];
        let currentPage = 1;

        function fetchPage() {
            if (currentPage > totalPages) {
                downloadAsWord(allNames);
                return;
            }
            DIV.textContent = `已请求${currentPage}次,请不要操作页面,请求完会自动下载`
            let url = `https://ppbc.iplant.cn/ashx/getuserphotopage.ashx?page=${currentPage}&n=2&group=userspeciallist2&sid=3940&uid=8486BCA5BF54C193`;
            fetch(url)
                .then(response => {
                // 检查响应状态码
                if (response.status === 200) {
                    return response.text();
                } else {
                    throw new Error('Server responded with status: ' + response.status);
                }
            })
                .then(html => {
                if (html.trim() === '') {
                    console.log('无数据');
                    downloadAsWord(allNames);
                    return;
                }

                let parser = new DOMParser();
                let doc = parser.parseFromString(html, "text/html");
                let items = doc.querySelectorAll('.nameall');
                items.forEach(item => {
                    let itemName = item.textContent.trim();
                    if (!allNames.includes(itemName)) {
                        allNames.push(itemName);
                    }
                });
                currentPage++;
                fetchPage();
            })
                .catch(error => {
                console.error('Failed to fetch page:', currentPage, error);
                // 如果发生错误,也下载之前的数据
                downloadAsWord(allNames);
            });
        }


        fetchPage();
    }

    function downloadAsWord(allNames) {
        let content = allNames.join("\n");
        let blob = new Blob([content], { type: "text/plain;charset=utf-8" });
        let a = document.createElement("a");
        a.href = URL.createObjectURL(blob);
        a.download = "photoName.txt";
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        alert("下载完成");
    }
})();