artalk 2.8.6 → 2.8.7
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/dist/Artalk.cjs +1 -1
- package/dist/Artalk.cjs.map +1 -1
- package/dist/Artalk.iife.js +1 -1
- package/dist/Artalk.iife.js.map +1 -1
- package/dist/Artalk.js +1 -1
- package/dist/Artalk.js.map +1 -1
- package/dist/Artalk.mjs +306 -267
- package/dist/Artalk.mjs.map +1 -1
- package/dist/ArtalkLite.cjs +2 -2
- package/dist/ArtalkLite.cjs.map +1 -1
- package/dist/ArtalkLite.iife.js +2 -2
- package/dist/ArtalkLite.iife.js.map +1 -1
- package/dist/ArtalkLite.js +2 -2
- package/dist/ArtalkLite.js.map +1 -1
- package/dist/ArtalkLite.mjs +306 -267
- package/dist/ArtalkLite.mjs.map +1 -1
- package/dist/main.d.cts +16 -14
- package/dist/main.d.ts +16 -14
- package/package.json +8 -10
package/dist/ArtalkLite.mjs
CHANGED
|
@@ -2663,6 +2663,157 @@ class DataManager {
|
|
|
2663
2663
|
this.events.trigger("page-loaded", pageData);
|
|
2664
2664
|
}
|
|
2665
2665
|
}
|
|
2666
|
+
function createElement(htmlStr = "") {
|
|
2667
|
+
const div = document.createElement("div");
|
|
2668
|
+
div.innerHTML = htmlStr.trim();
|
|
2669
|
+
return div.firstElementChild || div;
|
|
2670
|
+
}
|
|
2671
|
+
function getHeight(el) {
|
|
2672
|
+
const num = parseFloat(getComputedStyle(el, null).height.replace("px", ""));
|
|
2673
|
+
return num || 0;
|
|
2674
|
+
}
|
|
2675
|
+
function htmlEncode(str) {
|
|
2676
|
+
const temp = document.createElement("div");
|
|
2677
|
+
temp.innerText = str;
|
|
2678
|
+
const output = temp.innerHTML;
|
|
2679
|
+
return output;
|
|
2680
|
+
}
|
|
2681
|
+
function getQueryParam(name) {
|
|
2682
|
+
const match = RegExp(`[?&]${name}=([^&]*)`).exec(window.location.search);
|
|
2683
|
+
return match && decodeURIComponent(match[1].replace(/\+/g, " "));
|
|
2684
|
+
}
|
|
2685
|
+
function getOffset(el, relativeTo) {
|
|
2686
|
+
const getOffsetRecursive = (element) => {
|
|
2687
|
+
const rect = element.getBoundingClientRect();
|
|
2688
|
+
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
|
|
2689
|
+
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
2690
|
+
return {
|
|
2691
|
+
top: rect.top + scrollTop,
|
|
2692
|
+
left: rect.left + scrollLeft
|
|
2693
|
+
};
|
|
2694
|
+
};
|
|
2695
|
+
const elOffset = getOffsetRecursive(el);
|
|
2696
|
+
if (!relativeTo)
|
|
2697
|
+
return elOffset;
|
|
2698
|
+
const relativeToOffset = getOffsetRecursive(relativeTo);
|
|
2699
|
+
return {
|
|
2700
|
+
top: elOffset.top - relativeToOffset.top,
|
|
2701
|
+
left: elOffset.left - relativeToOffset.left
|
|
2702
|
+
};
|
|
2703
|
+
}
|
|
2704
|
+
function padWithZeros(vNumber, width) {
|
|
2705
|
+
let numAsString = vNumber.toString();
|
|
2706
|
+
while (numAsString.length < width) {
|
|
2707
|
+
numAsString = `0${numAsString}`;
|
|
2708
|
+
}
|
|
2709
|
+
return numAsString;
|
|
2710
|
+
}
|
|
2711
|
+
function dateFormat(date) {
|
|
2712
|
+
const vDay = padWithZeros(date.getDate(), 2);
|
|
2713
|
+
const vMonth = padWithZeros(date.getMonth() + 1, 2);
|
|
2714
|
+
const vYear = padWithZeros(date.getFullYear(), 2);
|
|
2715
|
+
return `${vYear}-${vMonth}-${vDay}`;
|
|
2716
|
+
}
|
|
2717
|
+
function timeAgo(date, $t = (n) => n) {
|
|
2718
|
+
try {
|
|
2719
|
+
const oldTime = date.getTime();
|
|
2720
|
+
const currTime = (/* @__PURE__ */ new Date()).getTime();
|
|
2721
|
+
const diffValue = currTime - oldTime;
|
|
2722
|
+
const days = Math.floor(diffValue / (24 * 3600 * 1e3));
|
|
2723
|
+
if (days === 0) {
|
|
2724
|
+
const leave1 = diffValue % (24 * 3600 * 1e3);
|
|
2725
|
+
const hours = Math.floor(leave1 / (3600 * 1e3));
|
|
2726
|
+
if (hours === 0) {
|
|
2727
|
+
const leave2 = leave1 % (3600 * 1e3);
|
|
2728
|
+
const minutes = Math.floor(leave2 / (60 * 1e3));
|
|
2729
|
+
if (minutes === 0) {
|
|
2730
|
+
const leave3 = leave2 % (60 * 1e3);
|
|
2731
|
+
const seconds = Math.round(leave3 / 1e3);
|
|
2732
|
+
if (seconds < 10)
|
|
2733
|
+
return $t("now");
|
|
2734
|
+
return `${seconds} ${$t("seconds")}`;
|
|
2735
|
+
}
|
|
2736
|
+
return `${minutes} ${$t("minutes")}`;
|
|
2737
|
+
}
|
|
2738
|
+
return `${hours} ${$t("hours")}`;
|
|
2739
|
+
}
|
|
2740
|
+
if (days < 0)
|
|
2741
|
+
return $t("now");
|
|
2742
|
+
if (days < 8) {
|
|
2743
|
+
return `${days} ${$t("days")}`;
|
|
2744
|
+
}
|
|
2745
|
+
return dateFormat(date);
|
|
2746
|
+
} catch (error) {
|
|
2747
|
+
console.error(error);
|
|
2748
|
+
return " - ";
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
function getGravatarURL(opts) {
|
|
2752
|
+
return `${opts.mirror.replace(/\/$/, "")}/${opts.emailHash}?${opts.params.replace(/^\?/, "")}`;
|
|
2753
|
+
}
|
|
2754
|
+
function versionCompare(a, b) {
|
|
2755
|
+
const pa = a.split(".");
|
|
2756
|
+
const pb = b.split(".");
|
|
2757
|
+
for (let i = 0; i < 3; i++) {
|
|
2758
|
+
const na = Number(pa[i]);
|
|
2759
|
+
const nb = Number(pb[i]);
|
|
2760
|
+
if (na > nb)
|
|
2761
|
+
return 1;
|
|
2762
|
+
if (nb > na)
|
|
2763
|
+
return -1;
|
|
2764
|
+
if (!Number.isNaN(na) && Number.isNaN(nb))
|
|
2765
|
+
return 1;
|
|
2766
|
+
if (Number.isNaN(na) && !Number.isNaN(nb))
|
|
2767
|
+
return -1;
|
|
2768
|
+
}
|
|
2769
|
+
return 0;
|
|
2770
|
+
}
|
|
2771
|
+
function getCorrectUserAgent() {
|
|
2772
|
+
return __async(this, null, function* () {
|
|
2773
|
+
const uaRaw = navigator.userAgent;
|
|
2774
|
+
if (!navigator.userAgentData || !navigator.userAgentData.getHighEntropyValues) {
|
|
2775
|
+
return uaRaw;
|
|
2776
|
+
}
|
|
2777
|
+
const uaData = navigator.userAgentData;
|
|
2778
|
+
let uaGot = null;
|
|
2779
|
+
try {
|
|
2780
|
+
uaGot = yield uaData.getHighEntropyValues(["platformVersion"]);
|
|
2781
|
+
} catch (err) {
|
|
2782
|
+
console.error(err);
|
|
2783
|
+
return uaRaw;
|
|
2784
|
+
}
|
|
2785
|
+
const majorPlatformVersion = Number(uaGot.platformVersion.split(".")[0]);
|
|
2786
|
+
if (uaData.platform === "Windows") {
|
|
2787
|
+
if (majorPlatformVersion >= 13) {
|
|
2788
|
+
return uaRaw.replace(/Windows NT 10.0/, "Windows NT 11.0");
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
if (uaData.platform === "macOS") {
|
|
2792
|
+
if (majorPlatformVersion >= 11) {
|
|
2793
|
+
return uaRaw.replace(
|
|
2794
|
+
/(Mac OS X \d+_\d+_\d+|Mac OS X)/,
|
|
2795
|
+
`Mac OS X ${uaGot.platformVersion.replace(/\./g, "_")}`
|
|
2796
|
+
);
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
return uaRaw;
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2802
|
+
function isValidURL(urlRaw) {
|
|
2803
|
+
let url;
|
|
2804
|
+
try {
|
|
2805
|
+
url = new URL(urlRaw);
|
|
2806
|
+
} catch (_) {
|
|
2807
|
+
return false;
|
|
2808
|
+
}
|
|
2809
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
2810
|
+
}
|
|
2811
|
+
function getURLBasedOnApi(opts) {
|
|
2812
|
+
return getURLBasedOn(opts.base, opts.path);
|
|
2813
|
+
}
|
|
2814
|
+
function getURLBasedOn(baseURL, path) {
|
|
2815
|
+
return `${baseURL.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
|
|
2816
|
+
}
|
|
2666
2817
|
const en = {
|
|
2667
2818
|
/* Editor */
|
|
2668
2819
|
placeholder: "Leave a comment",
|
|
@@ -2868,156 +3019,6 @@ const zhCN = {
|
|
|
2868
3019
|
openName: "打开{name}"
|
|
2869
3020
|
};
|
|
2870
3021
|
const GLOBAL_LOCALES_KEY = "ArtalkI18n";
|
|
2871
|
-
function createElement(htmlStr = "") {
|
|
2872
|
-
const div = document.createElement("div");
|
|
2873
|
-
div.innerHTML = htmlStr.trim();
|
|
2874
|
-
return div.firstElementChild || div;
|
|
2875
|
-
}
|
|
2876
|
-
function getHeight(el) {
|
|
2877
|
-
return parseFloat(getComputedStyle(el, null).height.replace("px", ""));
|
|
2878
|
-
}
|
|
2879
|
-
function htmlEncode(str) {
|
|
2880
|
-
const temp = document.createElement("div");
|
|
2881
|
-
temp.innerText = str;
|
|
2882
|
-
const output = temp.innerHTML;
|
|
2883
|
-
return output;
|
|
2884
|
-
}
|
|
2885
|
-
function getQueryParam(name) {
|
|
2886
|
-
const match = RegExp(`[?&]${name}=([^&]*)`).exec(window.location.search);
|
|
2887
|
-
return match && decodeURIComponent(match[1].replace(/\+/g, " "));
|
|
2888
|
-
}
|
|
2889
|
-
function getOffset(el, relativeTo) {
|
|
2890
|
-
const getOffsetRecursive = (element) => {
|
|
2891
|
-
const rect = element.getBoundingClientRect();
|
|
2892
|
-
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
|
|
2893
|
-
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
2894
|
-
return {
|
|
2895
|
-
top: rect.top + scrollTop,
|
|
2896
|
-
left: rect.left + scrollLeft
|
|
2897
|
-
};
|
|
2898
|
-
};
|
|
2899
|
-
const elOffset = getOffsetRecursive(el);
|
|
2900
|
-
if (!relativeTo)
|
|
2901
|
-
return elOffset;
|
|
2902
|
-
const relativeToOffset = getOffsetRecursive(relativeTo);
|
|
2903
|
-
return {
|
|
2904
|
-
top: elOffset.top - relativeToOffset.top,
|
|
2905
|
-
left: elOffset.left - relativeToOffset.left
|
|
2906
|
-
};
|
|
2907
|
-
}
|
|
2908
|
-
function padWithZeros(vNumber, width) {
|
|
2909
|
-
let numAsString = vNumber.toString();
|
|
2910
|
-
while (numAsString.length < width) {
|
|
2911
|
-
numAsString = `0${numAsString}`;
|
|
2912
|
-
}
|
|
2913
|
-
return numAsString;
|
|
2914
|
-
}
|
|
2915
|
-
function dateFormat(date) {
|
|
2916
|
-
const vDay = padWithZeros(date.getDate(), 2);
|
|
2917
|
-
const vMonth = padWithZeros(date.getMonth() + 1, 2);
|
|
2918
|
-
const vYear = padWithZeros(date.getFullYear(), 2);
|
|
2919
|
-
return `${vYear}-${vMonth}-${vDay}`;
|
|
2920
|
-
}
|
|
2921
|
-
function timeAgo(date, $t = (n) => n) {
|
|
2922
|
-
try {
|
|
2923
|
-
const oldTime = date.getTime();
|
|
2924
|
-
const currTime = (/* @__PURE__ */ new Date()).getTime();
|
|
2925
|
-
const diffValue = currTime - oldTime;
|
|
2926
|
-
const days = Math.floor(diffValue / (24 * 3600 * 1e3));
|
|
2927
|
-
if (days === 0) {
|
|
2928
|
-
const leave1 = diffValue % (24 * 3600 * 1e3);
|
|
2929
|
-
const hours = Math.floor(leave1 / (3600 * 1e3));
|
|
2930
|
-
if (hours === 0) {
|
|
2931
|
-
const leave2 = leave1 % (3600 * 1e3);
|
|
2932
|
-
const minutes = Math.floor(leave2 / (60 * 1e3));
|
|
2933
|
-
if (minutes === 0) {
|
|
2934
|
-
const leave3 = leave2 % (60 * 1e3);
|
|
2935
|
-
const seconds = Math.round(leave3 / 1e3);
|
|
2936
|
-
if (seconds < 10)
|
|
2937
|
-
return $t("now");
|
|
2938
|
-
return `${seconds} ${$t("seconds")}`;
|
|
2939
|
-
}
|
|
2940
|
-
return `${minutes} ${$t("minutes")}`;
|
|
2941
|
-
}
|
|
2942
|
-
return `${hours} ${$t("hours")}`;
|
|
2943
|
-
}
|
|
2944
|
-
if (days < 0)
|
|
2945
|
-
return $t("now");
|
|
2946
|
-
if (days < 8) {
|
|
2947
|
-
return `${days} ${$t("days")}`;
|
|
2948
|
-
}
|
|
2949
|
-
return dateFormat(date);
|
|
2950
|
-
} catch (error) {
|
|
2951
|
-
console.error(error);
|
|
2952
|
-
return " - ";
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
function getGravatarURL(opts) {
|
|
2956
|
-
return `${opts.mirror.replace(/\/$/, "")}/${opts.emailMD5}?${opts.params.replace(/^\?/, "")}`;
|
|
2957
|
-
}
|
|
2958
|
-
function versionCompare(a, b) {
|
|
2959
|
-
const pa = a.split(".");
|
|
2960
|
-
const pb = b.split(".");
|
|
2961
|
-
for (let i = 0; i < 3; i++) {
|
|
2962
|
-
const na = Number(pa[i]);
|
|
2963
|
-
const nb = Number(pb[i]);
|
|
2964
|
-
if (na > nb)
|
|
2965
|
-
return 1;
|
|
2966
|
-
if (nb > na)
|
|
2967
|
-
return -1;
|
|
2968
|
-
if (!Number.isNaN(na) && Number.isNaN(nb))
|
|
2969
|
-
return 1;
|
|
2970
|
-
if (Number.isNaN(na) && !Number.isNaN(nb))
|
|
2971
|
-
return -1;
|
|
2972
|
-
}
|
|
2973
|
-
return 0;
|
|
2974
|
-
}
|
|
2975
|
-
function getCorrectUserAgent() {
|
|
2976
|
-
return __async(this, null, function* () {
|
|
2977
|
-
const uaRaw = navigator.userAgent;
|
|
2978
|
-
if (!navigator.userAgentData || !navigator.userAgentData.getHighEntropyValues) {
|
|
2979
|
-
return uaRaw;
|
|
2980
|
-
}
|
|
2981
|
-
const uaData = navigator.userAgentData;
|
|
2982
|
-
let uaGot = null;
|
|
2983
|
-
try {
|
|
2984
|
-
uaGot = yield uaData.getHighEntropyValues(["platformVersion"]);
|
|
2985
|
-
} catch (err) {
|
|
2986
|
-
console.error(err);
|
|
2987
|
-
return uaRaw;
|
|
2988
|
-
}
|
|
2989
|
-
const majorPlatformVersion = Number(uaGot.platformVersion.split(".")[0]);
|
|
2990
|
-
if (uaData.platform === "Windows") {
|
|
2991
|
-
if (majorPlatformVersion >= 13) {
|
|
2992
|
-
return uaRaw.replace(/Windows NT 10.0/, "Windows NT 11.0");
|
|
2993
|
-
}
|
|
2994
|
-
}
|
|
2995
|
-
if (uaData.platform === "macOS") {
|
|
2996
|
-
if (majorPlatformVersion >= 11) {
|
|
2997
|
-
return uaRaw.replace(
|
|
2998
|
-
/(Mac OS X \d+_\d+_\d+|Mac OS X)/,
|
|
2999
|
-
`Mac OS X ${uaGot.platformVersion.replace(/\./g, "_")}`
|
|
3000
|
-
);
|
|
3001
|
-
}
|
|
3002
|
-
}
|
|
3003
|
-
return uaRaw;
|
|
3004
|
-
});
|
|
3005
|
-
}
|
|
3006
|
-
function isValidURL(urlRaw) {
|
|
3007
|
-
let url;
|
|
3008
|
-
try {
|
|
3009
|
-
url = new URL(urlRaw);
|
|
3010
|
-
} catch (_) {
|
|
3011
|
-
return false;
|
|
3012
|
-
}
|
|
3013
|
-
return url.protocol === "http:" || url.protocol === "https:";
|
|
3014
|
-
}
|
|
3015
|
-
function getURLBasedOnApi(opts) {
|
|
3016
|
-
return getURLBasedOn(opts.base, opts.path);
|
|
3017
|
-
}
|
|
3018
|
-
function getURLBasedOn(baseURL, path) {
|
|
3019
|
-
return `${baseURL.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
|
|
3020
|
-
}
|
|
3021
3022
|
const internal = {
|
|
3022
3023
|
en,
|
|
3023
3024
|
"en-US": en,
|
|
@@ -3101,11 +3102,12 @@ const defaults = {
|
|
|
3101
3102
|
uaBadge: true,
|
|
3102
3103
|
listSort: true,
|
|
3103
3104
|
preview: true,
|
|
3104
|
-
countEl: "
|
|
3105
|
-
pvEl: "
|
|
3105
|
+
countEl: ".artalk-comment-count",
|
|
3106
|
+
pvEl: ".artalk-pv-count",
|
|
3107
|
+
statPageKeyAttr: "data-page-key",
|
|
3106
3108
|
gravatar: {
|
|
3107
|
-
mirror: "https://
|
|
3108
|
-
params: "d=mp&s=240"
|
|
3109
|
+
mirror: "https://www.gravatar.com/avatar/",
|
|
3110
|
+
params: "sha256=1&d=mp&s=240"
|
|
3109
3111
|
},
|
|
3110
3112
|
pagination: {
|
|
3111
3113
|
pageSize: 20,
|
|
@@ -3151,9 +3153,18 @@ function handelCustomConf(customConf, full = false) {
|
|
|
3151
3153
|
return conf;
|
|
3152
3154
|
}
|
|
3153
3155
|
function handleConfFormServer(conf) {
|
|
3154
|
-
const
|
|
3156
|
+
const ExcludedKeys = [
|
|
3157
|
+
"el",
|
|
3158
|
+
"pageKey",
|
|
3159
|
+
"pageTitle",
|
|
3160
|
+
"server",
|
|
3161
|
+
"site",
|
|
3162
|
+
"pvEl",
|
|
3163
|
+
"countEl",
|
|
3164
|
+
"statPageKeyAttr"
|
|
3165
|
+
];
|
|
3155
3166
|
Object.keys(conf).forEach((k) => {
|
|
3156
|
-
if (
|
|
3167
|
+
if (ExcludedKeys.includes(k))
|
|
3157
3168
|
delete conf[k];
|
|
3158
3169
|
if (k === "darkMode" && conf[k] !== "auto")
|
|
3159
3170
|
delete conf[k];
|
|
@@ -3332,50 +3343,6 @@ class Context {
|
|
|
3332
3343
|
watchConf(this, keys, effect);
|
|
3333
3344
|
}
|
|
3334
3345
|
}
|
|
3335
|
-
class Dialog {
|
|
3336
|
-
constructor(contentEl) {
|
|
3337
|
-
__publicField(this, "$el");
|
|
3338
|
-
__publicField(this, "$content");
|
|
3339
|
-
__publicField(this, "$actions");
|
|
3340
|
-
this.$el = createElement(
|
|
3341
|
-
`<div class="atk-layer-dialog-wrap">
|
|
3342
|
-
<div class="atk-layer-dialog">
|
|
3343
|
-
<div class="atk-layer-dialog-content"></div>
|
|
3344
|
-
<div class="atk-layer-dialog-actions"></div>
|
|
3345
|
-
</div>
|
|
3346
|
-
</div>`
|
|
3347
|
-
);
|
|
3348
|
-
this.$actions = this.$el.querySelector(".atk-layer-dialog-actions");
|
|
3349
|
-
this.$content = this.$el.querySelector(".atk-layer-dialog-content");
|
|
3350
|
-
this.$content.appendChild(contentEl);
|
|
3351
|
-
}
|
|
3352
|
-
/** 按钮 · 确定 */
|
|
3353
|
-
setYes(handler) {
|
|
3354
|
-
const btn = createElement(
|
|
3355
|
-
`<button data-action="confirm">${t("confirm")}</button>`
|
|
3356
|
-
);
|
|
3357
|
-
btn.onclick = this.onBtnClick(handler);
|
|
3358
|
-
this.$actions.appendChild(btn);
|
|
3359
|
-
return this;
|
|
3360
|
-
}
|
|
3361
|
-
/** 按钮 · 取消 */
|
|
3362
|
-
setNo(handler) {
|
|
3363
|
-
const btn = createElement(
|
|
3364
|
-
`<button data-action="cancel">${t("cancel")}</button>`
|
|
3365
|
-
);
|
|
3366
|
-
btn.onclick = this.onBtnClick(handler);
|
|
3367
|
-
this.$actions.appendChild(btn);
|
|
3368
|
-
return this;
|
|
3369
|
-
}
|
|
3370
|
-
onBtnClick(handler) {
|
|
3371
|
-
return (evt) => {
|
|
3372
|
-
const re = handler(evt.currentTarget, this);
|
|
3373
|
-
if (re === void 0 || re === true) {
|
|
3374
|
-
this.$el.remove();
|
|
3375
|
-
}
|
|
3376
|
-
};
|
|
3377
|
-
}
|
|
3378
|
-
}
|
|
3379
3346
|
function showLoading(parentElem, conf) {
|
|
3380
3347
|
let $loading = parentElem.querySelector(":scope > .atk-loading");
|
|
3381
3348
|
if (!$loading) {
|
|
@@ -3621,6 +3588,50 @@ const AdminChecker = {
|
|
|
3621
3588
|
onError(checker, err, inputVal, formEl) {
|
|
3622
3589
|
}
|
|
3623
3590
|
};
|
|
3591
|
+
class Dialog {
|
|
3592
|
+
constructor(contentEl) {
|
|
3593
|
+
__publicField(this, "$el");
|
|
3594
|
+
__publicField(this, "$content");
|
|
3595
|
+
__publicField(this, "$actions");
|
|
3596
|
+
this.$el = createElement(
|
|
3597
|
+
`<div class="atk-layer-dialog-wrap">
|
|
3598
|
+
<div class="atk-layer-dialog">
|
|
3599
|
+
<div class="atk-layer-dialog-content"></div>
|
|
3600
|
+
<div class="atk-layer-dialog-actions"></div>
|
|
3601
|
+
</div>
|
|
3602
|
+
</div>`
|
|
3603
|
+
);
|
|
3604
|
+
this.$actions = this.$el.querySelector(".atk-layer-dialog-actions");
|
|
3605
|
+
this.$content = this.$el.querySelector(".atk-layer-dialog-content");
|
|
3606
|
+
this.$content.appendChild(contentEl);
|
|
3607
|
+
}
|
|
3608
|
+
/** 按钮 · 确定 */
|
|
3609
|
+
setYes(handler) {
|
|
3610
|
+
const btn = createElement(
|
|
3611
|
+
`<button data-action="confirm">${t("confirm")}</button>`
|
|
3612
|
+
);
|
|
3613
|
+
btn.onclick = this.onBtnClick(handler);
|
|
3614
|
+
this.$actions.appendChild(btn);
|
|
3615
|
+
return this;
|
|
3616
|
+
}
|
|
3617
|
+
/** 按钮 · 取消 */
|
|
3618
|
+
setNo(handler) {
|
|
3619
|
+
const btn = createElement(
|
|
3620
|
+
`<button data-action="cancel">${t("cancel")}</button>`
|
|
3621
|
+
);
|
|
3622
|
+
btn.onclick = this.onBtnClick(handler);
|
|
3623
|
+
this.$actions.appendChild(btn);
|
|
3624
|
+
return this;
|
|
3625
|
+
}
|
|
3626
|
+
onBtnClick(handler) {
|
|
3627
|
+
return (evt) => {
|
|
3628
|
+
const re = handler(evt.currentTarget, this);
|
|
3629
|
+
if (re === void 0 || re === true) {
|
|
3630
|
+
this.$el.remove();
|
|
3631
|
+
}
|
|
3632
|
+
};
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3624
3635
|
function wrapPromise(fn) {
|
|
3625
3636
|
return (payload) => new Promise((resolve, reject) => {
|
|
3626
3637
|
const cancelFn = payload.onCancel;
|
|
@@ -4450,7 +4461,10 @@ function check(conf, rules) {
|
|
|
4450
4461
|
};
|
|
4451
4462
|
_check();
|
|
4452
4463
|
if (imgCheck) {
|
|
4453
|
-
el.querySelectorAll(".atk-content img")
|
|
4464
|
+
const imgs = el.querySelectorAll(".atk-content img");
|
|
4465
|
+
if (imgs.length === 0)
|
|
4466
|
+
el.style.maxHeight = "";
|
|
4467
|
+
imgs.forEach((img) => {
|
|
4454
4468
|
img.onload = () => _check();
|
|
4455
4469
|
});
|
|
4456
4470
|
}
|
|
@@ -5248,7 +5262,7 @@ class CommentNode {
|
|
|
5248
5262
|
return getGravatarURL({
|
|
5249
5263
|
mirror: this.opts.gravatar.mirror,
|
|
5250
5264
|
params: this.opts.gravatar.params,
|
|
5251
|
-
|
|
5265
|
+
emailHash: this.data.email_encrypted
|
|
5252
5266
|
});
|
|
5253
5267
|
}
|
|
5254
5268
|
/** 获取评论 markdown 解析后的内容 */
|
|
@@ -5943,7 +5957,7 @@ const services = {
|
|
|
5943
5957
|
}
|
|
5944
5958
|
};
|
|
5945
5959
|
const PvCountWidget = (ctx) => {
|
|
5946
|
-
ctx.watchConf(["site", "pageKey", "pageTitle", "countEl", "pvEl"], (conf) => {
|
|
5960
|
+
ctx.watchConf(["site", "pageKey", "pageTitle", "countEl", "pvEl", "statPageKeyAttr"], (conf) => {
|
|
5947
5961
|
initCountWidget({
|
|
5948
5962
|
getApi: () => ctx.getApi(),
|
|
5949
5963
|
siteName: conf.site,
|
|
@@ -5951,81 +5965,85 @@ const PvCountWidget = (ctx) => {
|
|
|
5951
5965
|
pageTitle: conf.pageTitle,
|
|
5952
5966
|
countEl: conf.countEl,
|
|
5953
5967
|
pvEl: conf.pvEl,
|
|
5968
|
+
pageKeyAttr: conf.statPageKeyAttr,
|
|
5954
5969
|
pvAdd: typeof ctx.conf.pvAdd === "boolean" ? ctx.conf.pvAdd : true
|
|
5955
5970
|
});
|
|
5956
5971
|
});
|
|
5957
5972
|
};
|
|
5958
5973
|
function initCountWidget(opt) {
|
|
5959
5974
|
return __async(this, null, function* () {
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
const initialData = opt.pvAdd && opt.pageKey ? {
|
|
5964
|
-
[opt.pageKey]: (yield opt.getApi().pages.logPv({
|
|
5965
|
-
page_key: opt.pageKey,
|
|
5966
|
-
page_title: opt.pageTitle,
|
|
5967
|
-
site_name: opt.siteName
|
|
5968
|
-
})).data.pv
|
|
5969
|
-
// pv+1 and get pv count
|
|
5970
|
-
} : void 0;
|
|
5971
|
-
if (opt.pvEl && document.querySelector(opt.pvEl)) {
|
|
5972
|
-
refreshStatCount(opt, {
|
|
5973
|
-
query: "page_pv",
|
|
5974
|
-
numEl: opt.pvEl,
|
|
5975
|
-
data: initialData
|
|
5976
|
-
});
|
|
5977
|
-
}
|
|
5975
|
+
yield loadCommentCount(opt);
|
|
5976
|
+
const cacheData = yield incrementPvCount(opt);
|
|
5977
|
+
yield loadPvCount(opt, cacheData);
|
|
5978
5978
|
});
|
|
5979
5979
|
}
|
|
5980
|
-
function
|
|
5980
|
+
function incrementPvCount(opt) {
|
|
5981
5981
|
return __async(this, null, function* () {
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5982
|
+
if (!opt.pvAdd || !opt.pageKey)
|
|
5983
|
+
return void 0;
|
|
5984
|
+
const pvCount = (yield opt.getApi().pages.logPv({
|
|
5985
|
+
page_key: opt.pageKey,
|
|
5986
|
+
page_title: opt.pageTitle,
|
|
5987
|
+
site_name: opt.siteName
|
|
5988
|
+
})).data.pv;
|
|
5989
|
+
return {
|
|
5990
|
+
[opt.pageKey]: pvCount
|
|
5991
|
+
};
|
|
5992
|
+
});
|
|
5993
|
+
}
|
|
5994
|
+
function loadCommentCount(opt) {
|
|
5995
|
+
return __async(this, null, function* () {
|
|
5996
|
+
yield loadStatCount({ opt, query: "page_comment", containers: [opt.countEl, "#ArtalkCount"] });
|
|
5997
|
+
});
|
|
5998
|
+
}
|
|
5999
|
+
function loadPvCount(opt, cache) {
|
|
6000
|
+
return __async(this, null, function* () {
|
|
6001
|
+
yield loadStatCount({ opt, query: "page_pv", containers: [opt.pvEl, "#ArtalkPv"], cache });
|
|
6002
|
+
});
|
|
6003
|
+
}
|
|
6004
|
+
function loadStatCount(args) {
|
|
6005
|
+
return __async(this, null, function* () {
|
|
6006
|
+
const { opt } = args;
|
|
6007
|
+
let cache = args.cache || {};
|
|
6008
|
+
const els = retrieveElements(args.containers);
|
|
6009
|
+
const pageKeys = getPageKeys(els, opt.pageKeyAttr, opt.pageKey, cache);
|
|
6010
|
+
if (pageKeys.length > 0) {
|
|
5986
6011
|
const res = (yield opt.getApi().stats.getStats(args.query, {
|
|
5987
|
-
page_keys:
|
|
6012
|
+
page_keys: pageKeys.join(","),
|
|
5988
6013
|
site_name: opt.siteName
|
|
5989
6014
|
})).data.data;
|
|
5990
|
-
|
|
6015
|
+
cache = __spreadValues(__spreadValues({}, cache), res);
|
|
5991
6016
|
}
|
|
5992
|
-
|
|
5993
|
-
applyCountData(args.numEl, data, defaultCount);
|
|
6017
|
+
updateElementsText(els, cache, opt.pageKey);
|
|
5994
6018
|
});
|
|
5995
6019
|
}
|
|
5996
|
-
function
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
el.innerHTML = `${count}`;
|
|
6020
|
+
function retrieveElements(containers) {
|
|
6021
|
+
const els = /* @__PURE__ */ new Set();
|
|
6022
|
+
new Set(containers).forEach((selector) => {
|
|
6023
|
+
document.querySelectorAll(selector).forEach((el) => els.add(el));
|
|
6001
6024
|
});
|
|
6025
|
+
return els;
|
|
6002
6026
|
}
|
|
6003
|
-
function
|
|
6004
|
-
const
|
|
6005
|
-
|
|
6006
|
-
|
|
6007
|
-
|
|
6008
|
-
|
|
6009
|
-
|
|
6010
|
-
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
const $openSidebar = createElement(
|
|
6014
|
-
`<span atk-only-admin-show> | <span style="cursor:pointer;">${t("openName", { name: t("ctrlCenter") })}</span></span>`
|
|
6015
|
-
);
|
|
6016
|
-
errEl.appendChild($openSidebar);
|
|
6017
|
-
$openSidebar.onclick = () => opts.onOpenSidebar && opts.onOpenSidebar();
|
|
6018
|
-
}
|
|
6019
|
-
setError(opts.$err, errEl);
|
|
6027
|
+
function getPageKeys(els, pageKeyAttr, pageKey, cache) {
|
|
6028
|
+
const pageKeys = Array.from(els).map((el) => el.getAttribute(pageKeyAttr) || pageKey).filter((key) => key && typeof cache[key] !== "number");
|
|
6029
|
+
return [...new Set(pageKeys)];
|
|
6030
|
+
}
|
|
6031
|
+
function updateElementsText(els, data, defaultPageKey) {
|
|
6032
|
+
els.forEach((el) => {
|
|
6033
|
+
const pageKey = el.getAttribute("data-page-key");
|
|
6034
|
+
const count = pageKey && data[pageKey] || defaultPageKey && data[defaultPageKey] || 0;
|
|
6035
|
+
el.innerText = `${Number(count)}`;
|
|
6036
|
+
});
|
|
6020
6037
|
}
|
|
6021
6038
|
const Markdown = (ctx) => {
|
|
6022
|
-
ctx.watchConf(["
|
|
6039
|
+
ctx.watchConf(["imgLazyLoad", "markedOptions"], (conf) => {
|
|
6023
6040
|
initMarked({
|
|
6024
6041
|
markedOptions: ctx.getConf().markedOptions,
|
|
6025
6042
|
imgLazyLoad: ctx.getConf().imgLazyLoad
|
|
6026
6043
|
});
|
|
6027
|
-
|
|
6028
|
-
|
|
6044
|
+
});
|
|
6045
|
+
ctx.watchConf(["markedReplacers"], (conf) => {
|
|
6046
|
+
conf.markedReplacers && setReplacers(conf.markedReplacers);
|
|
6029
6047
|
});
|
|
6030
6048
|
};
|
|
6031
6049
|
const LocalStorageKey = "ArtalkContent";
|
|
@@ -7262,7 +7280,7 @@ const GotoFocus = (ctx) => {
|
|
|
7262
7280
|
comment.focus();
|
|
7263
7281
|
}));
|
|
7264
7282
|
};
|
|
7265
|
-
const version = "2.8.
|
|
7283
|
+
const version = "2.8.7";
|
|
7266
7284
|
const Copyright = (ctx) => {
|
|
7267
7285
|
ctx.on("mounted", () => {
|
|
7268
7286
|
const list = ctx.get("list");
|
|
@@ -7367,8 +7385,7 @@ function renderDropdown(conf) {
|
|
|
7367
7385
|
};
|
|
7368
7386
|
const $dropdown = createElement(`<ul class="atk-dropdown atk-fade-in"></ul>`);
|
|
7369
7387
|
dropdownList.forEach((item, i) => {
|
|
7370
|
-
const name = item
|
|
7371
|
-
const action = item[1];
|
|
7388
|
+
const [name, action] = item;
|
|
7372
7389
|
const $item = createElement(`<li class="atk-dropdown-item"><span></span></li>`);
|
|
7373
7390
|
const $link = $item.querySelector("span");
|
|
7374
7391
|
$link.innerText = name;
|
|
@@ -7403,6 +7420,24 @@ const TimeTicking = (ctx) => {
|
|
|
7403
7420
|
timer && window.clearInterval(timer);
|
|
7404
7421
|
});
|
|
7405
7422
|
};
|
|
7423
|
+
function showErrorDialog(opts) {
|
|
7424
|
+
const errEl = createElement(`<span><span class="error-message"></span><br/><br/></span>`);
|
|
7425
|
+
errEl.querySelector(".error-message").innerText = `${t("listLoadFailMsg")}
|
|
7426
|
+
${opts.errMsg}`;
|
|
7427
|
+
if (opts.retryFn) {
|
|
7428
|
+
const $retryBtn = createElement(`<span style="cursor:pointer;">${t("listRetry")}</span>`);
|
|
7429
|
+
$retryBtn.onclick = () => opts.retryFn && opts.retryFn();
|
|
7430
|
+
errEl.appendChild($retryBtn);
|
|
7431
|
+
}
|
|
7432
|
+
if (opts.onOpenSidebar) {
|
|
7433
|
+
const $openSidebar = createElement(
|
|
7434
|
+
`<span atk-only-admin-show> | <span style="cursor:pointer;">${t("openName", { name: t("ctrlCenter") })}</span></span>`
|
|
7435
|
+
);
|
|
7436
|
+
errEl.appendChild($openSidebar);
|
|
7437
|
+
$openSidebar.onclick = () => opts.onOpenSidebar && opts.onOpenSidebar();
|
|
7438
|
+
}
|
|
7439
|
+
setError(opts.$err, errEl);
|
|
7440
|
+
}
|
|
7406
7441
|
const ErrorDialog = (ctx) => {
|
|
7407
7442
|
ctx.on("list-fetch", () => {
|
|
7408
7443
|
const list = ctx.get("list");
|
|
@@ -7667,16 +7702,16 @@ const DefaultPlugins = [
|
|
|
7667
7702
|
VersionCheck,
|
|
7668
7703
|
DarkMode
|
|
7669
7704
|
];
|
|
7670
|
-
const GlobalPlugins = [...DefaultPlugins];
|
|
7705
|
+
const GlobalPlugins = /* @__PURE__ */ new Set([...DefaultPlugins]);
|
|
7671
7706
|
function load(ctx) {
|
|
7672
7707
|
return __async(this, null, function* () {
|
|
7673
7708
|
var _a;
|
|
7674
|
-
const loadedPlugins =
|
|
7709
|
+
const loadedPlugins = /* @__PURE__ */ new Set();
|
|
7675
7710
|
const loadPlugins = (plugins) => {
|
|
7676
7711
|
plugins.forEach((plugin) => {
|
|
7677
|
-
if (typeof plugin === "function" && !loadedPlugins.
|
|
7712
|
+
if (typeof plugin === "function" && !loadedPlugins.has(plugin)) {
|
|
7678
7713
|
plugin(ctx);
|
|
7679
|
-
loadedPlugins.
|
|
7714
|
+
loadedPlugins.add(plugin);
|
|
7680
7715
|
}
|
|
7681
7716
|
});
|
|
7682
7717
|
};
|
|
@@ -7712,8 +7747,9 @@ function load(ctx) {
|
|
|
7712
7747
|
}
|
|
7713
7748
|
function loadNetworkPlugins(scripts, apiBase) {
|
|
7714
7749
|
return __async(this, null, function* () {
|
|
7750
|
+
const networkPlugins = /* @__PURE__ */ new Set();
|
|
7715
7751
|
if (!scripts || !Array.isArray(scripts))
|
|
7716
|
-
return
|
|
7752
|
+
return networkPlugins;
|
|
7717
7753
|
const tasks = [];
|
|
7718
7754
|
scripts.forEach((url) => {
|
|
7719
7755
|
if (!/^(http|https):\/\//.test(url))
|
|
@@ -7733,7 +7769,11 @@ function loadNetworkPlugins(scripts, apiBase) {
|
|
|
7733
7769
|
);
|
|
7734
7770
|
});
|
|
7735
7771
|
yield Promise.all(tasks);
|
|
7736
|
-
|
|
7772
|
+
Object.values(window.ArtalkPlugins || {}).forEach((plugin) => {
|
|
7773
|
+
if (typeof plugin === "function")
|
|
7774
|
+
networkPlugins.add(plugin);
|
|
7775
|
+
});
|
|
7776
|
+
return networkPlugins;
|
|
7737
7777
|
});
|
|
7738
7778
|
}
|
|
7739
7779
|
function onLoadErr(ctx, err) {
|
|
@@ -7819,9 +7859,7 @@ class Artalk {
|
|
|
7819
7859
|
}
|
|
7820
7860
|
/** Use plugin, the plugin will be used when Artalk.init */
|
|
7821
7861
|
static use(plugin) {
|
|
7822
|
-
|
|
7823
|
-
return;
|
|
7824
|
-
GlobalPlugins.push(plugin);
|
|
7862
|
+
GlobalPlugins.add(plugin);
|
|
7825
7863
|
}
|
|
7826
7864
|
/** Load count widget */
|
|
7827
7865
|
static loadCountWidget(c) {
|
|
@@ -7831,6 +7869,7 @@ class Artalk {
|
|
|
7831
7869
|
siteName: conf.site,
|
|
7832
7870
|
countEl: conf.countEl,
|
|
7833
7871
|
pvEl: conf.pvEl,
|
|
7872
|
+
pageKeyAttr: conf.statPageKeyAttr,
|
|
7834
7873
|
pvAdd: false
|
|
7835
7874
|
});
|
|
7836
7875
|
}
|