front/js/coin.min.js
2024-09-02 14:26:09 +08:00

9 lines
4.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

function loadCoinSystem(){function l(e){var t=document.getElementById("coin-content");t.innerHTML=`<p>当前东币数:${e.coins}</p>`;let n=document.createElement("table");n.insertRow().innerHTML="<th>时间</th><th>明细</th><th>操作</th>",e.transactions.forEach(e=>{n.insertRow().innerHTML=`
<td>${e.date}</td>
<td>${"credit"===e.type?"+":"-"}${e.amount}</td>
<td>${e.description}</td>
`}),t.appendChild(n)}function o(){let s=document.getElementById("verification-modal"),o=(s.style.display="block",document.getElementById("send-code-btn")),a=document.getElementById("verify-btn"),i=document.getElementById("phone-number"),c=document.getElementById("verification-code"),d=document.getElementById("modal-message");o.addEventListener("click",async()=>{var e=i.value.trim();if(/^\d{11}$/.test(e)&&"1"===e.charAt(0))try{var t,n=CryptoJS.SHA256(e).toString();(await(await fetchNoCache("https://download.xn--xhq44jb2fzpc.com/user/pn.json")).json()).includes(n)?(d.innerText="此手机号已被验证过!",o.disabled=!1,o.textContent="发送验证码"):(o.disabled=!0,o.textContent="禁用中...",setTimeout(()=>{o.disabled=!1,o.textContent="发送验证码"},12e4),await(t=await fetch("https://sms.xn--xhq44jb2fzpc.com/send-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({phoneNumber:e})})).json(),t.ok?(d.innerText="验证码已发送。若未收到2分钟后可重新发送。",sessionStorage.setItem("phoneNumber",e)):(d.innerText="发送失败!请稍后再试。",o.disabled=!1,o.textContent="发送验证码"))}catch(e){d.innerText="发送验证码时出错,请稍后重试。",o.disabled=!1,o.textContent="发送验证码"}else d.innerText="请输入有效的11位手机号码"}),a.addEventListener("click",async()=>{var e=sessionStorage.getItem("phoneNumber"),t=c.value.trim();if(d.innerText="",t&&e)try{var n,o,i=await fetch("https://sms.xn--xhq44jb2fzpc.com/verify-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({phoneNumber:e,verificationCode:t})}),r=await i.json();i.ok&&r.verified?(d.innerText="验证通过,请稍后……",a.disabled=!0,c.disabled=!0,n=CryptoJS.SHA256(e).toString(),(o=await(await fetchNoCache("https://download.xn--xhq44jb2fzpc.com/user/pn.json")).json()).push(n),await client.put("user/pn.json",new Blob([JSON.stringify(o)],{type:"application/json"})),await client.put(`user/${curemail}/pn.json`,new Blob([JSON.stringify({phoneNumber:e})],{type:"application/json"})),setTimeout(async()=>{s.style.display="none";var e={userEmail:curemail,coins:20,transactions:[{type:"credit",amount:20,description:"初始东币奖励",date:(e=new Date,new Date(e.getTime()+288e5).toISOString().replace("T"," ").substring(0,19))}]},t=new Blob([JSON.stringify(!0)],{type:"application/json"}),t=(await client.put(`user/${curemail}/coin/verify.json`,t),new Blob([JSON.stringify(e)],{type:"application/json"}));await client.put(`user/${curemail}/coin/list.json`,t),l(e)},2e3)):d.innerText="验证码错误,请重新输入。"}catch(e){d.innerText="验证时出错,请稍后重试。"}else d.innerText="请输入手机号和验证码。"})}document.getElementById("cancel-btn").addEventListener("click",function(){document.getElementById("verification-modal").style.display="none"}),async function(){try{var e=`https://download.xn--xhq44jb2fzpc.com/user/${curemail}/coin/verify.json`,t=await(await fetchNoCache(e)).json();if(console.log("Verify Response: ",t),!0!==t)throw new Error("Verification required");var n=`https://download.xn--xhq44jb2fzpc.com/user/${curemail}/coin/list.json`;l(await(await fetchNoCache(n)).json())}catch(e){console.error("Error in initializeCoinSystem: ",e);{let e=document.getElementById("coin-content"),t=(e.innerHTML=`
<p>您需要进行手机验证以解锁东币系统。下载某些资源时会花费东币,而投稿审核通过后可以获得东币。</p>
<p><strong>请注意:</strong>由于下载同一份文件两次,从服务器流出的下行流量也会计算两次,因此当您多次下载同一个需要东币的资源时,东币也会多次扣除。<strong>我们建议您减少不必要的重复下载。</strong></p>
<button id="first-verify-btn">验证</button>
`,document.getElementById("first-verify-btn"));t.style.display="block",t.style.margin="0 auto",t.style.padding="10px 20px",t.style.backgroundColor="#007BFF",t.style.color="#fff",t.style.border="none",t.style.borderRadius="4px",t.style.cursor="pointer",t.style.textAlign="center",t.onmouseover=function(){t.style.backgroundColor="#0056b3"},t.onmouseout=function(){t.style.backgroundColor="#007BFF"},t.onmousedown=function(){t.style.backgroundColor="#003f7f"},document.body.classList.contains("dark")&&(t.style.backgroundColor="#444",t.style.color="#fff");t.addEventListener("click",o);return}}}()}