Skip to content

Commit c9bd5a8

Browse files
author
lucifer
committed
fix: #7
1 parent b58250b commit c9bd5a8

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

‎src/contentScript.js

+46-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// import "./content.css";
22
// import { message } from "antd";
3+
// import React from "react";
4+
// import ReactDOM from "react-dom";
5+
// import { Menu, Dropdown, Button } from "antd";
6+
// import { DownOutlined, UserOutlined } from "@ant-design/icons";
37
import { copyToClipboard, bjwd, getStorage, setCloundStorage } from "./utils";
48
import zenAble from "./zen/zenMode";
59

@@ -73,7 +77,7 @@ const message = {
7377
// } else
7478

7579
// testcase eg: `bottom = "BCD", allowed = ["BCG", "CDE", "GEA", "FFF"], c = [1,2,3], d = 2`
76-
function normalize(testCase) {
80+
function normalize(testCase, includeArray = true) {
7781
testCase = testCase.trim().replace(/\n/g, "").replace(" ", "");
7882

7983
// 单一参数
@@ -109,7 +113,8 @@ function normalize(testCase) {
109113
// skip ,
110114
i += 1;
111115
stack.push("\n");
112-
} else {
116+
} else if (includeArray) {
117+
// 解析为数组
113118
// cnt 左括号[ 与 右括号] 个数的差值
114119
let cnt = 0;
115120
while (i < testCase.length) {
@@ -125,8 +130,17 @@ function normalize(testCase) {
125130
break;
126131
}
127132
}
133+
} else {
134+
while (i < testCase.length) {
135+
stack.push(testCase[i]);
136+
i += 1;
137+
}
128138
}
129139
}
140+
const ans = stack.join("");
141+
if (includeArray && ans[ans.length - 1] !== testCase[testCase.length - 1]) {
142+
return normalize(testCase, false);
143+
}
130144
return stack.join("");
131145
}
132146

@@ -149,7 +163,7 @@ function extractTestCase(text, prefix) {
149163
return [];
150164
}
151165

152-
function getProviedTestCases() {
166+
function getProviedTestCases(includeArray = true) {
153167
const possibleTags = ["pre", "p"];
154168
const possiblePrefixs = ["输入:", "输入:", "Input:", "input:"];
155169
const ans = [];
@@ -164,19 +178,47 @@ function getProviedTestCases() {
164178
bjwd();
165179
return [];
166180
}
167-
ans.push(normalize(testcase[1]));
181+
ans.push(normalize(testcase[1], includeArray));
168182
}
169183
}
170184
if (ans.length > 0) return ans;
171185
}
172186
}
173187
return ans;
174188
}
189+
// const menu = (
190+
// <Menu onClick={() => handleTestCaseClick(false)}>
191+
// <Menu.Item key="1" icon={<UserOutlined />}>
192+
// 测试用例不包含数组选这个
193+
// </Menu.Item>
194+
// </Menu>
195+
// );
175196

197+
// function handleTestCaseClick(includeArray) {
198+
// const cases = getProviedTestCases(includeArray);
199+
// if (cases.filter(Boolean).length === 0) return bjwd();
200+
// copyToClipboard(cases.join("\n"));
201+
// message.success({
202+
// content: "复制成功~",
203+
// });
204+
// }
176205
function insertButton() {
177206
const buttons = document.querySelectorAll("button");
178207
for (var i = 0; i < buttons.length; ++i) {
179208
if (buttons[i].innerText.includes("执行代码")) {
209+
// const container = document.createElement("div");
210+
211+
// buttons[i].parentElement.prepend(container);
212+
// ReactDOM.render(
213+
// <Dropdown overlay={menu} style={{ marginLeft: "10px" }}>
214+
// <Button onClick={() => handleTestCaseClick(true)}>
215+
// 复制所有内置用例 <DownOutlined />
216+
// </Button>
217+
// </Dropdown>,
218+
// container
219+
// );
220+
221+
// const writeSolutionButton = document.createElement("div");
180222
const copyButton = buttons[i].cloneNode(true);
181223
copyButton.innerText = "复制所有内置用例";
182224
copyButton.style["margin-left"] = "10px";
@@ -189,8 +231,6 @@ function insertButton() {
189231
});
190232
};
191233
buttons[i].parentElement.prepend(copyButton);
192-
193-
// const writeSolutionButton = document.createElement("div");
194234
const writeSolutionButton = document.createElement("a");
195235
writeSolutionButton.innerText = "去写题解";
196236
writeSolutionButton.style["margin-right"] = "20px";

0 commit comments

Comments
 (0)