云库可选: 服务支持 cloud 请求参数, 油猴面板加'使用云库'开关(v1.5.0)
This commit is contained in:
1 parent
77b73554b1
commit
d3c667a61c
2 files changed
+30
-14
No files matched your search
+16
-3
@@ -2,7 +2,7 @@
|
||||
// @name Xiangqi.com 本地皮卡鱼引擎对接
|
||||
// @name:en Xiangqi.com Local Pikafish Engine
|
||||
// @namespace awesome-xiangqi
|
||||
// @version 1.4.1
|
||||
// @version 1.5.0
|
||||
// @description 在 play.xiangqi.com 对局中调用本地皮卡鱼引擎(http://127.0.0.1:9377)自动/手动走子
|
||||
// @description:en Hook the site WebSocket and let a local Pikafish engine play for you
|
||||
// @match https://play.xiangqi.com/*
|
||||
@@ -16,7 +16,7 @@
|
||||
const ENGINE_URL = "http://127.0.0.1:9377";
|
||||
const NS = "42/xiangqi,";
|
||||
const FIRST_MOVE_EXTRA_SEC = 5;
|
||||
const VERSION = "1.4.1";
|
||||
const VERSION = "1.5.0";
|
||||
const PATCH_MARK = Symbol.for("xiangqi.pikafish.ws.patched");
|
||||
const uW = typeof unsafeWindow !== "undefined" ? unsafeWindow : window;
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
|
||||
const cfg = {
|
||||
enabled: storage.get("pf_enabled", "0") === "1",
|
||||
useCloud: storage.get("pf_usecloud", "1") === "1",
|
||||
movetime: Math.max(50, +storage.get("pf_movetime", 800) || 800),
|
||||
depth: Math.max(0, +storage.get("pf_depth", 0) || 0),
|
||||
firstDelay: Math.max(0, +storage.get("pf_firstdelay", 0) || 0),
|
||||
@@ -60,6 +61,7 @@
|
||||
|
||||
function saveCfg() {
|
||||
storage.set("pf_enabled", cfg.enabled ? "1" : "0");
|
||||
storage.set("pf_usecloud", cfg.useCloud ? "1" : "0");
|
||||
storage.set("pf_movetime", cfg.movetime);
|
||||
storage.set("pf_depth", cfg.depth);
|
||||
storage.set("pf_firstdelay", cfg.firstDelay);
|
||||
@@ -195,7 +197,7 @@
|
||||
|
||||
let liveWS = null;
|
||||
|
||||
async function engineBestmove({ moves, fen, movetime, depth, signal }) {
|
||||
async function engineBestmove({ moves, fen, movetime, depth, useCloud, signal }) {
|
||||
const timeoutMs = Math.max(15000, movetime * 4 + 2000);
|
||||
const ctrl = new AbortController();
|
||||
const timer = setTimeout(
|
||||
@@ -216,6 +218,7 @@
|
||||
fen: fen || undefined,
|
||||
movetime,
|
||||
depth: depth > 0 ? depth : undefined,
|
||||
cloud: useCloud !== false,
|
||||
}),
|
||||
signal: ctrl.signal,
|
||||
});
|
||||
@@ -296,6 +299,7 @@
|
||||
fen: G.fen,
|
||||
movetime: cfg.movetime,
|
||||
depth: cfg.depth,
|
||||
useCloud: cfg.useCloud,
|
||||
});
|
||||
if (reqId !== G.reqId) return;
|
||||
if (G.over) throw new Error("对局已结束");
|
||||
@@ -494,6 +498,7 @@
|
||||
<div class="title"><span>🐴 皮卡鱼</span><span class="dot" id="pf-dot" style="background:#666"></span></div>
|
||||
<div class="row"><label><input type="checkbox" id="pf-enabled"> 自动走子</label>
|
||||
<span id="pf-side-hint"></span></div>
|
||||
<div class="row"><label><input type="checkbox" id="pf-cloud"> 使用云库</label></div>
|
||||
<div class="row"><span>每步用时(ms)</span><input type="number" id="pf-mt" min="50" step="50"></div>
|
||||
<div class="row"><span>深度(0=用时间)</span><input type="number" id="pf-depth" min="0" max="40" step="1"></div>
|
||||
<div class="row"><span>首步延迟(秒+5)</span><input type="number" id="pf-delay" min="0" max="120" step="1"></div>
|
||||
@@ -519,6 +524,14 @@
|
||||
if (cfg.enabled) scheduleTurn(0);
|
||||
});
|
||||
|
||||
const cloudCb = panel.querySelector("#pf-cloud");
|
||||
cloudCb.checked = cfg.useCloud;
|
||||
cloudCb.addEventListener("change", () => {
|
||||
cfg.useCloud = cloudCb.checked;
|
||||
saveCfg();
|
||||
if (cfg.enabled) scheduleTurn(0);
|
||||
});
|
||||
|
||||
const mt = panel.querySelector("#pf-mt");
|
||||
mt.value = cfg.movetime;
|
||||
mt.addEventListener("change", () => {
|
||||
|
||||
Reference in new issue
Block a user