https://leetcode.cn/circle/article/48kq9d/
我觉得这种很实用,题目链接
// ==UserScript==
// @name 有没有人一起从零开始刷力扣
// @namespace likou-replace
// @version 1.0
// @description none
// @AuThor Permission
// @match https://leetcode.cn/circle/article/48kq9d/*
// @require https://code.jquery.com/jquery-3.4.1.min.js
// @grant none
// ==/UserScript==
/* globals $, jQuery */
'use strict';
let proMap = new Map(),
transMap = new Map(),
buildMapComplete = false;
const getProblems = () => {
$.ajax({
url : 'https://leetcode.cn/api/problems/all/'
}).then((response) => {
getTrans(JSON.parse(response));
});
}
const getTrans = (picker) => {
$.post({
url : 'https://leetcode.cn/graphql',data:{"operationName":"getQuestionTranslation","variables":{},"query":"query getQuestionTranslation($lang: String) {\n translations: allAppliedQuestionTranslations(lang: $lang) {\n title\n questionId\n __typename\n }\n}\n"}
}).then((trans) => {
buildMap(picker, trans);
});
}
const buildMap = (picker, trans) => {
for(let pro of picker.stat_status_pairs){
proMap.set(pro.stat.frontend_question_id, pro.stat.question__title_slug);
}
for(let t of trans.data.translations){
transMap.set(t.questionId, t.title);
}
buildMapComplete = true;
};
const replace = () => {
let even = true;
for(let problem of $("table tr td")){
if(!even){
let htmlString = "";
let normalExit = true;
for(let id of problem.textContent.split('、')){
if(isNaN(parseInt(id))){
normalExit = false;
break;
}
htmlString += `<a href = 'https://leetcode.cn/problems/${proMap.get(id)}/' title = '${transMap.get(id)}' target = 'blank'>${id}</a>、`;
}
if(normalExit){
problem.innerHTML = `<td>${htmlString.substring(0, htmlString.length - 1)}</td>`;
}
}
even = !even;
};
}
getProblems();
const interval = setInterval(() => {
if(buildMapComplete && $("table tr td").length != 0){
clearInterval(interval);
replace();
}
}, 5e2);
|