fix: dom-to-image add: specialthanks

This commit is contained in:
Vick Scarlet
2021-09-07 21:41:12 +08:00
parent 3f3d6dda0f
commit 4964b01eac
9 changed files with 243 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
import { max, sum } from './functions/util.js';
import { summary } from './functions/summary.js'
import Life from './life.js'
import domtoimage from 'dom-to-image';
class App{
constructor(){
this.#life = new Life();
@@ -14,11 +14,17 @@ class App{
#isEnd = false;
#selectedExtendTalent = null;
#hintTimeout;
#specialthanks;
async initial() {
this.initPages();
this.switch('loading');
await this.#life.initial();
const [,specialthanks] = await Promise.all([
this.#life.initial(),
json('specialthanks')
]);
this.#specialthanks = specialthanks;
console.table(specialthanks);
this.switch('index');
window.onerror = (event, source, lineno, colno, error) => {
this.hint(`[ERROR] at (${source}:${lineno}:${colno})\n\n${error?.stack||error||'unknow Error'}`, 'error');
@@ -42,6 +48,7 @@ class App{
<div id="main">
<div id="cnt" class="head">已重开1次</div>
<button id="rank">排行榜</button>
<button id="specialthanks">特别感谢</button>
<button id="themeToggleBtn">黑</button>
<div id="title">
人生重开模拟器<br>
@@ -74,6 +81,25 @@ class App{
this.setTheme(localStorage.getItem('theme'))
});
indexPage
.find('#specialthanks')
.click(()=>this.switch('specialthanks'));
const specialThanksPage = $(`
<div id="main">
<button id="specialthanks">返回</button>
<div id="spthx">
<ul class="g1"></ul>
<ul class="g2"></ul>
</div>
<button id="sponsor" onclick="window.open('https://afdian.net/@LifeRestart')">打赏作者</button>
</div>
`);
specialThanksPage
.find('#specialthanks')
.click(()=>this.switch('index'));
// Talent
const talentPage = $(`
<div id="main">
@@ -347,7 +373,7 @@ class App{
if(ua.match(/MicroMessenger/i)=="micromessenger") {
$('#endImage').attr('src', dataUrl);
}
});
})
trajectoryPage
@@ -375,7 +401,7 @@ class App{
<button id="again" class="mainbtn" style="top:auto; bottom:0.1em"><span class="iconfont">&#xe6a7;</span>再次重开</button>
</div>
`);
summaryPage
.find('#again')
.click(()=>{
@@ -393,7 +419,6 @@ class App{
page: loadingPage,
clear: ()=>{},
},
index: {
page: indexPage,
btnRank: indexPage.find('#rank'),
@@ -417,6 +442,25 @@ class App{
cnt.hide();
},
},
specialthanks: {
page: specialThanksPage,
clear: () => {
const groups = [
specialThanksPage.find('#spthx > ul.g1'),
specialThanksPage.find('#spthx > ul.g2'),
];
groups.forEach(g=>g.empty());
Object
.values(this.#specialthanks)
.sort(()=>0.5-Math.random())
.forEach(({group, name, comment})=>groups[--group].append(`
<li>
<span class="name">${name}</span>
<span class="comment">${comment||''}</span>
</li>
`))
}
},
talent: {
page: talentPage,
clear: ()=>{
@@ -511,7 +555,7 @@ class App{
})(),
].join(''));
}
}
},
}
}