Oricon All Photo Loader

Oricon Photo Loader

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Oricon All Photo Loader 
// @namespace    http://tampermonkey.net/
// @author       gpt5
// @version      3.0
// @description  Oricon Photo Loader
// @match        https://www.oricon.co.jp/news/*/photo/1/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 解析總張數
    let captionEl = document.querySelector('.photo_caption h1');
    if (!captionEl) return;
    let match = captionEl.textContent.match(/((\d+)\/(\d+)枚)/);
    if (!match) return;
    let total = parseInt(match[2], 10);

    // 找第一張圖片
    let firstImg = document.querySelector('.main_photo_image img');
    if (!firstImg) return;

    // 建立 gallery
    let gallery = document.createElement('div');
    gallery.id = 'all-photo-gallery';
    gallery.style.marginTop = '20px';
    gallery.style.border = '2px solid #ddd';
    gallery.style.padding = '10px';
    let mainContainer = document.querySelector('#main_photo');
    if (mainContainer) mainContainer.insertAdjacentElement('afterend', gallery);

    // 工具:建立圖片+caption block
    function createPhotoBlock(imgSrc, captionText) {
        let block = document.createElement('div');
        block.className = 'photo-block';
        block.style.marginBottom = '20px';
        block.style.paddingBottom = '15px';
        block.style.borderBottom = '1px solid #ccc';

        let img = document.createElement('img');
        img.src = imgSrc;
        img.style.maxWidth = '100%';
        img.style.display = 'block';
        img.style.margin = '0 auto 8px auto';

        let cap = document.createElement('div');
        cap.textContent = captionText;
        cap.style.fontSize = '14px';
        cap.style.textAlign = 'center';
        cap.style.color = '#444';

        block.appendChild(img);
        block.appendChild(cap);
        return block;
    }

    // Step1: 先存第一張
    let photos = [];
    photos[1] = {
        img: firstImg.src,
        caption: captionEl.textContent
    };

    // Step2: 依序 fetch 其餘圖片 (用 Shift_JIS decoder)
    let fetches = [];
    for (let i = 2; i <= total; i++) {
        let url = location.href.replace('/photo/1/', `/photo/${i}/`);
        let f = fetch(url)
            .then(res => res.arrayBuffer())
            .then(buf => {
                let decoder = new TextDecoder("shift-jis");
                let html = decoder.decode(buf);
                let parser = new DOMParser();
                let doc = parser.parseFromString(html, 'text/html');
                let imgEl = doc.querySelector('.main_photo_image img');
                let capEl = doc.querySelector('.photo_caption h1');
                if (imgEl && capEl) {
                    photos[i] = {
                        img: imgEl.src,
                        caption: capEl.textContent
                    };
                }
            }).catch(e => console.error("Load error:", e));
        fetches.push(f);
    }

    // Step3: 等全部載入完成後,依頁碼順序 append
    Promise.all(fetches).then(() => {
        for (let i = 1; i <= total; i++) {
            if (photos[i]) {
                gallery.appendChild(createPhotoBlock(photos[i].img, photos[i].caption));
            }
        }
    });
})();