1
1
// import "./content.css";
2
2
// 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";
3
7
import { copyToClipboard , bjwd , getStorage , setCloundStorage } from "./utils" ;
4
8
import zenAble from "./zen/zenMode" ;
5
9
@@ -73,7 +77,7 @@ const message = {
73
77
// } else
74
78
75
79
// 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 ) {
77
81
testCase = testCase . trim ( ) . replace ( / \n / g, "" ) . replace ( " " , "" ) ;
78
82
79
83
// 单一参数
@@ -109,7 +113,8 @@ function normalize(testCase) {
109
113
// skip ,
110
114
i += 1 ;
111
115
stack . push ( "\n" ) ;
112
- } else {
116
+ } else if ( includeArray ) {
117
+ // 解析为数组
113
118
// cnt 左括号[ 与 右括号] 个数的差值
114
119
let cnt = 0 ;
115
120
while ( i < testCase . length ) {
@@ -125,8 +130,17 @@ function normalize(testCase) {
125
130
break ;
126
131
}
127
132
}
133
+ } else {
134
+ while ( i < testCase . length ) {
135
+ stack . push ( testCase [ i ] ) ;
136
+ i += 1 ;
137
+ }
128
138
}
129
139
}
140
+ const ans = stack . join ( "" ) ;
141
+ if ( includeArray && ans [ ans . length - 1 ] !== testCase [ testCase . length - 1 ] ) {
142
+ return normalize ( testCase , false ) ;
143
+ }
130
144
return stack . join ( "" ) ;
131
145
}
132
146
@@ -149,7 +163,7 @@ function extractTestCase(text, prefix) {
149
163
return [ ] ;
150
164
}
151
165
152
- function getProviedTestCases ( ) {
166
+ function getProviedTestCases ( includeArray = true ) {
153
167
const possibleTags = [ "pre" , "p" ] ;
154
168
const possiblePrefixs = [ "输入:" , "输入:" , "Input:" , "input:" ] ;
155
169
const ans = [ ] ;
@@ -164,19 +178,47 @@ function getProviedTestCases() {
164
178
bjwd ( ) ;
165
179
return [ ] ;
166
180
}
167
- ans . push ( normalize ( testcase [ 1 ] ) ) ;
181
+ ans . push ( normalize ( testcase [ 1 ] , includeArray ) ) ;
168
182
}
169
183
}
170
184
if ( ans . length > 0 ) return ans ;
171
185
}
172
186
}
173
187
return ans ;
174
188
}
189
+ // const menu = (
190
+ // <Menu onClick={() => handleTestCaseClick(false)}>
191
+ // <Menu.Item key="1" icon={<UserOutlined />}>
192
+ // 测试用例不包含数组选这个
193
+ // </Menu.Item>
194
+ // </Menu>
195
+ // );
175
196
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
+ // }
176
205
function insertButton ( ) {
177
206
const buttons = document . querySelectorAll ( "button" ) ;
178
207
for ( var i = 0 ; i < buttons . length ; ++ i ) {
179
208
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");
180
222
const copyButton = buttons [ i ] . cloneNode ( true ) ;
181
223
copyButton . innerText = "复制所有内置用例" ;
182
224
copyButton . style [ "margin-left" ] = "10px" ;
@@ -189,8 +231,6 @@ function insertButton() {
189
231
} ) ;
190
232
} ;
191
233
buttons [ i ] . parentElement . prepend ( copyButton ) ;
192
-
193
- // const writeSolutionButton = document.createElement("div");
194
234
const writeSolutionButton = document . createElement ( "a" ) ;
195
235
writeSolutionButton . innerText = "去写题解" ;
196
236
writeSolutionButton . style [ "margin-right" ] = "20px" ;
0 commit comments