Greasy Fork 支持简体中文。

Modify Limit Rate Script

Modify limit_rate directly from the fetched data

  1. // ==UserScript==
  2. // @name Modify Limit Rate Script
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description Modify limit_rate directly from the fetched data
  6. // @author Your Name
  7. // @match *://*/*
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13.  
  14. // Create modify limit_rate button
  15. const modifyButton = document.createElement('button');
  16. modifyButton.textContent = '修改 limit_rate';
  17. modifyButton.style.position = 'fixed';
  18. modifyButton.style.top = '10px';
  19. modifyButton.style.right = '10px';
  20. modifyButton.style.zIndex = 1000;
  21. modifyButton.style.padding = '10px 15px';
  22. modifyButton.style.backgroundColor = '#007BFF';
  23. modifyButton.style.color = '#FFFFFF';
  24. modifyButton.style.border = 'none';
  25. modifyButton.style.borderRadius = '5px';
  26. modifyButton.style.cursor = 'pointer';
  27. document.body.appendChild(modifyButton);
  28.  
  29. // Get the id from the current URL path
  30. function getIdFromUrl() {
  31. const pathSegments = window.location.pathname.split('/'); // Split the path into segments
  32. return pathSegments[pathSegments.length - 1]; // Get the last segment which should be the id
  33. }
  34.  
  35. // Modify limit_rate button event handler
  36. modifyButton.addEventListener('click', () => {
  37. const id = getIdFromUrl(); // Fetch the id from the URL
  38.  
  39. if (!id) {
  40. alert("无法获取 ID,请确保 URL 中包含 'id'。");
  41. return;
  42. }
  43.  
  44. const fetchUrl = window.location.origin + `/api/admin/storage/get?id=${id}`;
  45. const token = window.localStorage['token'];
  46.  
  47. fetch(fetchUrl, {
  48. method: "GET",
  49. headers: {
  50. "authorization": token
  51. }
  52. })
  53. .then(response => response.json())
  54. .then(data => {
  55. console.log("获取成功:", data);
  56.  
  57. // Prompt for limit_rate modification based on current value
  58. const newLimitRate = prompt("当前 limit_rate: " + data.data.limit_rate + "\n请输入新的 limit_rate 值(留空则不修改):");
  59.  
  60. if (newLimitRate !== null && newLimitRate.trim() !== "") {
  61. // Update limit_rate in data
  62. const limitRateValue = parseFloat(newLimitRate);
  63. data.data.limit_rate = limitRateValue; // Update limit_rate
  64.  
  65. // Parse and modify the addition field
  66. const additionData = JSON.parse(data.data.addition);
  67.  
  68. // Update the addition field with the new limit_rate
  69. additionData.limit_rate = limitRateValue;
  70.  
  71. // Remove sensitive information if not necessary
  72. delete additionData.AccessToken; // Remove if not needed
  73. delete additionData.refresh_token; // Remove if not needed
  74.  
  75. // Update the addition field back to JSON string
  76. data.data.addition = JSON.stringify(additionData);
  77. }
  78.  
  79. // Confirm before updating
  80. if (confirm("是否更新 limit_rate 到以下值: " + data.data.limit_rate + "?")) {
  81. const updateUrl = window.location.origin + "/api/admin/storage/update"; // Assuming the update URL follows this pattern
  82.  
  83. // Send updated data back to the server
  84. fetch(updateUrl, {
  85. method: "POST",
  86. headers: {
  87. "Content-Type": "application/json",
  88. "authorization": token
  89. },
  90. body: JSON.stringify(data.data), // Send the modified data
  91. })
  92. .then(response => response.json())
  93. .then(responseData => {
  94. console.log("更新成功:", responseData);
  95. alert("limit_rate 更新成功!新值为: " + data.data.limit_rate);
  96. })
  97. .catch(error => {
  98. console.error("更新错误:", error);
  99. alert("limit_rate 更新失败,请查看控制台以获取详情。");
  100. });
  101. }
  102. })
  103. .catch(error => {
  104. console.error("获取错误:", error);
  105. alert("数据获取失败,请查看控制台以获取详情。");
  106. });
  107. });
  108. })();
  109.