Modify Limit Rate Script

Modify limit_rate directly from the fetched data

当前为 2025-01-09 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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("数据获取失败,请查看控制台以获取详情。");
        });
    });
})();