auto-lady

订阅小姐姐

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         auto-lady
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  订阅小姐姐
// @author       oreki
// @match        https://www.javlibrary.com/cn/*
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 添加菜单选项让用户设置订阅地址
    GM_registerMenuCommand('设置订阅地址', () => {
        const url = prompt('请输入订阅请求地址:', GM_getValue('subscriptionUrl', 'https://default-subscription-url.com/subscribe'));
        if (url) {
            GM_setValue('subscriptionUrl', url);
            alert('订阅地址已保存');
        }
    });

    // 获取所有影片条目
    const movieItems = document.querySelectorAll('.video');  // 根据页面结构修改

    // 为每个影片条目添加订阅按钮
    movieItems.forEach((movieItem) => {
        const div = document.createElement('div');
        // 创建 <a> 元素
        const subButton = document.createElement('button');
        subButton.innerText = '订阅影片';
        subButton.className = 'smallbutton'
        const idDiv = movieItem.querySelector('.id');
        const movieId = idDiv ? idDiv.innerText : '';
        // 将按钮添加到影片项中
        div.appendChild(subButton)
        idDiv.appendChild(div);
        // 绑定点击事件
        subButton.addEventListener('click', (event) => {
            event.stopPropagation();  // 阻止事件冒泡
            event.preventDefault();


            // 获取订阅请求地址并发送订阅请求
            const subscriptionUrl = GM_getValue('subscriptionUrl', '');

            // 发送POST请求
            GM_xmlhttpRequest({
                method: 'POST',
                url: subscriptionUrl,
                headers: {
                    'Content-Type': 'application/json'
                },
                data: JSON.stringify({ code: movieId,filter:{},mode:''}),
                onload: function(response) {
                    if (response.status === 200) {
                        alert(`番号 ${movieId} 订阅成功!`);
                    } else {
                        alert(`订阅失败:${response.responseText}`);
                    }
                },
                onerror: function() {
                    alert('订阅请求失败,番号'+movieId);
                }
            });
        });
    });
})();