海底掘金

这是一个针对 海底掘金活动 编写的油猴脚本,实现了用户信息的自动获取和掘进方式的高效的选择。

  1. /* eslint-disable */
  2. // ==UserScript==
  3. // @name 海底掘金
  4. // @namespace https://github.com/palmcivet/juejin-miming
  5. // @version 0.0.4
  6. // @license MIT
  7. // @description 这是一个针对 海底掘金活动 编写的油猴脚本,实现了用户信息的自动获取和掘进方式的高效的选择。
  8. // @author Palm Civet
  9. // @match https://juejin.cn/game/haidijuejin/*
  10. // @require https://unpkg.com/alpinejs@3.8/dist/cdn.min.js
  11. // @grant none
  12. // ==/UserScript==
  13. var __defProp = Object.defineProperty;
  14. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  15. var __hasOwnProp = Object.prototype.hasOwnProperty;
  16. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  17. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  18. var __spreadValues = (a, b) => {
  19. for (var prop in b || (b = {}))
  20. if (__hasOwnProp.call(b, prop))
  21. __defNormalProp(a, prop, b[prop]);
  22. if (__getOwnPropSymbols)
  23. for (var prop of __getOwnPropSymbols(b)) {
  24. if (__propIsEnum.call(b, prop))
  25. __defNormalProp(a, prop, b[prop]);
  26. }
  27. return a;
  28. };
  29. (function() {
  30. const CLASS_NAME = "juejin-miming";
  31. const API_USER = "https://api.juejin.cn/user_api/v1/user/get";
  32. const API_GAME_BASE = "https://juejin-game.bytedance.com/game/sea-gold";
  33. const API_GAME_COMMAND = `${API_GAME_BASE}/game/command`;
  34. async function getUserInfo() {
  35. try {
  36. const result = await fetch(API_USER, {
  37. credentials: "include"
  38. });
  39. const data = await result.json();
  40. return data.data;
  41. } catch (error) {
  42. throw error;
  43. }
  44. }
  45. async function gameCommand({ uid = "", authorization = "", gameId = "", commandStep = 0 }) {
  46. const commandArr = [
  47. [{ times: 2, command: ["2", "L", "D", "L", "4", "D", "6", "R", "D", "R"] }],
  48. [{ times: 2, command: ["2", "R", "D", "R", "6", "D", "4", "L", "D", "L"] }],
  49. [
  50. {
  51. times: 10,
  52. command: [
  53. {
  54. times: 2,
  55. command: ["D", "2", "L", "D", "L", "4", "D", "6", "U", "L", "D", "R"]
  56. },
  57. "L",
  58. "D"
  59. ]
  60. },
  61. { times: 2, command: ["U", "U", "8", "R"] },
  62. {
  63. times: 10,
  64. command: [
  65. {
  66. times: 2,
  67. command: ["D", "2", "R", "D", "R", "6", "D", "4", "U", "R", "D", "L"]
  68. },
  69. "R",
  70. "D"
  71. ]
  72. },
  73. { times: 2, command: ["U", "U", "8", "L"] }
  74. ],
  75. [
  76. {
  77. times: 10,
  78. command: [
  79. {
  80. times: 2,
  81. command: ["D", "2", "L", "D", "L", "4", "D", "6", "U", "L", "D", "R"]
  82. },
  83. "L",
  84. "D"
  85. ]
  86. },
  87. { times: 2, command: ["U", "U", "8", "R"] },
  88. {
  89. times: 10,
  90. command: [
  91. {
  92. times: 2,
  93. command: ["D", "2", "R", "D", "R", "6", "D", "4", "U", "R", "D", "L"]
  94. },
  95. "R",
  96. "D"
  97. ]
  98. },
  99. { times: 2, command: ["U", "U", "8", "L"] }
  100. ],
  101. [
  102. {
  103. times: 10,
  104. command: [
  105. "L",
  106. "L",
  107. "L",
  108. "4",
  109. "L",
  110. "L",
  111. "L",
  112. "4",
  113. "D",
  114. "R",
  115. "R",
  116. "R",
  117. "6",
  118. "R",
  119. "R",
  120. "R",
  121. "6"
  122. ]
  123. },
  124. { times: 3, command: ["U", "U", "L", "L", "8", "4"] },
  125. {
  126. times: 6,
  127. command: ["D", "2", "L", "D", "L", "4", "D", "6", "U", "L", "D", "R"]
  128. },
  129. "L",
  130. "D",
  131. {
  132. times: 10,
  133. command: [
  134. "R",
  135. "R",
  136. "R",
  137. "6",
  138. "R",
  139. "R",
  140. "R",
  141. "6",
  142. "D",
  143. "L",
  144. "L",
  145. "L",
  146. "4",
  147. "L",
  148. "L",
  149. "L",
  150. "4"
  151. ]
  152. },
  153. { times: 3, command: ["U", "U", "R", "R", "8", "6"] },
  154. {
  155. times: 6,
  156. command: ["D", "2", "R", "D", "R", "6", "D", "4", "U", "R", "D", "L"]
  157. },
  158. "R",
  159. "D"
  160. ]
  161. ];
  162. const coreCode = commandArr[commandStep];
  163. const loop = commandStep <= 1 ? 2 : 4;
  164. const params = { command: [] };
  165. let _params = params;
  166. for (let i = 0; i < loop; i++) {
  167. _params["command"].push({ times: 10, command: [] });
  168. _params = _params.command[0];
  169. if (i >= loop - 1) {
  170. _params.command.push(...coreCode);
  171. }
  172. }
  173. _params = null;
  174. const datarus = await fetch(`${API_GAME_COMMAND}?uid=${uid}&time=${Date.parse(new Date().toString())}`, {
  175. method: "POST",
  176. credentials: "include",
  177. headers: {
  178. "Content-type": "application/json; charset=UTF-8",
  179. "authorization": authorization,
  180. "accept": "application/json, text/plain, */*",
  181. "content-length": JSON.stringify(params).length.toString(),
  182. "x-tt-gameid": gameId
  183. },
  184. body: JSON.stringify(params)
  185. });
  186. return datarus.json();
  187. }
  188. function injectStyle() {
  189. const styleDOM = document.createElement("style");
  190. styleDOM.id = `${CLASS_NAME}-style`;
  191. styleDOM.innerHTML = `:root {
  192. --radius: 6px;
  193. --padding: 10px;
  194. --primary-color: #3c7eff;
  195. }
  196.  
  197. .juejin-miming-controls {
  198. background-color: #3c7eff;
  199. border: 2px solid #bedaff;
  200. border-radius: var(--radius);
  201. position: absolute;
  202. right: 10px;
  203. top: 10px;
  204. width: 200px;
  205. padding: var(--padding);
  206. display: flex;
  207. flex-direction: column;
  208. align-items: center;
  209. color: white;
  210. }
  211.  
  212. .juejin-miming-controls h2 {
  213. margin: var(--padding) 0;
  214. }
  215.  
  216. .juejin-miming-controls a {
  217. color: white;
  218. }
  219.  
  220. .juejin-miming-info input[type="text"] {
  221. font-family: monospace, "Courier New", Courier;
  222. width: 100%;
  223. font-size: 15px;
  224. height: 28px;
  225. border: 0;
  226. outline: 0;
  227. overflow-x: hidden;
  228. white-space: nowrap;
  229. text-overflow: ellipsis;
  230. box-sizing: border-box;
  231. border-radius: calc(var(--radius) / 2);
  232. margin: 2px 0;
  233. padding: 0 4px;
  234. }
  235.  
  236. .juejin-miming-cmd {
  237. margin: var(--padding) 0;
  238. display: flex;
  239. flex-direction: column;
  240. width: 100%;
  241. }
  242.  
  243. .juejin-miming-cmd label {
  244. list-style: none;
  245. width: 100%;
  246. text-align: left;
  247. cursor: pointer;
  248. display: inline-flex;
  249. align-items: center;
  250. font-family: monospace, "Courier New", Courier;
  251. }
  252.  
  253. .juejin-miming-cmd input[type="radio"] {
  254. cursor: pointer;
  255. padding: 0;
  256. width: 17px;
  257. height: 17px;
  258. margin: 0 5px 0 5px;
  259. }
  260.  
  261. .juejin-miming-btn {
  262. color: #1d4dd2;
  263. background-color: white;
  264. border: 2px solid #1d4dd2;
  265. width: 70px;
  266. height: 30px;
  267. cursor: pointer;
  268. border-radius: calc(var(--radius) / 2);
  269. }
  270.  
  271. .juejin-miming-btn:hover {
  272. color: white;
  273. background-color: #1d4dd2;
  274. border: 2px solid white;
  275. }
  276.  
  277. .juejin-miming-msg {
  278. margin-top: var(--padding);
  279. height: 24px;
  280. }
  281. `;
  282. document.head.append(styleDOM);
  283. }
  284. function injectControls() {
  285. const root = document.querySelector("#Cocos2dGameContainer");
  286. const container = document.createElement("div");
  287. container.className = `${CLASS_NAME}-script`;
  288. container.innerHTML = `<div class="juejin-miming-controls" x-data>
  289. <div class="juejin-miming-project">
  290. <h2>
  291. <a href="//github.com/palmcivet/juejin-miming" target="_blank" title="GitHub">\u6398\u91D1\u6316\u77FF</a>
  292. </h2>
  293. </div>
  294.  
  295. <div class="juejin-miming-info">
  296. <input type="text" x-model="$store.controls.form.uid" placeholder="uid" />
  297. <input type="text" x-model="$store.controls.form.authorization" placeholder="authorization" />
  298. <input type="text" x-model="$store.controls.form.gameId" placeholder="x-tt-gameid" />
  299. </div>
  300.  
  301. <div class="juejin-miming-cmd">
  302. <label>
  303. <input type="radio" value="0" name="commandStep" @change="$store.controls.onChange(0)" />
  304. 0\uFF1A\u5F00\u5C40\u5F80\u5DE6
  305. </label>
  306.  
  307. <label>
  308. <input type="radio" value="1" name="commandStep" @change="$store.controls.onChange(1)" />
  309. 1\uFF1A\u5F00\u5C40\u5F80\u53F3
  310. </label>
  311.  
  312. <label>
  313. <input type="radio" value="2" name="commandStep" @change="$store.controls.onChange(2)" />
  314. 2\uFF1A\u4E2D\u671F
  315. </label>
  316.  
  317. <label>
  318. <input type="radio" value="3" name="commandStep" @change="$store.controls.onChange(3)" />
  319. 3\uFF1A\u540E\u671F\u98DE\u7FD4
  320. </label>
  321.  
  322. <label>
  323. <input type="radio" value="4" name="commandStep" @change="$store.controls.onChange(4)" />
  324. 4\uFF1A\u540E\u671F\u626B\u8361
  325. </label>
  326. </div>
  327.  
  328. <button class="juejin-miming-btn" @click="$store.controls.onSubmit()">\u6267\u884C</button>
  329.  
  330. <div class="juejin-miming-msg" x-text="$store.controls.message"></div>
  331. </div>
  332. `;
  333. root.appendChild(container);
  334. }
  335. (function(context) {
  336. context.rewriteXHR = {
  337. cachedProto: function() {
  338. this._originXhr = context.XMLHttpRequest.prototype;
  339. this._originOpen = this._originXhr.open;
  340. this._originSend = this._originXhr.send;
  341. this._originSetRequestHeader = this._originXhr.setRequestHeader;
  342. },
  343. overWrite: function() {
  344. const _this = this;
  345. this._originXhr.open = function() {
  346. this.open_args = [...arguments];
  347. return _this._originOpen.apply(this, arguments);
  348. };
  349. this._originXhr.send = function() {
  350. return _this._originSend.apply(this, arguments);
  351. };
  352. this._originXhr.setRequestHeader = function() {
  353. const url = this.open_args && this.open_args[1];
  354. if (url.startsWith(API_GAME_BASE)) {
  355. const headerKey = arguments[0];
  356. if (/^x-tt-gameid$/.test(headerKey)) {
  357. localStorage.setItem(`${CLASS_NAME}-gameid`, arguments[1]);
  358. Alpine.store("controls").form.gameId = localStorage.getItem(`${CLASS_NAME}-gameid`);
  359. }
  360. if (/^Authorization$/.test(headerKey)) {
  361. localStorage.setItem(`${CLASS_NAME}-authid`, arguments[1]);
  362. Alpine.store("controls").form.authorization = localStorage.getItem(`${CLASS_NAME}-authid`);
  363. }
  364. }
  365. return _this._originSetRequestHeader.apply(this, arguments);
  366. };
  367. },
  368. init: function() {
  369. this.cachedProto();
  370. this.overWrite();
  371. }
  372. };
  373. context.rewriteXHR.init();
  374. })(window);
  375. document.addEventListener("alpine:init", () => {
  376. Alpine.store("controls", {
  377. form: {
  378. uid: "",
  379. gameId: "",
  380. authorization: "",
  381. commandStep: "0"
  382. },
  383. message: "",
  384. onChange(value) {
  385. Alpine.store("controls").form.commandStep = value;
  386. },
  387. async onSubmit() {
  388. Alpine.store("controls").message = "";
  389. const result = await gameCommand(__spreadValues({}, Alpine.store("controls").form));
  390. const { message } = result;
  391. Alpine.store("controls").message = message;
  392. }
  393. });
  394. console.info("== Juejin miming: inject ==");
  395. });
  396. const _onload = window.onload || function() {
  397. };
  398. window.onload = async (event) => {
  399. _onload(event);
  400. setTimeout(injectStyle);
  401. setTimeout(injectControls, 8e3);
  402. const { user_id } = await getUserInfo();
  403. Alpine.store("controls").form.uid = user_id;
  404. Alpine.store("controls").form.gameId = localStorage.getItem(`${CLASS_NAME}-gameid`);
  405. Alpine.store("controls").form.authorization = localStorage.getItem(`${CLASS_NAME}-authid`);
  406. console.log("== Juejin miming: enjoy ==");
  407. };
  408. })();

QingJ © 2025

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