Skip to content

Commit 4300df9

Browse files
authored
Merge branch 'master' into feat-lang
2 parents cde9a4a + e28f96e commit 4300df9

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@
5353
"mkdirp": "^1.0.4",
5454
"react-app-rewired": "^2.1.7"
5555
}
56-
}
56+
}

‎src/contentScript.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ int main()
340340
window.open(
341341
`https://pythontutor.com/visualize.html#code=${encodeURIComponent(
342342
code
343-
)}&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=${languageMap[language]
343+
)}&cumulative=false&curInstr=0&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=${
344+
languageMap[language]
344345
}&rawInputLstJSON=%5B%5D&textReferences=false`
345346
);
346347
}
@@ -360,9 +361,19 @@ function getCodeLanguage() {
360361

361362
}
362363
function insertButton() {
364+
const customBtnStyle = {
365+
"line-height": "1",
366+
cursor: "pointer",
367+
"vertical-align": "text-top",
368+
};
363369
const buttons = document.querySelectorAll("button");
370+
364371
for (var i = 0; i < buttons.length; ++i) {
365372
if (buttons[i].innerText.includes("运行")) {
373+
374+
// 停止观察器
375+
// observer.disconnect();
376+
366377
// const container = document.createElement("div");
367378

368379
// buttons[i].parentElement.prepend(container);
@@ -390,8 +401,8 @@ function insertButton() {
390401
// buttons[i].parentElement.prepend(copyButton);
391402
const writeSolutionButton = document.createElement("a");
392403
writeSolutionButton.innerText = "写题解";
393-
writeSolutionButton.style["margin-right"] = "20px";
394-
writeSolutionButton.style["line-height"] = "32px";
404+
Object.assign(writeSolutionButton.style, customBtnStyle);
405+
writeSolutionButton.className = buttons[i].className;
395406

396407
writeSolutionButton.onclick = () => {
397408
// d: "<a href="/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable/">1579. 保证图可完全遍历</a>"
@@ -474,17 +485,17 @@ function insertButton() {
474485

475486
// ReactDOM.render(<SolutionButton />, writeSolutionButton);
476487

477-
buttons[i].parentElement.prepend(writeSolutionButton);
488+
buttons[i].parentElement.parentElement.prepend(writeSolutionButton);
478489
// ele.appendChild(writeSolutionButton);
479490

480491
const visDebugButton = document.createElement("a");
481492
visDebugButton.innerText = "可视化调试";
482-
visDebugButton.style["margin-right"] = "20px";
483-
visDebugButton.style["line-height"] = "32px";
493+
Object.assign(visDebugButton.style, customBtnStyle);
494+
visDebugButton.className = buttons[i].className;
484495

485496
visDebugButton.onclick = goToVisDebug;
486497

487-
buttons[i].parentElement.prepend(visDebugButton);
498+
buttons[i].parentElement.parentElement.prepend(visDebugButton);
488499
inserted = true;
489500
} else if (buttons[i].innerText.includes("提交")) {
490501
const click = buttons[i].onclick;
@@ -500,18 +511,17 @@ function insertButton() {
500511
// 300 times means 30s
501512
if (tries > 300) return;
502513
tries++;
503-
}, 100)
504-
}
505-
514+
}, 100);
515+
};
506516

507-
submitProxied = true
517+
submitProxied = true;
508518
}
509519
}
510520
return false;
511521
}
512522
let inserted = false;
513523
let retried = 0;
514-
let submitProxied = false
524+
let submitProxied = false;
515525
const MAX_TRY = 10;
516526

517527
// 去除智能提示
@@ -521,13 +531,15 @@ const MAX_TRY = 10;
521531
// visibility: hidden !important;
522532
// }
523533
// `);
534+
524535
const timerId = setInterval(() => {
525536
if (inserted && submitProxied) return clearInterval(timerId);
526537
if (retried > MAX_TRY) {
527538
clearInterval(timerId);
528539
return console.error("初始化 chrome 插件 content script 失败");
529540
}
530541
insertButton();
542+
531543
// if (inserted && submitProxied) {
532544
// window.location.title = "";
533545
// // 可进入禅定模式
@@ -552,9 +564,6 @@ const timerId = setInterval(() => {
552564

553565
// ReactDOM.render(<Main />, app);
554566

555-
556-
557-
558567
// history.pushState = (f => function pushState() {
559568
// var ret = f.apply(this, arguments);
560569
// window.dispatchEvent(new Event('pushstate'));
@@ -579,4 +588,4 @@ const timerId = setInterval(() => {
579588
// if (url.endsWith("submissions/")) {
580589

581590
// }
582-
// })
591+
// })

0 commit comments

Comments
 (0)