8000 Merge pull request #70 from EurFelux/main · zhang-wangz/LeetCodeRating@2d654cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d654cb

Browse files
authored
Merge pull request #70 from EurFelux/main
update: 更新若干新特性,调整样式,修复bug
2 parents 4a68c90 + 9567605 commit 2d654cb

File tree

2 files changed

+96
-99
lines changed

2 files changed

+96
-99
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ leetcoderatingjs/*-lock.json
77
*-lock.json
88
dist
99
node_modules
10-
doc
10+
doc
11+
bun.lock

leetcodeRating_greasyfork.user.js

Lines changed: 94 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,51 @@
9898
let localVal = localStorage.getItem('used-dynamic-layout');
9999
let isDynamic = localVal != null ? localVal.includes('true') : false;
100100

101+
// 因为字符显示问题,暂时去除
102+
// <span class="layui-progress-text myfont">0%</span>
103+
const pbstatusContent = `
104+
<div style="text-align: center; padding: 1rem; height: 100%; display: flex; flex-direction: column; justify-content: center;">
105+
<strong class="myfont"> 希望有大佬可以美化这丑丑的界面~ =v= </strong>
106+
<p style="padding-top: 10px;"></p>
107+
<div class="layui-progress layui-progress-big" lay-showPercent="true" lay-filter="demo-filter-progress">
108+
<div class="layui-progress-bar" lay-percent="0%">
109+
</div>
110+
</div>
111+
<p style="padding-top: 20px;"></p>
112+
<div class="layui-btn-container" style="">
113+
<button id="statusasyc" class="layui-btn layui-btn-radius" lay-on="loading">同步</button>
114+
</div>
115+
</div>
116+
`;
117+
const levelContent = `
118+
1 无算法要求
119+
2 知道常用数据结构和算法并简单使用
120+
3 理解常用数据结构和算法
121+
4 掌握常用数据结构和算法
122+
5 熟练掌握常用数据结构和算法,初步了解高级数据结构
123+
6 深入理解并灵活应用数据结构和算法,理解高级数据结构
124+
7 结合多方面的数据结构和算法,处理较复杂问题
125+
8 掌握不同的数据结构与算法之间的关联性,处理复杂问题,掌握高级数据结构
126+
9 处理复杂问题,对时间复杂度的要求更严格
127+
10 非常复杂的问题,非常高深的数据结构和算法(例如线段树、树状数组)
128+
11 竞赛内容,知识点超出面试范围
129+
`;
130+
131+
// layer复用
132+
const layer_sync = {
133+
type: 1,
134+
content: pbstatusContent,
135+
title: '同步所有题目状态',
136+
area: ['550px', '250px'],
137+
shade: 0.6,
138+
shadeClose: true
139+
};
140+
141+
const open_layer_sync = () => {
142+
layer.open(layer_sync)
143+
layui.element.render('progress', 'demo-filter-progress');
144+
}
145+
101146
// 判断observer是否已存在,如果存在,则断开重新创建
102147
function observerReplace(item, newObserver) {
103148
const oldObserver = observerMap.get(item);
@@ -359,8 +404,8 @@
359404
waitForKeyElements.controlObj = controlObj;
360405
}
361406

362-
let ajaxReq = (type, reqUrl, headers, data, successFuc, withCredentials = true) => {
363-
$.ajax({
407+
const ajaxReq = (type, reqUrl, headers, data, successFuc, asyn = false) => {
408+
return $.ajax({
364409
// 请求方式
365410
type: type,
366411
// 请求的媒体类型
@@ -370,7 +415,7 @@
370415
// 数据,json字符串
371416
data: data != null ? JSON.stringify(data) : null,
372417
// 同步方式
373-
async: false,
418+
async: asyn,
374419
xhrFields: {
375420
withCredentials: true
376421
},
@@ -817,15 +862,7 @@
817862
if (GM_getValue('switchpbstatusBtn')) {
818863
// console.log(levelData[id])
819864
span.innerHTML = `<i style="font-size:12px;" class="layui-icon layui-icon-refresh"></i> 同步题目状态`;
820-
span.onclick = function (e) {
821-
layer.open({
822-
type: 1,
823-
content: `${pbstatusContent}`,
824-
title: '同步所有题目状态',
825-
area: ['550px', '250px'],
826-
shade: 0.6
827-
});
828-
};
865+
span.onclick = open_layer_sync;
829866
// 使用layui的渲染
830867
layuiload();
831868
}
@@ -1946,35 +1983,6 @@
19461983
}
19471984
}
19481985

1949-
// 因为字符显示问题,暂时去除
1950-
// <span class="layui-progress-text myfont">0%</span>
1951-
let pbstatusContent = `
1952-
<div style="text-align: center;">
1953-
<strong class="myfont"> 希望有大佬可以美化这丑丑的界面~ =v= <strong>
1954-
<p style="padding-top: 10px;"></p>
1955-
<div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="demo-filter-progress">
1956-
<div class="layui-progress-bar" lay-percent="0%">
1957-
</div>
1958-
</div>
1959-
<p style="padding-top: 20px;"></p>
1960-
<div class="layui-btn-container" style="">
1961-
<button id="statusasyc" class="layui-btn layui-btn-radius" lay-on="loading">同步所有问题状态按钮</button>
1962-
</div>
1963-
</div>
1964-
`;
1965-
let levelContent = `
1966-
1 无算法要求
1967-
2 知道常用数据结构和算法并简单使用
1968-
3 理解常用数据结构和算法
1969-
4 掌握常用数据结构和算法
1970-
5 熟练掌握常用数据结构和算法,初步了解高级数据结构
1971-
6 深入理解并灵活应用数据结构和算法,理解高级数据结构
1972-
7 结合多方面的数据结构和算法,处理较复杂问题
1973-
8 掌握不同的数据结构与算法之间的关联性,处理复杂问题,掌握高级数据结构
1974-
9 处理复杂问题,对时间复杂度的要求更严格
1975-
10 非常复杂的问题,非常高深的数据结构和算法(例如线段树、树状数组)
1976-
11 竞赛内容,知识点超出面试范围
1977-
`;
19781986
async function layuiload() {
19791987
// 使用layui的渲染
19801988
layui.use(function () {
@@ -1984,51 +1992,53 @@
19841992
// 普通事件
19851993
util.on('lay-on', {
19861994
// loading
1987-
loading: function (othis) {
1988-
let DISABLED = 'layui-btn-disabled';
1995+
loading: async function (othis) {
1996+
const DISABLED = 'layui-btn-disabled';
19891997
if (othis.hasClass(DISABLED)) return;
19901998
othis.addClass(DISABLED);
1991-
let cnt = Math.trunc((getpbCnt() + 99) / 100);
1992-
let headers = {
1999+
const cnt = Math.ceil(getpbCnt() / 100);
2000+
const headers = {
19932001
'Content-Type': 'application/json'
19942002
};
1995-
let skip = 0;
1996-
let timer = setInterval(
1997-
async function () {
1998-
ajaxReq('POST', lcgraphql, headers, allPbPostData(skip, 100), res => {
1999-
let questions = res.data.problemsetQuestionList.questions;
2000-
for (let pb of questions) {
2001-
pbstatus[pb.titleSlug] = {
2002-
titleSlug: pb.titleSlug,
2003-
id: pb.frontendQuestionId,
2004-
status: pb.status,
2005-
title: pb.title,
2006-
titleCn: pb.titleCn,
2007-
difficulty: pb.difficulty,
2008-
paidOnly: pb.paidOnly
2009-
};
2010-
}
2011-
});
2012-
skip += 100;
2013-
// skip / 100 是当前已经进行的次数
2014-
let showval = Math.trunc((skip / 100 / cnt) * 100);
2015-
if (skip / 100 >= cnt) {
2016-
showval = 100;
2017-
clearInterval(timer);
2018-
}
2019-
element.progress('demo-filter-progress', showval + '%');
2020-
if (showval == 100) {
2021-
pbstatus[pbstatusVersion] = {};
2022-
GM_setValue('pbstatus', JSON.stringify(pbstatus));
2023-
console.log('同步所有题目状态完成...');
2024-
await sleep(1000);
2025-
layer.msg('同步所有题目状态完成!');
2026-
await sleep(1000);
2027-
layer.closeAll();
2028-
}
2029-
},
2030-
300 + Math.random() * 1000
2031-
);
2003+
let loaded = 0;
2004+
const promises = [];
2005+
for (let i = 0; i < cnt; i++) {
2006+
promises.push(
2007+
ajaxReq(
2008+
'POST',
2009+
lcgraphql,
2010+
headers,
2011+
allPbPostData(i * 100, 100),
2012+
async res => {
2013+
const questions = res.data.problemsetQuestionList.questions;
2014+
for (const pb of questions) {
2015+
pbstatus[pb.titleSlug] = {
2016+
titleSlug: pb.titleSlug,
2017+
id: pb.frontendQuestionId,
2018+
status: pb.status,
2019+
title: pb.title,
2020+
titleCn: pb.titleCn,
2021+
difficulty: pb.difficulty,
2022+
paidOnly: pb.paidOnly
2023+
};
2024+
}
2025+
loaded += 1;
2026+
2027+
const showval = Math.trunc((loaded / cnt) * 100);
2028+
element.progress('demo-filter-progress', `${showval}%`);
2029+
},
2030+
true
2031+
)
2032+
);
2033+
}
2034+
2035+
Promise.all(promises).then(async () => {
2036+
pbstatus[pbstatusVersion] = {};
2037+
GM_setValue('pbstatus', JSON.stringify(pbstatus));
2038+
layer.msg('同步所有题目状态完成!');
2039+
await sleep(1000);
2040+
layer.closeAll();
2041+
});
20322042
}
20332043
});
20342044
});
@@ -2140,15 +2150,7 @@
21402150
if (GM_getValue('switchpbstatusBtn')) {
21412151
// console.log(levelData[id])
21422152
span4.innerHTML = `<i style="font-size:12px" class="layui-icon layui-icon-refresh"></i>&nbsp;同步题目状态`;
2143-
span4.onclick = function (e) {
2144-
layer.open({
2145-
type: 1,
2146-
content: `${pbstatusContent}`,
2147-
title: '同步所有题目状态',
2148-
area: ['550px', '250px'],
2149-
shade: 0.6
2150-
});
2151-
};
2153+
span4.onclick = open_layer_sync;
21522154
span4.setAttribute('style', 'cursor:pointer;');
21532155
// 使用layui的渲染
21542156
layuiload();
@@ -2571,13 +2573,7 @@
25712573
{ icon: 3 },
25722574
function () {
25732575
layer.close(syncLayer);
2574-
layer.open({
2575-
type: 1,
2576-
content: `${pbstatusContent}`,
2577-
title: '同步所有题目状态',
2578-
area: ['550px', '250px'],
2579-
shade: 0.6
2580-
});
2576+
open_layer_sync();
25812577
layuiload();
25822578
},
25832579
function () {

0 commit comments

Comments
 (0)
0