diff --git a/js/coin.js b/js/coin.js index 594541f..bc9bdaa 100644 --- a/js/coin.js +++ b/js/coin.js @@ -34,17 +34,40 @@ function loadCoinSystem() { +// 渲染东币内容并分页显示 +function renderCoinContent(coinData) { + const coinContent = document.getElementById('coin-content'); + const itemsPerPage = 10; // 每页显示的记录数 + let currentPage = 1; // 当前页码 - // 渲染东币内容 - function renderCoinContent(coinData) { - const coinContent = document.getElementById('coin-content'); - coinContent.innerHTML = `

当前东币数:${coinData.coins}

`; + // 初始化内容 + coinContent.innerHTML = ` +

当前东币数:${coinData.coins}

+

下载某些资源时会花费东币,而投稿审核通过后可以获得东币。

+

请注意:由于下载同一份文件两次,从服务器流出的下行流量也会计算两次,因此当您多次下载同一个需要东币的资源时,东币也会多次扣除。我们建议您减少不必要的重复下载。

+

每页显示10条东币记录,最近的记录将显示在最后。

+ `; - const table = document.createElement('table'); - const headerRow = table.insertRow(); - headerRow.innerHTML = `时间明细操作`; + // 渲染表格数据 + function renderTable(page) { + const start = (page - 1) * itemsPerPage; + const end = start + itemsPerPage; + const transactions = coinData.transactions.slice(start, end); - coinData.transactions.forEach(transaction => { + let table = coinContent.querySelector('table'); + + // 如果表格不存在,创建一个新的表格 + if (!table) { + table = document.createElement('table'); + const headerRow = table.insertRow(); + headerRow.innerHTML = `时间明细操作`; + coinContent.appendChild(table); + } else { + // 如果表格存在,清空之前的内容(除标题外) + table.innerHTML = table.rows[0].innerHTML; // 保留标题行 + } + + transactions.forEach(transaction => { const row = table.insertRow(); row.innerHTML = ` ${transaction.date} @@ -52,10 +75,51 @@ function loadCoinSystem() { ${transaction.description} `; }); - - coinContent.appendChild(table); } + // 渲染页码 + function renderPagination() { + const totalPages = Math.ceil(coinData.transactions.length / itemsPerPage); + const pagination = document.createElement('div'); + pagination.className = 'pagination'; + + // 页码前添加“页码:” + const pageLabel = document.createElement('span'); + // pageLabel.textContent = '每页显示10条记录。'; + // pageLabel.style.marginRight = '10px'; + pagination.appendChild(pageLabel); + + for (let i = 1; i <= totalPages; i++) { + const pageLink = document.createElement('button'); + pageLink.textContent = i; + pageLink.className = 'page-link'; + pageLink.style.margin = '0 5px'; + pageLink.style.fontWeight = (i === currentPage) ? 'bold' : 'normal'; // 当前页码加粗 + pageLink.disabled = (i === currentPage); + pageLink.addEventListener('click', () => { + currentPage = i; + renderTable(currentPage); + renderPagination(); + }); + pagination.appendChild(pageLink); + } + + // 清空并添加新的分页控件 + const existingPagination = coinContent.querySelector('.pagination'); + if (existingPagination) { + coinContent.removeChild(existingPagination); + } + coinContent.appendChild(pagination); + } + + // 初始渲染 + renderTable(currentPage); + renderPagination(); +} + + + + // 渲染验证提示 function renderVerificationPrompt() { const coinContent = document.getElementById('coin-content'); @@ -207,11 +271,11 @@ function loadCoinSystem() { // 初始化金币系统 const initialData = { userEmail: curemail, - coins: 20, + coins: 50, transactions: [ { type: 'credit', - amount: 20, + amount: 50, description: '初始东币奖励', date: getCurrentTime() } diff --git a/js/coin.min.js b/js/coin.min.js index 80c61d1..d90cccf 100644 --- a/js/coin.min.js +++ b/js/coin.min.js @@ -1,8 +1,13 @@ -function loadCoinSystem(){function l(e){var t=document.getElementById("coin-content");t.innerHTML=`

当前东币数:${e.coins}

`;let n=document.createElement("table");n.insertRow().innerHTML="时间明细操作",e.transactions.forEach(e=>{n.insertRow().innerHTML=` +function loadCoinSystem(){function d(r){let a=document.getElementById("coin-content"),s=1;function c(e){e=10*(e-1),e=r.transactions.slice(e,10+e);let t=a.querySelector("table");t?t.innerHTML=t.rows[0].innerHTML:((t=document.createElement("table")).insertRow().innerHTML="时间明细操作",a.appendChild(t)),e.forEach(e=>{t.insertRow().innerHTML=` ${e.date} ${"credit"===e.type?"+":"-"}${e.amount} ${e.description} - `}),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=` + `})}a.innerHTML=` +

当前东币数:${r.coins}

+

下载某些资源时会花费东币,而投稿审核通过后可以获得东币。

+

请注意:由于下载同一份文件两次,从服务器流出的下行流量也会计算两次,因此当您多次下载同一个需要东币的资源时,东币也会多次扣除。我们建议您减少不必要的重复下载。

+

每页显示10条东币记录,最近的记录将显示在最后。

+ `,c(s),function t(){var n=Math.ceil(r.transactions.length/10),o=document.createElement("div"),e=(o.className="pagination",document.createElement("span"));o.appendChild(e);for(let e=1;e<=n;e++){var i=document.createElement("button");i.textContent=e,i.className="page-link",i.style.margin="0 5px",i.style.fontWeight=e===s?"bold":"normal",i.disabled=e===s,i.addEventListener("click",()=>{c(s=e),t()}),o.appendChild(i)}e=a.querySelector(".pagination");e&&a.removeChild(e),a.appendChild(o)}()}function o(){let a=document.getElementById("verification-modal"),o=(a.style.display="block",document.getElementById("send-code-btn")),s=document.getElementById("verify-btn"),i=document.getElementById("phone-number"),c=document.getElementById("verification-code"),l=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)?(l.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?(l.innerText="验证码已发送。若未收到,2分钟后可重新发送。",sessionStorage.setItem("phoneNumber",e)):(l.innerText="发送失败!请稍后再试。",o.disabled=!1,o.textContent="发送验证码"))}catch(e){l.innerText="发送验证码时出错,请稍后重试。",o.disabled=!1,o.textContent="发送验证码"}else l.innerText="请输入有效的11位手机号码!"}),s.addEventListener("click",async()=>{var e=sessionStorage.getItem("phoneNumber"),t=c.value.trim();if(l.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?(l.innerText="验证通过,请稍后……",s.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()=>{a.style.display="none";var e={userEmail:curemail,coins:50,transactions:[{type:"credit",amount:50,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),d(e)},2e3)):l.innerText="验证码错误,请重新输入。"}catch(e){l.innerText="验证时出错,请稍后重试。"}else l.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`;d(await(await fetchNoCache(n)).json())}catch(e){console.error("Error in initializeCoinSystem: ",e);{let e=document.getElementById("coin-content"),t=(e.innerHTML=`

您需要进行手机验证以解锁东币系统。下载某些资源时会花费东币,而投稿审核通过后可以获得东币。

请注意:由于下载同一份文件两次,从服务器流出的下行流量也会计算两次,因此当您多次下载同一个需要东币的资源时,东币也会多次扣除。我们建议您减少不必要的重复下载。

diff --git a/js/dlwithcoin.js b/js/dlwithcoin.js index 8a6edb5..749c3b9 100644 --- a/js/dlwithcoin.js +++ b/js/dlwithcoin.js @@ -58,10 +58,17 @@ function d2(e2, k2) { f1(); document.addEventListener("DOMContentLoaded", function() { - const linkId = "{{ .Get "id" }}"; - const objectKey = "{{ .Get "url" }}"; // 使用URL参数作为OSS对象的key + // const linkId = "{{ .Get "id" }}"; + // const objectKey = "{{ .Get "url" }}"; // 使用URL参数作为OSS对象的key + // const popupId = "popup-" + linkId; + // const requiredCoins = {{ .Get "coin" | default 0 }}; // 获取需要扣除的金币数,默认为0 + // const resourceTitle = "{{ .Get "title" }}"; // 获取资源标题 + + const linkId = "aaa"; + const objectKey = "bbb"; // 使用URL参数作为OSS对象的key const popupId = "popup-" + linkId; - const requiredCoins = {{ .Get "coin" | default 0 }}; // 获取需要扣除的金币数,默认为0 + const requiredCoins = 666; // 获取需要扣除的金币数,默认为0 + const resourceTitle = "ccc" const checkAndDownload = async () => { const loggedIn = getCookie('loggedIn'); @@ -92,7 +99,7 @@ document.addEventListener("DOMContentLoaded", function() { data.transactions.push({ type: "debit", amount: requiredCoins, - description: "下载资源", + description: `下载资源:${resourceTitle}`, // 使用资源标题 date: getCurrentTime() }); const coinBlob = new Blob([JSON.stringify(data)], { type: 'application/json' }); diff --git a/js/dlwithcoin.min.js b/js/dlwithcoin.min.js index dd1d657..10557b4 100644 --- a/js/dlwithcoin.min.js +++ b/js/dlwithcoin.min.js @@ -1 +1 @@ -let client;function getCookie(t){const n=t+"=";const o=document.cookie.split(";");for(let e=0;e{const t=getCookie("loggedIn");const e=getCookie("userEmail");if(!t){alert("请登录后下载!");window.location.href="/submission";return}if(l>0){const n=`https://download.xn--xhq44jb2fzpc.com/user/${e}/coin/list.json`;try{const o=await fetchNoCache(n);if(!o.ok){alert("您还未激活金币系统,请前往激活!");window.location.href="/submission";return}const c=await o.json();if(c.coins{let o=3;const c=document.getElementById(e);const s=c.querySelector(".popup-content");if(client){let t=client.signatureUrl(n,{expires:20,response:{"content-disposition":"attachment"}});const i=t.replace("emberimg.oss-cn-beijing.aliyuncs.com","download.xn--xhq44jb2fzpc.com");const r=()=>{if(o>0){s.textContent=`${o}秒后将开始下载...`;o--;setTimeout(r,1e3)}else{c.style.display="none";window.location.href=i}};c.style.display="block";r()}else{console.error("OSS client is not initialized.")}};document.getElementById(i).addEventListener("click",t)});function getCurrentTime(){const t=new Date;const e=new Date(t.getTime()+8*60*60*1e3);return e.toISOString().replace("T"," ").substring(0,19)} \ No newline at end of file +let client;function getCookie(t){const n=t+"=";const o=document.cookie.split(";");for(let e=0;e{const t=getCookie("loggedIn");const e=getCookie("userEmail");if(!t){alert("请登录后下载!");window.location.href="/submission";return}if(l>0){const n=`https://download.xn--xhq44jb2fzpc.com/user/${e}/coin/list.json`;try{const o=await fetchNoCache(n);if(!o.ok){alert("您还未激活金币系统,请前往激活!");window.location.href="/submission";return}const c=await o.json();if(c.coins{let o=3;const c=document.getElementById(e);const s=c.querySelector(".popup-content");if(client){let t=client.signatureUrl(n,{expires:20,response:{"content-disposition":"attachment"}});const i=t.replace("emberimg.oss-cn-beijing.aliyuncs.com","download.xn--xhq44jb2fzpc.com");const r=()=>{if(o>0){s.textContent=`${o}秒后将开始下载...`;o--;setTimeout(r,1e3)}else{c.style.display="none";window.location.href=i}};c.style.display="block";r()}else{console.error("OSS client is not initialized.")}};document.getElementById(i).addEventListener("click",t)});function getCurrentTime(){const t=new Date;const e=new Date(t.getTime()+8*60*60*1e3);return e.toISOString().replace("T"," ").substring(0,19)} \ No newline at end of file diff --git a/js/uglifyjs.txt b/js/uglifyjs.txt index c99f6aa..e57e48b 100644 --- a/js/uglifyjs.txt +++ b/js/uglifyjs.txt @@ -4,4 +4,7 @@ uglifyjs submission.js -o submission.min.js -m -c -o script.min.js:指定输出文件名为 script.min.js。 -m:启用变量名压缩(mangle),会将变量名压缩成更短的形式。 --c:启用代码压缩(compress),会对代码进行优化以减少文件体积。 \ No newline at end of file +-c:启用代码压缩(compress),会对代码进行优化以减少文件体积。 + +uglifyjs coin.js -o coin.min.js -m -c +uglifyjs dlwithcoin.js -o dlwithcoin.min.js -m diff --git a/resources/习概课本/index.html b/resources/习概课本/index.html index af33180..491f42f 100644 --- a/resources/习概课本/index.html +++ b/resources/习概课本/index.html @@ -467,7 +467,7 @@
diff --git a/resources/公路交通ppt/index.html b/resources/公路交通ppt/index.html index f2fbfcd..e42e5fa 100644 --- a/resources/公路交通ppt/index.html +++ b/resources/公路交通ppt/index.html @@ -467,7 +467,7 @@
diff --git a/resources/数值分析课本/index.html b/resources/数值分析课本/index.html index ba73b7a..7c39eec 100644 --- a/resources/数值分析课本/index.html +++ b/resources/数值分析课本/index.html @@ -470,7 +470,7 @@
diff --git a/resources/概率论/index.html b/resources/概率论/index.html index 8dcb6f0..edc4ee7 100644 --- a/resources/概率论/index.html +++ b/resources/概率论/index.html @@ -480,7 +480,7 @@
diff --git a/resources/马原课本/index.html b/resources/马原课本/index.html index b89f92b..e8e277a 100644 --- a/resources/马原课本/index.html +++ b/resources/马原课本/index.html @@ -463,7 +463,7 @@