Skip to content

Commit

Permalink
feat: 更新题目
Browse files Browse the repository at this point in the history
  • Loading branch information
robot committed Dec 10, 2024
1 parent efb5ed9 commit 028be9e
Show file tree
Hide file tree
Showing 6 changed files with 2,228 additions and 8,481 deletions.
Binary file modified leetcode-cheat.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "leetcode cheatsheet",
"description": "刷题小助手,made by 力扣加加",
"version": "0.12.0",
"version": "0.12.1",
"action": {
"default_popup": "index.html",
"default_title": "力扣加加"
Expand Down
37 changes: 26 additions & 11 deletions src/contentScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ function insertButton() {

for (var i = 0; i < buttons.length; ++i) {
if (buttons[i].innerText.includes(t("Locale.app.run"))) {

// const container = document.createElement("div");

// buttons[i].parentElement.prepend(container);
Expand Down Expand Up @@ -404,17 +404,19 @@ function insertButton() {
writeSolutionButton.className = buttons[i].className;

writeSolutionButton.onclick = () => {
console.log("writeSolutionButton");
// d: "<a href="/problems/remove-max-number-of-edges-to-keep-graph-fully-traversable/">1579. 保证图可完全遍历</a>"

const desc = document.querySelector(
"[data-track-load=\"description_content\"]"
'[data-track-load="description_content"]'
).innerHTML;

if (!desc) {
return message.warn({
content: t("app.getProblemError"),
});
}

const title = document.title;
const link = window.location.href;
const language = getCodeLanguage();
Expand All @@ -426,6 +428,8 @@ function insertButton() {
// const desc = document.querySelector("#question-detail-main-tabs")?.children[1]?.children[0]?.children[1]?.innerText;

const hide = message.loading(t("app.savingProblem"), 0);

console.log("writeSolutionButton", title, link, language, code, desc);
writeSolutionButton.setAttribute("disabled", true);
// Dismiss manually and asynchronously
setTimeout(() => {
Expand All @@ -442,7 +446,8 @@ function insertButton() {
raw: "e574bf60b50d8d2d2db2320ee83aba3cd29cecf2",
}))
.then((res) => {
const t = res.raw;
const token = res.raw;
console.log("getStorage", token);
setCloundStorage(
{
title,
Expand All @@ -453,10 +458,11 @@ function insertButton() {
},

{
token: t,
token: token,
}
)
.then((res) => {
console.log("setCloundStorage", res);
hide();
writeSolutionButton.removeAttribute("disabled");
if (res.id) {
Expand All @@ -468,15 +474,24 @@ function insertButton() {
content: t("app.githubAPIError"),
});
setTimeout(() => {
window.open(
`https://leetcode-pp.github.io/leetcode-cheat/?title=${title}&link=${link}&language=${language}&tab=solution-template`
);
}, 2000);
const url = `https://leetcode-pp.github.io/leetcode-cheat/?title=${title}&link=${link}&language=${language}&tab=solution-template`;
console.log("window.open", url);
window.open(url);
}, 1000);
}
})
.catch(() => {
console.log("setCloundStorage", "catch");
hide();
writeSolutionButton.removeAttribute("disabled");
message.warn({
content: t("app.githubAPIError"),
});
setTimeout(() => {
window.open(
`https://leetcode-pp.github.io/leetcode-cheat/?title=${title}&link=${link}&language=${language}&tab=solution-template`
);
}, 1000);
});
});
};
Expand All @@ -501,7 +516,7 @@ function insertButton() {
inserted = true;
} else if (buttons[i].innerText.includes(t("app.submit"))) {
const click = buttons[i].onclick;
const originalFn = buttons[i]
const originalFn = buttons[i];
buttons[i].onclick = (...args) => {
click.call(originalFn, ...args);

Expand Down Expand Up @@ -543,8 +558,8 @@ const timerId = setInterval(() => {
}

// 防止 insertButton 在本插件应用中执行,会匹配到题目中包含 "Run" 的情况,例如:“1480. Running Sum of 1d Array”
if (document.title.includes("力扣加加")) return
if (document.title.includes("力扣加加")) return;

insertButton();

// if (inserted && submitProxied) {
Expand Down
Loading

0 comments on commit 028be9e

Please sign in to comment.