Skip to content

Commit

Permalink
✨ Support data style
Browse files Browse the repository at this point in the history
  • Loading branch information
soxft committed Oct 30, 2024
1 parent e64fac0 commit 6455e59
Show file tree
Hide file tree
Showing 6 changed files with 729 additions and 570 deletions.
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Web:
Address: 0.0.0.0:8080 # 监听地址
Cors: "https://xsot.cn,https://google.com" # 跨域访问
Debug: false # 是否开启debug模式
Log: true # 是否开启日志
Log: false # 是否开启日志
Redis:
Address: redis:6379 # redis地址
Password:
Expand Down
2 changes: 1 addition & 1 deletion dist/busuanzi.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 22 additions & 2 deletions dist/busuanzi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,35 @@
pjax: boolean = current.hasAttribute("pjax"), // 是否启用 pjax
api: string = current.getAttribute("data-api") || url, // 自定义后端地址
prefix: string = current.getAttribute("data-prefix") || "busuanzi", // 自定义标签ID前缀
style: string = current.getAttribute("data-style") || "default", // 数字显示风格 default | comma | short
storageName: string = "bsz-id"; // 本地存储名称

let bsz_send: Function = function () {
let format = (num: number, style: string = 'default'): string => {
switch (style) {
case "comma":
return num.toLocaleString();
case "short": {
let units = ["", "K", "M", "B", "T"];
let index = 0;
while (num >= 1000 && index < units.length - 1) {
num /= 1000;
index++;
}
return Math.round(num * 100) / 100 + units[index]; // 四舍五入到两位小数
}
default:
return num.toString();
}
};

let bsz_send = () => {
let xhr: XMLHttpRequest = new XMLHttpRequest();
xhr.open("POST", api, true);

// set user identity
let token: string | null = localStorage.getItem(storageName);
if (token != null) xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("x-bsz-referer", window.location.href);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
Expand All @@ -23,7 +43,7 @@
if (res.success === true) {
tags.map((tag: string) => {
let element = document.getElementById(`${prefix}_${tag}`);
if (element != null) element.innerHTML = res['data'][tag];
if (element != null) element.innerHTML = format(res['data'][tag], style);

let container = document.getElementById(`${prefix}_container_${tag}`);
if (container != null) container.style.display = "inline";
Expand Down
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<link href="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/bootstrap/4.6.0/css/bootstrap.min.css" type="text/css" rel="stylesheet" />
<link href="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/highlight.js/11.4.0/styles/atom-one-dark.min.css" type="text/css" rel="stylesheet" />
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/highlight.js/11.4.0/highlight.min.js" type="application/javascript"></script>
<script async src="/js"></script>
<script async data-style="short" src="/js"></script>
<script>
try {
hljs.highlightAll();
Expand Down
52 changes: 26 additions & 26 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"name": "busuanzi",
"description": "",
"dependencies": {
"ts-loader": "^9.3.0",
"typescript": "^4.6.4",
"webpack": "^5.72.1",
"webpack-cli": "^4.10.0"
},
"license": "Apache-2.0",
"scripts": {
"build": "webpack --config webpack.config.js",
"dev": "webpack-dev-server --config webpack.config.js --hot"
},
"version": "1.0.0",
"main": "busuanzi.ts",
"repository": {
"type": "git",
"url": "https://github.com/soxft/busuanzi"
},
"keywords": [],
"author": "xcsoft",
"bugs": {
"url": "https://github.com/soxft/busuanzi/issues"
},
"homepage": "https://busuanzi.9420.ltd/"
{
"name": "busuanzi",
"description": "",
"dependencies": {
"ts-loader": "^9.3.0",
"typescript": "^4.6.4",
"webpack": "5.76.0",
"webpack-cli": "^4.10.0"
},
"license": "Apache-2.0",
"scripts": {
"build": "webpack --config webpack.config.js",
"dev": "webpack-dev-server --config webpack.config.js --hot"
},
"version": "1.0.0",
"main": "busuanzi.ts",
"repository": {
"type": "git",
"url": "https://github.com/soxft/busuanzi"
},
"keywords": [],
"author": "xcsoft",
"bugs": {
"url": "https://github.com/soxft/busuanzi/issues"
},
"homepage": "https://busuanzi.9420.ltd/"
}
Loading

0 comments on commit 6455e59

Please sign in to comment.