StakeUs+

Stake.US plugin framework

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/480138/1511853/StakeUs%2B.js

  1. // ==UserScript==
  2. // @name StakeUsPlus
  3. // @namespace a
  4. // @version 1.2
  5. // @description StakeUs plugin framework
  6. // @author diehard2k0
  7. // @match *://stake.us/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. const VERSION = '1.0.0';
  13. const INFO = 'Plugin Management';
  14. const LOCAL_STORAGE_KEY_DEBUG = 'debug';
  15.  
  16. // Utility function to log in a fancy way
  17. function logFancy(s, color="#00f7ff") {
  18. console.log("%cStakeUsPlus: %c"+s, `color: ${color}; font-weight: bold; font-size: 12pt;`, "color: black; font-weight: normal; font-size: 10pt;");
  19. }
  20.  
  21. // Define the StakeUsPlusPlugin and StakeUsPlus classes
  22. class StakeUsPlusPlugin {
  23. constructor(id, opts) {
  24. this.id = id;
  25. this.opts = opts;
  26. }
  27. }
  28.  
  29. class StakeUsPlus {
  30. constructor() {
  31. this.version = VERSION;
  32. this.plugins = {};
  33. this.panels = {};
  34. this.debug = true;
  35. this.info = INFO;
  36. this.nextUniqueId = 1;
  37. this.customMessageCallbacks = {};
  38. this.customChatCommands = {
  39. help: (command, data) => {
  40. console.log("help", command, data);
  41. }
  42. };
  43. this.customChatHelp = {};
  44. this.customDialogOptions = {};
  45.  
  46. if (localStorage.getItem(LOCAL_STORAGE_KEY_DEBUG) == "1") {
  47. this.debug = true;
  48. }
  49. }
  50.  
  51. // Register a plugin
  52. registerPlugin(plugin) {
  53. if (!(plugin instanceof StakeUsPlusPlugin)) {
  54. throw new TypeError("StakeUsPlus.registerPlugin takes the following arguments: (plugin:StakeUsPlusPlugin)");
  55. }
  56. if (plugin.id in this.plugins) {
  57. throw new Error(`StakeUsPlusPlugin with id "${plugin.id}" is already registered. Make sure your plugin id is unique!`);
  58. }
  59.  
  60. this.plugins[plugin.id] = plugin;
  61. let versionString = plugin.opts && plugin.opts.about && plugin.opts.about.version ? ` (v${plugin.opts.about.version})` : "";
  62. logFancy(`registered plugin "${plugin.id}"${versionString}`);
  63. }
  64.  
  65. // Add a panel (e.g., plugin settings panel)
  66. addPanel(id, title, content) {
  67. if (typeof id !== "string" || typeof title !== "string" || (typeof content !== "string" && typeof content !== "function")) {
  68. throw new TypeError("StakeUsPlus.addPanel takes the following arguments: (id:string, title:string, content:string|function)");
  69. }
  70. const panels = document.querySelector("#svelte > div.draggable.svelte-uhzn2f");
  71. panels.append(`
  72. <div data-layout class="svelte-uhzn2f" id="panel-${id}">
  73. <h1>${title}</h1>
  74. <hr>
  75. <div class="stakeusplus-panel-content"></div>
  76. </div>
  77. `);
  78. this.panels[id] = { id: id, title: title, content: content };
  79. this.refreshPanel(id);
  80. }
  81.  
  82. // Refresh a panel's content
  83. refreshPanel(id) {
  84. if (typeof id !== "string") {
  85. throw new TypeError("StakeUsPlus.refreshPanel takes the following arguments: (id:string)");
  86. }
  87. const panel = this.panels[id];
  88. if (!panel) {
  89. throw new TypeError(`Error rendering panel with id="${id}" - panel has not been added.`);
  90. }
  91. let content = panel.content;
  92. if (!["string", "function"].includes(typeof content)) {
  93. throw new TypeError(`Error rendering panel with id="${id}" - panel.content must be a string or a function returning a string.`);
  94. }
  95. if (typeof content === "function") {
  96. content = content();
  97. if (typeof content !== "string") {
  98. throw new TypeError(`Error rendering panel with id="${id}" - panel.content must be a string or a function returning a string.`);
  99. }
  100. }
  101. const panelContent = document.querySelector(`#panel-${id} .stakeusplus-panel-content`);
  102. panelContent.innerHTML = content;
  103. }
  104.  
  105. // Show modal
  106. showModal() {
  107. document.getElementById("pluginPanel").style.display = 'block'; // Show the modal
  108. }
  109.  
  110. // Toggle plugin panel (e.g., visibility of a plugin settings panel)
  111. togglePluginPanel() {
  112. var pluginPanel = document.querySelector("#svelte > div.draggable.svelte-uhzn2f");
  113. if (pluginPanel.style.display === "none") {
  114. console.log("Plugin Panel Turned On");
  115. pluginPanel.style.display = "flex";
  116. } else {
  117. console.log("Plugin Panel Turned Off");
  118. pluginPanel.style.display = "none";
  119. }
  120. }
  121.  
  122. // Show the plugin modal and set up its draggable behavior
  123. initModal() {
  124. const pluginPanel = document.getElementById("pluginPanel");
  125. const pluginPanelHeader = document.getElementById("pluginPanelHeader");
  126.  
  127. let isDragging = false;
  128. let offsetX, offsetY;
  129.  
  130. // Make the header draggable
  131. pluginPanelHeader.addEventListener("mousedown", (e) => {
  132. isDragging = true;
  133. offsetX = e.clientX - pluginPanel.offsetLeft;
  134. offsetY = e.clientY - pluginPanel.offsetTop;
  135. document.addEventListener("mousemove", handleDrag);
  136. document.addEventListener("mouseup", () => {
  137. isDragging = false;
  138. document.removeEventListener("mousemove", handleDrag);
  139. });
  140. });
  141.  
  142. // Handle the dragging movement
  143. function handleDrag(e) {
  144. if (isDragging) {
  145. pluginPanel.style.left = `${e.clientX - offsetX}px`;
  146. pluginPanel.style.top = `${e.clientY - offsetY}px`;
  147. }
  148. }
  149. }
  150. }
  151.  
  152. // Modal HTML structure
  153. document.body.insertAdjacentHTML('beforeend', `
  154. <div class="plugin-panel" id="pluginPanel">
  155. <div class="plugin-panel-header" id="pluginPanelHeader">Plugin Settings</div>
  156. <div class="plugin-panel-content">
  157. <p>Welcome to the plugin settings page!</p>
  158. <p>More content goes here.</p>
  159. </div>
  160. </div>
  161. `);
  162.  
  163. // Styles for modal and draggable behavior
  164. const style = document.createElement('style');
  165. style.innerHTML = `
  166. .plugin-panel {
  167. display: none;
  168. position: absolute;
  169. top: 70px;
  170. left: 50%;
  171. transform: translateX(-50%);
  172. z-index: 9999;
  173. background-color: white;
  174. border: 1px solid #ccc;
  175. border-radius: 5px;
  176. padding: 10px;
  177. max-height: 300px;
  178. overflow-y: auto;
  179. cursor: move;
  180. }
  181. .plugin-panel-header {
  182. padding: 10px;
  183. background: #ddd;
  184. cursor: move;
  185. border-radius: 5px 5px 0 0;
  186. text-align: center;
  187. font-weight: bold;
  188. }
  189. .plugin-panel-content {
  190. padding: 10px;
  191. font-size: 14px;
  192. }
  193. `;
  194. document.head.appendChild(style);
  195.  
  196. // Initialize the StakeUsPlus instance
  197. window.StakeUsPlusPlugin = StakeUsPlusPlugin;
  198. window.StakeUsPlus = new StakeUsPlus();
  199.  
  200. // Initialize modal dragging functionality
  201. window.StakeUsPlus.initModal();
  202.  
  203. // Example to show modal
  204. setTimeout(() => {
  205. window.StakeUsPlus.showModal();
  206. }, 1000);
  207.  
  208. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址