@jx3box/jx3box-common 8.7.4 → 8.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/utils.js +26 -55
- package/package.json +1 -1
package/js/utils.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
default_avatar,
|
|
3
|
-
__sourceType,
|
|
4
|
-
__postType,
|
|
5
|
-
__wikiType,
|
|
6
|
-
__appType,
|
|
7
|
-
__gameType,
|
|
8
|
-
__imgPath,
|
|
9
|
-
__iconPath,
|
|
10
|
-
__clients,
|
|
11
|
-
__ossMirror,
|
|
12
|
-
} from "../data/jx3box.json";
|
|
1
|
+
import { default_avatar, __sourceType, __postType, __wikiType, __appType, __gameType, __imgPath, __iconPath, __clients, __ossMirror } from "../data/jx3box.json";
|
|
13
2
|
import tvmap from "../data/tvmap.json";
|
|
14
3
|
|
|
15
4
|
export function resolveImagePath(str) {
|
|
@@ -26,10 +15,7 @@ export function checkImageLoad(jq) {
|
|
|
26
15
|
jq.length &&
|
|
27
16
|
jq.one("error", function () {
|
|
28
17
|
var img_url = $(this).attr("src");
|
|
29
|
-
var fix_url = img_url.replace(
|
|
30
|
-
/cdn\.jx3box\.com/g,
|
|
31
|
-
"oss.jx3box.com"
|
|
32
|
-
);
|
|
18
|
+
var fix_url = img_url.replace(/cdn\.jx3box\.com/g, "oss.jx3box.com");
|
|
33
19
|
$(this).attr("src", fix_url);
|
|
34
20
|
});
|
|
35
21
|
}
|
|
@@ -150,12 +136,7 @@ export function iconLink(icon_id, client = "std") {
|
|
|
150
136
|
* 获取应用图标
|
|
151
137
|
*/
|
|
152
138
|
export function getAppIcon(key, colorful = false) {
|
|
153
|
-
return (
|
|
154
|
-
__imgPath +
|
|
155
|
-
(colorful ? "image/box-colorful/" : "image/box/") +
|
|
156
|
-
key +
|
|
157
|
-
".svg"
|
|
158
|
-
);
|
|
139
|
+
return __imgPath + (colorful ? "image/box-colorful/" : "image/box/") + key + ".svg";
|
|
159
140
|
}
|
|
160
141
|
|
|
161
142
|
/**
|
|
@@ -189,10 +170,7 @@ export function getLink(type, id, level) {
|
|
|
189
170
|
id = id || "";
|
|
190
171
|
|
|
191
172
|
// 核心作品、休闲数据
|
|
192
|
-
if (
|
|
193
|
-
__sourceType.cms_types.includes(type) ||
|
|
194
|
-
__sourceType.pvx_types.includes(type)
|
|
195
|
-
) {
|
|
173
|
+
if (__sourceType.cms_types.includes(type) || __sourceType.pvx_types.includes(type)) {
|
|
196
174
|
return "/" + type + "/" + id;
|
|
197
175
|
|
|
198
176
|
// 百科类型
|
|
@@ -290,13 +268,7 @@ export function getQuery(key) {
|
|
|
290
268
|
}
|
|
291
269
|
|
|
292
270
|
export function getTypeLabel(type) {
|
|
293
|
-
let types = Object.assign(
|
|
294
|
-
{},
|
|
295
|
-
__postType,
|
|
296
|
-
__wikiType,
|
|
297
|
-
__appType,
|
|
298
|
-
__gameType
|
|
299
|
-
);
|
|
271
|
+
let types = Object.assign({}, __postType, __wikiType, __appType, __gameType);
|
|
300
272
|
return types[type] || "未知";
|
|
301
273
|
}
|
|
302
274
|
|
|
@@ -316,11 +288,7 @@ export function ts2str(timestamp, opt = { polished: true, separator: "-" }) {
|
|
|
316
288
|
let year = dt.getFullYear();
|
|
317
289
|
let month = dt.getMonth() + 1;
|
|
318
290
|
let date = dt.getDate();
|
|
319
|
-
let str = opt.polished
|
|
320
|
-
? `${year}${opt.separator}${polish(month)}${opt.separator}${polish(
|
|
321
|
-
date
|
|
322
|
-
)}`
|
|
323
|
-
: `${year}${opt.separator}${month}${opt.separator}${date}`;
|
|
291
|
+
let str = opt.polished ? `${year}${opt.separator}${polish(month)}${opt.separator}${polish(date)}` : `${year}${opt.separator}${month}${opt.separator}${date}`;
|
|
324
292
|
return str;
|
|
325
293
|
|
|
326
294
|
function polish(val) {
|
|
@@ -340,10 +308,7 @@ export function jx3ClientType() {
|
|
|
340
308
|
*/
|
|
341
309
|
export function extractTextContent(str) {
|
|
342
310
|
if (!str || typeof str !== "string") return [];
|
|
343
|
-
const innerHTML = str.replace(
|
|
344
|
-
/<Text>(.*?)<\/text>/gimsy,
|
|
345
|
-
`<span $1></span>`
|
|
346
|
-
);
|
|
311
|
+
const innerHTML = str.replace(/<Text>(.*?)<\/text>/gimsy, `<span $1></span>`);
|
|
347
312
|
const parser = new DOMParser();
|
|
348
313
|
const doc = parser.parseFromString(innerHTML, "text/html");
|
|
349
314
|
const spans = doc.querySelectorAll("span");
|
|
@@ -388,8 +353,7 @@ export function showClientLabel(client) {
|
|
|
388
353
|
}
|
|
389
354
|
|
|
390
355
|
export function getMedalLink(event_id, subtype) {
|
|
391
|
-
if (subtype === "rank" || subtype === "superstar")
|
|
392
|
-
return `/rank/race/#/${event_id}/${subtype}`;
|
|
356
|
+
if (subtype === "rank" || subtype === "superstar") return `/rank/race/#/${event_id}/${subtype}`;
|
|
393
357
|
return `${subtype}/${event_id}`;
|
|
394
358
|
}
|
|
395
359
|
|
|
@@ -415,25 +379,33 @@ export function isMiniProgram() {
|
|
|
415
379
|
return navigator.userAgent.toLowerCase().includes("miniprogram");
|
|
416
380
|
}
|
|
417
381
|
|
|
382
|
+
/**
|
|
383
|
+
* 判断当前环境是否为app
|
|
384
|
+
* 判断url是否包含__env=app
|
|
385
|
+
*/
|
|
386
|
+
export function isApp() {
|
|
387
|
+
return new URLSearchParams(window.location.search).get("__env") === "app" || localStorage.getItem("__env") === "app";
|
|
388
|
+
}
|
|
389
|
+
|
|
418
390
|
export function miniprogramHack() {
|
|
419
|
-
document.addEventListener(
|
|
391
|
+
document.addEventListener("DOMContentLoaded", function () {
|
|
420
392
|
// 检查 html 标签是否有 wechat-miniprogram 类
|
|
421
|
-
if (document.documentElement.classList.contains(
|
|
393
|
+
if (document.documentElement.classList.contains("wechat-miniprogram")) {
|
|
422
394
|
// 为整个 document 添加一个点击事件监听器
|
|
423
|
-
document.addEventListener(
|
|
395
|
+
document.addEventListener("click", function (event) {
|
|
424
396
|
// 检查被点击的元素是否是一个链接
|
|
425
|
-
if (event.target.tagName ===
|
|
426
|
-
var href = event.target.getAttribute(
|
|
427
|
-
|
|
397
|
+
if (event.target.tagName === "A") {
|
|
398
|
+
var href = event.target.getAttribute("href");
|
|
399
|
+
|
|
428
400
|
// 检查是否是相对链接
|
|
429
|
-
var isRelative = !href.startsWith(
|
|
430
|
-
|
|
401
|
+
var isRelative = !href.startsWith("http://") && !href.startsWith("https://") && !href.startsWith("//");
|
|
402
|
+
|
|
431
403
|
// 检查是否是jx3box.com域名
|
|
432
404
|
var isJx3boxDomain = /jx3box\.com/.test(href);
|
|
433
|
-
|
|
405
|
+
|
|
434
406
|
// 检查是否是jx3.xoyo.com域名
|
|
435
407
|
var isJx3Domain = /jx3\.xoyo\.com/.test(href);
|
|
436
|
-
|
|
408
|
+
|
|
437
409
|
// 如果不是相对链接且不是jx3box.com域名
|
|
438
410
|
if (!isRelative && !isJx3boxDomain && !isJx3Domain) {
|
|
439
411
|
// 阻止默认行为
|
|
@@ -467,7 +439,6 @@ export function getTokenFromUrl() {
|
|
|
467
439
|
}
|
|
468
440
|
}
|
|
469
441
|
|
|
470
|
-
|
|
471
442
|
export default {
|
|
472
443
|
resolveImagePath,
|
|
473
444
|
checkImageLoad,
|