Modify Limit Rate Script

Modify limit_rate directly from the fetched data

目前為 2025-01-09 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Modify Limit Rate Script
// @namespace    http://tampermonkey.net/
// @version      0.8
// @description  Modify limit_rate directly from the fetched data
// @author       Your Name
// @match        *://*/*
// @license MIT
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    // Create modify limit_rate button
    const modifyButton = document.createElement('button');
    modifyButton.textContent = '修改 limit_rate';
    modifyButton.style.position = 'fixed';
    modifyButton.style.top = '10px';
    modifyButton.style.right = '10px';
    modifyButton.style.zIndex = 1000;
    modifyButton.style.padding = '10px 15px';
    modifyButton.style.backgroundColor = '#007BFF';
    modifyButton.style.color = '#FFFFFF';
    modifyButton.style.border = 'none';
    modifyButton.style.borderRadius = '5px';
    modifyButton.style.cursor = 'pointer';
    document.body.appendChild(modifyButton);

    // Modify limit_rate button event handler
    modifyButton.addEventListener('click', () => {
        const fetchUrl = window.location.origin + "/api/admin/storage/get?id=7";
        const token = window.localStorage['token'];

        fetch(fetchUrl, {
            method: "GET",
            headers: {
                "authorization": token
            }
        })
        .then(response => response.json())
        .then(data => {
            console.log("获取成功:", data);

            // Prompt for limit_rate modification based on current value
            const newLimitRate = prompt("当前 limit_rate: " + data.data.limit_rate + "\n请输入新的 limit_rate 值(留空则不修改):");

            if (newLimitRate !== null && newLimitRate.trim() !== "") {
                // Update limit_rate with the new value
                data.data.limit_rate = parseFloat(newLimitRate); // Ensure it's a float

                // Also update the addition field with the new limit_rate
                const additionData = JSON.parse(data.data.addition);
                additionData.limit_rate = data.data.limit_rate;
                data.data.addition = JSON.stringify(additionData);
            }

            // Confirm before updating
            if (confirm("是否更新 limit_rate 到以下值: " + data.data.limit_rate + "?")) {
                const updateUrl = window.location.origin + "/api/admin/storage/update"; // Assuming the update URL follows this pattern

                // Send updated data back to the server
                fetch(updateUrl, {
                    method: "POST",
                    headers: {
                        "Content-Type": "application/json",
                        "authorization": token
                    },
                    body: JSON.stringify(data.data), // Send the modified data
                })
                .then(response => response.json())
                .then(responseData => {
                    console.log("更新成功:", responseData);
                    alert("limit_rate 更新成功!新值为: " + data.data.limit_rate);
                })
                .catch(error => {
                    console.error("更新错误:", error);
                    alert("limit_rate 更新失败,请查看控制台以获取详情。");
                });
            }
        })
        .catch(error => {
            console.error("获取错误:", error);
            alert("数据获取失败,请查看控制台以获取详情。");
        });
    });
})();