feat: expose fudai region coordinates in gui
This commit is contained in:
1 parent
bcc4d1151f
commit
4797fa046e
17 files changed
+1044
-119
No files matched your search
@@ -62,10 +62,25 @@ function coerceValue(type, raw, isCheckbox) {
|
||||
}
|
||||
|
||||
function applyConfigToUI(cfg) {
|
||||
const seenIndexedKeys = new Set();
|
||||
for (const el of getConfigBoundElements()) {
|
||||
const key = el.dataset.key;
|
||||
const type = el.dataset.type || "str";
|
||||
const val = getConfigValue(cfg, key);
|
||||
const indexAttr = el.dataset.index;
|
||||
const hasIndex = typeof indexAttr !== "undefined";
|
||||
|
||||
if (hasIndex) {
|
||||
if (seenIndexedKeys.has(key)) continue;
|
||||
seenIndexedKeys.add(key);
|
||||
const grouped = document.querySelectorAll(`[data-key="${CSS.escape(key)}"][data-index]`);
|
||||
const useVal = Array.isArray(val) ? val : (Array.isArray(DEFAULTS[key]) ? DEFAULTS[key] : []);
|
||||
grouped.forEach((field) => {
|
||||
const idx = parseInt(field.dataset.index || "-1", 10);
|
||||
field.value = Number.isInteger(idx) && idx >= 0 ? String(useVal[idx] ?? 0) : "0";
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// undefined/null 都视为“未配置”:保留页面默认值
|
||||
const hasVal = !(typeof val === "undefined" || val === null);
|
||||
@@ -86,10 +101,18 @@ function applyConfigToUI(cfg) {
|
||||
|
||||
function collectConfigFromUI() {
|
||||
const out = {};
|
||||
const indexed = new Map();
|
||||
for (const el of getConfigBoundElements()) {
|
||||
const key = el.dataset.key;
|
||||
const type = el.dataset.type || "str";
|
||||
const indexAttr = el.dataset.index;
|
||||
if (!key) continue;
|
||||
if (typeof indexAttr !== "undefined") {
|
||||
const idx = parseInt(indexAttr, 10);
|
||||
if (!indexed.has(key)) indexed.set(key, [0, 0, 0, 0]);
|
||||
indexed.get(key)[idx] = coerceValue("int", el.value, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (el.type === "checkbox") {
|
||||
out[key] = coerceValue(type, el.checked, true);
|
||||
@@ -97,6 +120,7 @@ function collectConfigFromUI() {
|
||||
out[key] = coerceValue(type, el.value, false);
|
||||
}
|
||||
}
|
||||
for (const [key, value] of indexed.entries()) out[key] = value;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,78 @@
|
||||
(function mountConfigPanelTemplates() {
|
||||
const mount = document.getElementById("configPanelTemplatesMount");
|
||||
if (!mount) return;
|
||||
const regionFields = [
|
||||
{
|
||||
title: "legacy OCR",
|
||||
items: [
|
||||
["fudai_detail_regions.legacy.content", "内容"],
|
||||
["fudai_detail_regions.legacy.value", "价值"],
|
||||
["fudai_detail_regions.legacy.countdown_full", "倒计时"],
|
||||
["fudai_detail_regions.legacy.task_list", "任务列表"],
|
||||
["fudai_detail_regions.legacy.task_count", "任务数量"],
|
||||
["fudai_detail_regions.legacy.participants", "人数"],
|
||||
["fudai_detail_regions.legacy.button", "按钮"],
|
||||
["fudai_detail_regions.legacy.live_title", "直播间标题"],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "v2_0 two task OCR",
|
||||
items: [
|
||||
["fudai_detail_regions.v2_0_two_task.content", "内容"],
|
||||
["fudai_detail_regions.v2_0_two_task.value", "价值"],
|
||||
["fudai_detail_regions.v2_0_two_task.countdown_full", "倒计时"],
|
||||
["fudai_detail_regions.v2_0_two_task.task_list", "任务列表"],
|
||||
["fudai_detail_regions.v2_0_two_task.task_count", "任务数量"],
|
||||
["fudai_detail_regions.v2_0_two_task.participants", "人数"],
|
||||
["fudai_detail_regions.v2_0_two_task.button", "按钮"],
|
||||
["fudai_detail_regions.v2_0_two_task.live_title", "直播间标题"],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "v2_0 one task OCR",
|
||||
items: [
|
||||
["fudai_detail_regions.v2_0_one_task.content", "内容"],
|
||||
["fudai_detail_regions.v2_0_one_task.value", "价值"],
|
||||
["fudai_detail_regions.v2_0_one_task.countdown_full", "倒计时"],
|
||||
["fudai_detail_regions.v2_0_one_task.info_line", "信息行"],
|
||||
["fudai_detail_regions.v2_0_one_task.task_list", "任务列表"],
|
||||
["fudai_detail_regions.v2_0_one_task.task_count", "任务数量"],
|
||||
["fudai_detail_regions.v2_0_one_task.participants", "人数"],
|
||||
["fudai_detail_regions.v2_0_one_task.button", "按钮"],
|
||||
["fudai_detail_regions.v2_0_one_task.live_title", "直播间标题"],
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "像素检测区域",
|
||||
items: [
|
||||
["pixel_regions.lottery_result.button", "开奖按钮"],
|
||||
["pixel_regions.lottery_result.pixel", "开奖像素"],
|
||||
["pixel_regions.lottery_result.click", "开奖点击"],
|
||||
["pixel_regions.attend_button", "参与按钮"],
|
||||
["pixel_regions.fansclub_join", "粉丝团"],
|
||||
["pixel_regions.coupon_popup", "优惠券"],
|
||||
["pixel_regions.shopping_redpacket", "购物红包"],
|
||||
["pixel_regions.fudai_detail_body", "详情主体"],
|
||||
["pixel_regions.live_room_icon_bbox", "直播间图标bbox"],
|
||||
],
|
||||
},
|
||||
];
|
||||
const renderRegionInputs = (key, label) => {
|
||||
const safe = key.replace(/[^a-zA-Z0-9_]/g, "_");
|
||||
const axes = ["x1", "y1", "x2", "y2"];
|
||||
return `
|
||||
<div class="row grid4">
|
||||
<div><label class="label">${label} x1</label><input id="${safe}_x1" class="input" data-key="${key}" data-type="int" data-index="0" type="number" step="1" /></div>
|
||||
<div><label class="label">${label} y1</label><input id="${safe}_y1" class="input" data-key="${key}" data-type="int" data-index="1" type="number" step="1" /></div>
|
||||
<div><label class="label">${label} x2</label><input id="${safe}_x2" class="input" data-key="${key}" data-type="int" data-index="2" type="number" step="1" /></div>
|
||||
<div><label class="label">${label} y2</label><input id="${safe}_y2" class="input" data-key="${key}" data-type="int" data-index="3" type="number" step="1" /></div>
|
||||
</div>
|
||||
`;
|
||||
};
|
||||
const regionSectionsHtml = regionFields.map((section) => `
|
||||
<div class="sectionTitle">${section.title}</div>
|
||||
${section.items.map(([key, label]) => renderRegionInputs(key, label)).join("")}
|
||||
`).join("");
|
||||
mount.innerHTML = `
|
||||
<div class="panel" data-panel="keywords" role="tabpanel" hidden>
|
||||
<div class="sectionTitle">
|
||||
@@ -102,6 +174,8 @@
|
||||
<label class="check"><input id="fudai_detail_ocr_participants_enabled" type="checkbox" data-key="fudai_detail_ocr_participants_enabled" data-type="bool" /> <span>人数 OCR(默认关闭)</span></label>
|
||||
<label class="check"><input id="fudai_detail_ocr_live_title_enabled" type="checkbox" data-key="fudai_detail_ocr_live_title_enabled" data-type="bool" /> <span>直播间标题 OCR(默认关闭)</span></label>
|
||||
</div>
|
||||
<div class="sectionTitle">福袋坐标配置</div>
|
||||
${regionSectionsHtml}
|
||||
<div class="row">
|
||||
<label class="label">启用 OCR 模式1(备用)</label>
|
||||
<label class="check">
|
||||
|
||||
@@ -142,6 +142,40 @@ const DEFAULTS = {
|
||||
fudai_detail_ocr_button_enabled: true,
|
||||
fudai_detail_ocr_participants_enabled: false,
|
||||
fudai_detail_ocr_live_title_enabled: false,
|
||||
"fudai_detail_regions.legacy.content": [389, 1273, 1000, 1534],
|
||||
"fudai_detail_regions.legacy.value": [643, 1466, 769, 1656],
|
||||
"fudai_detail_regions.legacy.countdown_full": [390, 1110, 690, 1230],
|
||||
"fudai_detail_regions.legacy.task_list": [50, 1621, 1032, 1960],
|
||||
"fudai_detail_regions.legacy.task_count": [0, 0, 0, 0],
|
||||
"fudai_detail_regions.legacy.participants": [389, 1273, 1000, 1534],
|
||||
"fudai_detail_regions.legacy.button": [306, 2030, 780, 2180],
|
||||
"fudai_detail_regions.legacy.live_title": [130, 120, 560, 225],
|
||||
"fudai_detail_regions.v2_0_two_task.content": [360, 1410, 1035, 1495],
|
||||
"fudai_detail_regions.v2_0_two_task.value": [300, 1585, 650, 1685],
|
||||
"fudai_detail_regions.v2_0_two_task.countdown_full": [760, 1328, 1038, 1398],
|
||||
"fudai_detail_regions.v2_0_two_task.task_list": [60, 1840, 1030, 2005],
|
||||
"fudai_detail_regions.v2_0_two_task.task_count": [860, 1770, 1035, 1875],
|
||||
"fudai_detail_regions.v2_0_two_task.participants": [520, 1325, 760, 1415],
|
||||
"fudai_detail_regions.v2_0_two_task.button": [70, 2020, 1010, 2165],
|
||||
"fudai_detail_regions.v2_0_two_task.live_title": [130, 120, 560, 225],
|
||||
"fudai_detail_regions.v2_0_one_task.content": [360, 1460, 1035, 1545],
|
||||
"fudai_detail_regions.v2_0_one_task.value": [350, 1640, 760, 1735],
|
||||
"fudai_detail_regions.v2_0_one_task.countdown_full": [730, 1338, 1038, 1418],
|
||||
"fudai_detail_regions.v2_0_one_task.info_line": [430, 1315, 1055, 1435],
|
||||
"fudai_detail_regions.v2_0_one_task.task_list": [60, 1845, 885, 2005],
|
||||
"fudai_detail_regions.v2_0_one_task.task_count": [890, 1855, 1040, 1960],
|
||||
"fudai_detail_regions.v2_0_one_task.participants": [516, 1396, 743, 1443],
|
||||
"fudai_detail_regions.v2_0_one_task.button": [70, 2050, 1010, 2195],
|
||||
"fudai_detail_regions.v2_0_one_task.live_title": [130, 120, 560, 225],
|
||||
"pixel_regions.lottery_result.button": [250, 1275, 825, 1435],
|
||||
"pixel_regions.lottery_result.pixel": [290, 1300, 790, 1415],
|
||||
"pixel_regions.lottery_result.click": [540, 1360, 0, 0],
|
||||
"pixel_regions.attend_button": [200, 2000, 880, 2120],
|
||||
"pixel_regions.fansclub_join": [200, 1940, 880, 2140],
|
||||
"pixel_regions.coupon_popup": [9, 1173, 1079, 2255],
|
||||
"pixel_regions.shopping_redpacket": [200, 300, 880, 1400],
|
||||
"pixel_regions.fudai_detail_body": [0, 1160, 1080, 2250],
|
||||
"pixel_regions.live_room_icon_bbox": [999, 172, 1028, 202],
|
||||
pixel_detect_fudai_icon_enabled: true,
|
||||
pixel_detect_coupon_popup_enabled: true,
|
||||
pixel_detect_shopping_redpacket_enabled: false,
|
||||
|
||||
Reference in new issue
Block a user