Skip to content

Commit

Permalink
fix: busuanzi
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio24 committed Sep 28, 2024
1 parent 977474d commit f9aff10
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/core/utils/busuanzi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ type Data = {
readonly [k in (typeof keys)[number]]: number;
};

function forEachKey(f: (key: (typeof keys)[number]) => string) {
for (const key of keys) {
const element = document.getElementById(prefix + key);
if (element) {
element.innerHTML = f(key);
}
}
}

export default async function busuanzi() {
forEachKey((_) => '?');

const page = window.location.href.replace('#', 'H').replace('?', '/');
const data: Data = await fetch(busuanzi_url, {
method: 'POST',
Expand All @@ -16,12 +27,6 @@ export default async function busuanzi() {
},
body: JSON.stringify({ url: page }),
}).then((res) => res.json());

console.debug('busuanzi', data);
for (const key of keys) {
const element = document.getElementById(prefix + key);
if (element) {
element.innerHTML = '' + data[key];
}
}
console.debug('busuanzi', window.location.hash, data);
forEachKey((key) => '' + data[key]);
}

0 comments on commit f9aff10

Please sign in to comment.