`;
};
let lists = "";
for (let i in local) lists += getList(i);
return lists;
};
let loaderTrainEntry = async () => {
let lists = loadTrainList();
$("#problem-helper-entry").html(lists);
$(".problem-helper-fold-on").click((u) => {
u = $(u.target);
u.parent().prev(".problem-helper-inner").removeAttr("style");
u.attr("style", "display:none;");
u.prev(".problem-helper-fold-off").removeAttr("style");
});
$(".problem-helper-fold-off").click((u) => {
u = $(u.target);
u.parent().prev(".problem-helper-inner").attr("style", "display:none;");
u.attr("style", "display:none;");
u.next(".problem-helper-fold-on").removeAttr("style");
});
$("#problem-helper-add-to-list").click((u) => {
let r = unsafeWindow.location.href.split("/");
r = r[r.length - 1].split("#")[0];
if (!unsafeWindow._feInjection.currentData.training.title) return;
let now = configs.train;
if (!now) now = {};
now[r] = unsafeWindow._feInjection.currentData.training.title;
configs.train = now;
unsafeWindow._feInstance.$swalToastSuccess("添加成功");
loaderTrainEntry();
});
$(".problem-helper-delete-from-list").click((u) => {
u = $(u.target).parents(".problem-helper-delete-from-list");
let r = u.attr("data");
let now = configs.train;
let newone = {};
for (let i in now) if (i != r) newone[i] = now[i];
configs.train = newone;
unsafeWindow._feInstance.$swalToastSuccess("删除成功");
loaderProblemEntry();
});
};
let deferredInjectTrainPage = () => {
$("#problem-helper-container").remove();
$(".side").prepend(
renderList(
"做题助手",
'',
'添加至列表'
)
);
loaderTrainEntry();
};
let deferredInjectProblemlist = async () => {
local_problems = (await getTask(configs.local)).problems.map(
(u) => u.problem.pid
);
$(".problem-helper-inlist-adder").remove();
let pid = "",
name = "";
let h = (pid, name) => `
添加
`;
let rows = $(".row");
let trim = (s) => {
return s.replace(/(^\s*)|(\s*$)/g, "");
};
rows.each((u) => {
u = $(rows[u]);
pid = u.children(".pid").text();
name = u.children(".title").children(".title").text();
name = trim(name);
u.children(".title").prepend(h(pid, name));
});
$(".problem-helper-inlist-adder").click((u) => {
u = $(u.target);
let r = u.attr("data");
let now = local_problems;
if (now.indexOf(r) == -1) now.push(r);
saveTrain(now);
unsafeWindow._feInstance.$swalToastSuccess("添加成功");
});
};
/* main controller */
function inject() {
if (unsafeWindow.location.href.includes("problem/list"))
deferredInjectProblemlist();
else if (unsafeWindow.location.href.includes("training"))
deferredInjectTrainPage(), deferredInjectProblemlist();
else if (unsafeWindow.location.href.includes("problem"))
deferredInjectProblemPage();
}
window.addEventListener("pushState", function (e) {
setTimeout(inject, inject_lantency);
});
window.addEventListener("replaceState", function (e) {
setTimeout(inject, inject_lantency);
});
setTimeout(inject, 100);
$(document.body).append(
``
);
};