|
98 | 98 | let localVal = localStorage.getItem('used-dynamic-layout');
|
99 | 99 | let isDynamic = localVal != null ? localVal.includes('true') : false;
|
100 | 100 |
|
| 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 | + |
101 | 146 | // 判断observer是否已存在,如果存在,则断开重新创建
|
102 | 147 | function observerReplace(item, newObserver) {
|
103 | 148 | const oldObserver = observerMap.get(item);
|
|
359 | 404 | waitForKeyElements.controlObj = controlObj;
|
360 | 405 | }
|
361 | 406 |
|
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({ |
364 | 409 | // 请求方式
|
365 | 410 | type: type,
|
366 | 411 | // 请求的媒体类型
|
|
370 | 415 | // 数据,json字符串
|
371 | 416 | data: data != null ? JSON.stringify(data) : null,
|
372 | 417 | // 同步方式
|
373 |
| - async: false, |
| 418 | + async: asyn, |
374 | 419 | xhrFields: {
|
375 | 420 | withCredentials: true
|
376 | 421 | },
|
|
817 | 862 | if (GM_getValue('switchpbstatusBtn')) {
|
818 | 863 | // console.log(levelData[id])
|
819 | 864 | 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; |
829 | 866 | // 使用layui的渲染
|
830 | 867 | layuiload();
|
831 | 868 | }
|
|
1946 | 1983 | }
|
1947 | 1984 | }
|
1948 | 1985 |
|
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 |
| - `; |
1978 | 1986 | async function layuiload() {
|
1979 | 1987 | // 使用layui的渲染
|
1980 | 1988 | layui.use(function () {
|
|
1984 | 1992 | // 普通事件
|
1985 | 1993 | util.on('lay-on', {
|
1986 | 1994 | // loading
|
1987 |
| - loading: function (othis) { |
1988 |
| - let DISABLED = 'layui-btn-disabled'; |
| 1995 | + loading: async function (othis) { |
| 1996 | + const DISABLED = 'layui-btn-disabled'; |
1989 | 1997 | if (othis.hasClass(DISABLED)) return;
|
1990 | 1998 | othis.addClass(DISABLED);
|
1991 |
| - let cnt = Math.trunc((getpbCnt() + 99) / 100); |
1992 |
| - let headers = { |
| 1999 | + const cnt = Math.ceil(getpbCnt() / 100); |
| 2000 | + const headers = { |
1993 | 2001 | 'Content-Type': 'application/json'
|
1994 | 2002 | };
|
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 | + }); |
2032 | 2042 | }
|
2033 | 2043 | });
|
2034 | 2044 | });
|
|
2140 | 2150 | if (GM_getValue('switchpbstatusBtn')) {
|
2141 | 2151 | // console.log(levelData[id])
|
2142 | 2152 | span4.innerHTML = `<i style="font-size:12px" class="layui-icon layui-icon-refresh"></i> 同步题目状态`;
|
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; |
2152 | 2154 | span4.setAttribute('style', 'cursor:pointer;');
|
2153 | 2155 | // 使用layui的渲染
|
2154 | 2156 | layuiload();
|
|
2571 | 2573 | { icon: 3 },
|
2572 | 2574 | function () {
|
2573 | 2575 | 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(); |
2581 | 2577 | layuiload();
|
2582 | 2578 | },
|
2583 | 2579 | function () {
|
|
0 commit comments