🏠 Home 

Strategry Import/Export on Stake|Stake策略导入导出

Import and export dice strategy on Stake.Contact @fcfcface via telegram for more tools.通过Telegram联系@fcfcface获取更多工具。

  1. // ==UserScript==
  2. // @name Strategry Import/Export on Stake|Stake策略导入导出
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Import and export dice strategy on Stake.Contact @fcfcface via telegram for more tools.通过Telegram联系@fcfcface获取更多工具。
  6. // @author FCFC
  7. // @match https://stake.com/zh/casino/games/dice
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=stake.com
  9. // @match https://stake.com/*
  10. // @match https://stake.ac/*
  11. // @match https://stake.games/*
  12. // @match https://stake.bet/*
  13. // @match https://stake.pet/*
  14. // @match https://stake.mba/*
  15. // @match https://stake.jp/*
  16. // @match https://stake.bz/*
  17. // @match https://stake.ceo/*
  18. // @match https://stake.krd/*
  19. // @match https://staketr.com/*
  20. // @match https://stake1001.com/*
  21. // @match https://stake1002.com/*
  22. // @match https://stake1003.com/*
  23. // @match https://stake1021.com/*
  24. // @match https://stake.us/*
  25. // @require https://code.jquery.com/jquery-3.7.1.min.js
  26. // @grant GM_getResourceText
  27. // @grant GM_addStyle
  28. // @require https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.js
  29. // @require https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/mode/javascript/javascript.min.js
  30. // @resource codemirrorCSS https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/codemirror.min.css
  31. // @resource codemirrorthemeCSS https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.5/theme/dracula.min.css
  32. // ==/UserScript==
  33. (function() {
  34. 'use strict';
  35. // 获取CSS内容
  36. const css = GM_getResourceText("codemirrorCSS");
  37. const css1 = GM_getResourceText("codemirrorthemeCSS");
  38. // 添加到页面样式中
  39. GM_addStyle(css);
  40. GM_addStyle(css1);
  41. var $ = $ || window.$;
  42. $(function(){
  43. var botName = GM_info.script.name;
  44. var version = GM_info.script.version;
  45. var storeKey = 'strategies_saved';
  46. var list = [];
  47. var selectedList = [];
  48. var editor = null;
  49. var storage = {
  50. get: async(key) => {
  51. try {
  52. const res = localStorage.getItem(key);
  53. return JSON.parse(res);
  54. } catch(error) {
  55. throw error;
  56. }
  57. },
  58. set: async(key, data) => {
  59. try {
  60. let datastr = JSON.stringify(data);
  61. localStorage.setItem(key, datastr);
  62. } catch(error) {
  63. throw error;
  64. }
  65. }
  66. }
  67. var language = {
  68. zh: {
  69. showBotLabel: '策略管理',
  70. botName: '策略导入导出',
  71. export: '导出',
  72. import: '导入',
  73. selectStra: '选择要导出的策略',
  74. selectFile: '从JSON文件导入',
  75. fileError: '文件解析错误。',
  76. ImportNotFound: '请选选择json文件或者粘贴json内容。',
  77. importSuccess: '已导入,请刷新页面。',
  78. exportNotFound: '请先选择要导出的策略。',
  79. exportSuccess: '已导出,请查看浏览器下载列表。',
  80. },
  81. en: {
  82. showBotLabel: 'Strategy',
  83. botName: 'Strategy Import/Export',
  84. export: 'Export',
  85. import: 'Import',
  86. selectStra: 'Select the strategy to export',
  87. selectFile: 'Import from json file',
  88. fileError: 'File parsing error.',
  89. ImportNotFound: 'Please select the json file or paste the json content.',
  90. importSuccess: 'mported, please refresh the page.',
  91. exportNotFound: 'Please select the strategy you want to export first.',
  92. exportSuccess: 'Exported, please check the browser download list.',
  93. }
  94. }
  95. var locale = window.location.href.indexOf('/zh') > -1 ? 'zh' : 'en';
  96. var i18n = locale == 'zh' ? language.zh : language.en;
  97. init();
  98. async function init() {
  99. await UI();
  100. // 初始化 CodeMirror 编辑器
  101. let target = $('#strategyWrap .editor textarea')[0];
  102. editor = CodeMirror.fromTextArea(target, {
  103. mode: { name: "javascript", json: true },
  104. lineNumbers: true,
  105. //theme: "default",
  106. theme: "dracula", // 设置黑暗主题
  107. tabSize: 2,
  108. });
  109. editor.setSize("100%", "300px");
  110. await getList();
  111. exportStrategy();
  112. chooseFile();
  113. importStrategy();
  114. }
  115. async function getList() {
  116. try {
  117. list = await storage.get(storeKey);
  118. const straList = [];
  119. let renderList = '';
  120. list.forEach((item, index) => {
  121. straList.push({name: item.label, index});
  122. renderList+= `<div class="strategy-item">${item.label}</div>`
  123. })
  124. $('#strategyWrap .strategy').html(renderList);
  125. // 获取所选项的值
  126. $('#strategyWrap .strategy-item').click(function(e) {
  127. let index = $(this).index();
  128. let name = $(this).text();
  129. //console.log('Index:' + index);
  130. let active = $(this).hasClass('stra-item-active');
  131. let select = !active;
  132. if (select) {
  133. $(this).addClass('stra-item-active');
  134. selectedList.push(list[index]);
  135. } else {
  136. //console.log('取消选择:' + name);
  137. $(this).removeClass('stra-item-active');
  138. const newSelectList = [];
  139. selectedList.forEach(item => {
  140. if (item.label != name) {
  141. newSelectList.push(item);
  142. }
  143. });
  144. selectedList = newSelectList;
  145. }
  146. //console.log(selectedList)
  147. //editor.setValue(JSON.stringify(selectedList, null, 2));
  148. })
  149. } catch(error) {
  150. message(error.message, 'error');
  151. }
  152. }
  153. function chooseFile() {
  154. document.getElementById('json-input').addEventListener('change', function(event) {
  155. const file = event.target.files[0];
  156. if (file) {
  157. const reader = new FileReader();
  158. reader.onload = function(e) {
  159. try {
  160. // 将文件内容解析为 JSON 对象
  161. const jsonData = JSON.parse(e.target.r###lt);
  162. editor.setValue(JSON.stringify(jsonData, null, 2));
  163. } catch (error) {
  164. console.error("文件解析错误:", error);
  165. message(i18n.fileError, 'error');
  166. }
  167. };
  168. reader.readAsText(file); // 读取文件内容
  169. }
  170. });
  171. }
  172. function importStrategy() {
  173. $('#strategyWrap .import-btn').click(async function(){
  174. try {
  175. const content = editor.getValue();
  176. if (!content || !content.toString || content.toString() == '[]' || content.toString() == '{}') {
  177. message(i18n.ImportNotFound);
  178. return;
  179. }
  180. const newList = JSON.parse(content); // 解析 JSON 验证格式
  181. const oldList = await storage.get(storeKey);
  182. const oldlabels = [];
  183. oldList.forEach(item => {
  184. oldlabels.push(item.label);
  185. })
  186. newList.forEach((item,index) => {
  187. if (oldlabels.includes(item.label)) {
  188. newList[index].label = `${item.label}-1`;
  189. }
  190. })
  191. oldList.push(...newList);
  192. // 保存策略
  193. await storage.set(storeKey, oldList);
  194. message(i18n.importSuccess, 'success');
  195. editor.setValue("");
  196. } catch(error) {
  197. message(error.message, 'error');
  198. }
  199. })
  200. }
  201. function exportStrategy() {
  202. $('#strategyWrap .export-btn').click(function() {
  203. if (selectedList.length == 0) {
  204. message(i18n.exportNotFound);
  205. return;
  206. }
  207. selectedList.map(item => {
  208. item.label = `${item.label}`;
  209. return item;
  210. })
  211. const filename = 'export_strategy.json';
  212. // 将 JSON 对象转为字符串
  213. const jsonStr = JSON.stringify(selectedList, null, 2);
  214. // 创建 Blob 对象
  215. const blob = new Blob([jsonStr], { type: "application/json" });
  216. // 创建下载链接
  217. const link = document.createElement("a");
  218. link.href = URL.createObjectURL(blob);
  219. link.download = filename;
  220. // 触发下载
  221. link.click();
  222. // 释放 URL 对象
  223. URL.revokeObjectURL(link.href);
  224. message(i18n.exportSuccess, 'success');
  225. })
  226. }
  227. function message(text, type) {
  228. let msgHtml = '';
  229. let successColor = '#00e701';
  230. let errorColor = 'red';
  231. if (type == 'success') {
  232. msgHtml = `<div style="color: ${successColor}">${text}</div>`;
  233. } else if (type == 'error') {
  234. msgHtml = `<div style="color: ${errorColor}">${text}</div>`;
  235. } else {
  236. msgHtml = `<div style="color:#e3a725">${text}</div>`;
  237. }
  238. $('#strategyWrap .error-message-wrap').html(msgHtml);
  239. }
  240. async function UI() {
  241. // 获取窗口宽度
  242. var windowWidth = $(window).width();
  243. //console.log("初始窗口宽度: " + windowWidth);
  244. let wrapWidth = windowWidth > 640 ? '480px' : '86%';
  245. let wrapLeft = windowWidth > 640 ? '60px' : '7%';
  246. let showCenter = windowWidth > 640 ? 'left:50%;margin-left:-240px;' : '';
  247. //const style = document.createElement('style');
  248. //style.type = 'text/css';
  249. // style.innerHTML
  250. const CSS = `#strategyWrap {font-size:13px;color:#d5dceb;}
  251. #strategy-status {position:fixed;right: 0;top:136px;width:62px;height:30px;text-align:center;line-height:30px;background:#1475E1;color:#fff;font-size:12px;cursor:pointer;z-index:1000001;border-top-left-radius: 16px;
  252. border-bottom-left-radius: 16px;}
  253. #strategyWrap .get-balance-btn {padding: 0 5px;height: 30px;border-radius: 4px;background: #1475E1;color:#fff;font-size:0.7rem;cursor:no-drop;opacity:0.6;}
  254. #strategyWrap .import-btn {display:flex;align-items:center;justify-content: center;padding: 0 8px;height:26px;background:#996d0e;border-radius:4px;cursor:pointer;}
  255. #strategyWrap .export-btn {display:flex;align-items:center;justify-content: center;padding: 0 8px;height:26px;background:#158922;border-radius:4px;cursor:pointer;}
  256. #strategyWrap .strategy {background:#1a2c38;padding:5px;border:1px solid #2f4553;border-radius:5px;max-height:100px;overflow:auto;}
  257. #strategyWrap .strategy .strategy-item {display:inline-block;line-height:26px;padding:0 8px;height:26px;border:1px solid #2f4553;margin:5px;border-radius:5px;cursor:pointer;}
  258. .stra-item-active {background: #1f5b9f}
  259. #strategyWrap .error-message-wrap {background:#1a2c38;padding:10px;border:1px solid #2f4553;border-radius:5px;min-height:35px;max-height:60px;overflow:auto;margin-top:5px;}
  260. `;
  261. GM_addStyle(CSS);
  262. // 将样式元素添加到页面头部
  263. //document.head.appendChild(style);
  264. var html = `<div id="strategy-status">${i18n.showBotLabel}</div>
  265. <div id="strategyWrap" style="position:fixed;top:72px;left:${wrapLeft};z-index:1000000;background:rgba(0,0,0,.5);border-radius:5px;width:${wrapWidth};${showCenter}">
  266. <div style="padding:10px 8px;background:#213743;margin:0 auto;border-radius:5px;border:2px solid #2f4553;">
  267. <div style="display:flex;align-items:center;justify-content: space-between;">
  268. <div style="font-size:16px;font-weight:bold;color:#fff">${i18n.botName} <span class="version">v${version}</span></div>
  269. </div>
  270. <div class="export" style="margin:10px 0;">
  271. <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:5px;">
  272. <div style="margin-bottom:5px;font-size:14px;font-weight:bold;color:#fff;">${i18n.selectStra}</div>
  273. <div class="export-btn">${i18n.export}</div>
  274. </div>
  275. <div class="strategy"></div>
  276. </div>
  277. <div class="import" style="margin-top:10px;">
  278. <div style="display:flex;align-items:center;justify-content:space-between;">
  279. <div style="margin-bottom:5px;font-size:14px;font-weight:bold;color:#fff;">${i18n.selectFile}</div>
  280. <div class="import-btn">${i18n.import}</div>
  281. </div>
  282. <input type="file" id="json-input" accept=".json" />
  283. </div>
  284. <div class="editor" style="margin-top:8px;overflow:hidden;border-radius:5px;border:1px solid #2f4553;">
  285. <textarea></textarea>
  286. </div>
  287. <div class="error-message-wrap"></div>
  288. </div>
  289. </div>`
  290. $('body').append(html);
  291. $('#strategy-status').click(function(){
  292. $('#strategyWrap').toggle();
  293. })
  294. }
  295. })
  296. })();