Rule34 Combined Script

Combines functionality: Open all links in a div and download highest resolution MP4 video.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Rule34 Combined Script
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Combines functionality: Open all links in a div and download highest resolution MP4 video.
// @author       Your Name
// @match        *://*rule34*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // ---------------------------
    // Functionality 1: Open all links in a specific div
    // ---------------------------
    const targetDivSelector = '.thumbs.clearfix'; // CSS 선택자

    document.addEventListener('keydown', (event) => {
        if (event.key === '`') {
            const targetDiv = document.querySelector(targetDivSelector);
            if (!targetDiv) {
                alert('대상 div를 찾을 수 없습니다.');
                return;
            }

            const links = targetDiv.querySelectorAll('a[href]');
            if (links.length === 0) {
                alert('열 URL이 없습니다.');
                return;
            }

            links.forEach(link => {
                const url = link.href;
                if (url) window.open(url, '_blank');
            });
        }
    });

    // ---------------------------
    // Functionality 2: Download the highest resolution MP4 from rule34video.com
    // ---------------------------
    if (window.location.href.startsWith('https://rule34video.com/video')) {
        window.addEventListener('load', () => {
            const links = document.querySelectorAll('a.tag_item');

            if (!links || links.length === 0) {
                console.log("No video links found.");
                return;
            }

            let bestLink = null;
            let bestResolution = 0;

            links.forEach(link => {
                const text = link.textContent.trim();
                if (text.includes('MP4')) {
                    const resolutionMatch = text.match(/(\d+)p/);
                    if (resolutionMatch) {
                        const resolution = parseInt(resolutionMatch[1], 10);
                        if (resolution > bestResolution) {
                            bestResolution = resolution;
                            bestLink = link;
                        }
                    }
                }
            });

            if (bestLink) {
                const downloadUrl = bestLink.href;
                console.log(`Best video found: ${downloadUrl}`);
                const anchor = document.createElement('a');
                anchor.href = downloadUrl;
                anchor.download = '';
                document.body.appendChild(anchor);
                anchor.click();
                document.body.removeChild(anchor);
            } else {
                console.log("No suitable MP4 video found.");
            }
        });
    }
})();