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.mjs CHANGED
@@ -4685,6 +4685,157 @@ class DataManager {
4685
4685
  this.events.trigger("page-loaded", pageData);
4686
4686
  }
4687
4687
  }
4688
+ function createElement(htmlStr = "") {
4689
+ const div = document.createElement("div");
4690
+ div.innerHTML = htmlStr.trim();
4691
+ return div.firstElementChild || div;
4692
+ }
4693
+ function getHeight(el) {
4694
+ const num = parseFloat(getComputedStyle(el, null).height.replace("px", ""));
4695
+ return num || 0;
4696
+ }
4697
+ function htmlEncode(str) {
4698
+ const temp = document.createElement("div");
4699
+ temp.innerText = str;
4700
+ const output = temp.innerHTML;
4701
+ return output;
4702
+ }
4703
+ function getQueryParam(name) {
4704
+ const match = RegExp(`[?&]${name}=([^&]*)`).exec(window.location.search);
4705
+ return match && decodeURIComponent(match[1].replace(/\+/g, " "));
4706
+ }
4707
+ function getOffset(el, relativeTo) {
4708
+ const getOffsetRecursive = (element) => {
4709
+ const rect = element.getBoundingClientRect();
4710
+ const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
4711
+ const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
4712
+ return {
4713
+ top: rect.top + scrollTop,
4714
+ left: rect.left + scrollLeft
4715
+ };
4716
+ };
4717
+ const elOffset = getOffsetRecursive(el);
4718
+ if (!relativeTo)
4719
+ return elOffset;
4720
+ const relativeToOffset = getOffsetRecursive(relativeTo);
4721
+ return {
4722
+ top: elOffset.top - relativeToOffset.top,
4723
+ left: elOffset.left - relativeToOffset.left
4724
+ };
4725
+ }
4726
+ function padWithZeros(vNumber, width) {
4727
+ let numAsString = vNumber.toString();
4728
+ while (numAsString.length < width) {
4729
+ numAsString = `0${numAsString}`;
4730
+ }
4731
+ return numAsString;
4732
+ }
4733
+ function dateFormat(date) {
4734
+ const vDay = padWithZeros(date.getDate(), 2);
4735
+ const vMonth = padWithZeros(date.getMonth() + 1, 2);
4736
+ const vYear = padWithZeros(date.getFullYear(), 2);
4737
+ return `${vYear}-${vMonth}-${vDay}`;
4738
+ }
4739
+ function timeAgo(date, $t = (n) => n) {
4740
+ try {
4741
+ const oldTime = date.getTime();
4742
+ const currTime = (/* @__PURE__ */ new Date()).getTime();
4743
+ const diffValue = currTime - oldTime;
4744
+ const days = Math.floor(diffValue / (24 * 3600 * 1e3));
4745
+ if (days === 0) {
4746
+ const leave1 = diffValue % (24 * 3600 * 1e3);
4747
+ const hours = Math.floor(leave1 / (3600 * 1e3));
4748
+ if (hours === 0) {
4749
+ const leave2 = leave1 % (3600 * 1e3);
4750
+ const minutes = Math.floor(leave2 / (60 * 1e3));
4751
+ if (minutes === 0) {
4752
+ const leave3 = leave2 % (60 * 1e3);
4753
+ const seconds = Math.round(leave3 / 1e3);
4754
+ if (seconds < 10)
4755
+ return $t("now");
4756
+ return `${seconds} ${$t("seconds")}`;
4757
+ }
4758
+ return `${minutes} ${$t("minutes")}`;
4759
+ }
4760
+ return `${hours} ${$t("hours")}`;
4761
+ }
4762
+ if (days < 0)
4763
+ return $t("now");
4764
+ if (days < 8) {
4765
+ return `${days} ${$t("days")}`;
4766
+ }
4767
+ return dateFormat(date);
4768
+ } catch (error) {
4769
+ console.error(error);
4770
+ return " - ";
4771
+ }
4772
+ }
4773
+ function getGravatarURL(opts) {
4774
+ return `${opts.mirror.replace(/\/$/, "")}/${opts.emailHash}?${opts.params.replace(/^\?/, "")}`;
4775
+ }
4776
+ function versionCompare(a, b) {
4777
+ const pa = a.split(".");
4778
+ const pb = b.split(".");
4779
+ for (let i = 0; i < 3; i++) {
4780
+ const na = Number(pa[i]);
4781
+ const nb = Number(pb[i]);
4782
+ if (na > nb)
4783
+ return 1;
4784
+ if (nb > na)
4785
+ return -1;
4786
+ if (!Number.isNaN(na) && Number.isNaN(nb))
4787
+ return 1;
4788
+ if (Number.isNaN(na) && !Number.isNaN(nb))
4789
+ return -1;
4790
+ }
4791
+ return 0;
4792
+ }
4793
+ function getCorrectUserAgent() {
4794
+ return __async(this, null, function* () {
4795
+ const uaRaw = navigator.userAgent;
4796
+ if (!navigator.userAgentData || !navigator.userAgentData.getHighEntropyValues) {
4797
+ return uaRaw;
4798
+ }
4799
+ const uaData = navigator.userAgentData;
4800
+ let uaGot = null;
4801
+ try {
4802
+ uaGot = yield uaData.getHighEntropyValues(["platformVersion"]);
4803
+ } catch (err) {
4804
+ console.error(err);
4805
+ return uaRaw;
4806
+ }
4807
+ const majorPlatformVersion = Number(uaGot.platformVersion.split(".")[0]);
4808
+ if (uaData.platform === "Windows") {
4809
+ if (majorPlatformVersion >= 13) {
4810
+ return uaRaw.replace(/Windows NT 10.0/, "Windows NT 11.0");
4811
+ }
4812
+ }
4813
+ if (uaData.platform === "macOS") {
4814
+ if (majorPlatformVersion >= 11) {
4815
+ return uaRaw.replace(
4816
+ /(Mac OS X \d+_\d+_\d+|Mac OS X)/,
4817
+ `Mac OS X ${uaGot.platformVersion.replace(/\./g, "_")}`
4818
+ );
4819
+ }
4820
+ }
4821
+ return uaRaw;
4822
+ });
4823
+ }
4824
+ function isValidURL(urlRaw) {
4825
+ let url;
4826
+ try {
4827
+ url = new URL(urlRaw);
4828
+ } catch (_) {
4829
+ return false;
4830
+ }
4831
+ return url.protocol === "http:" || url.protocol === "https:";
4832
+ }
4833
+ function getURLBasedOnApi(opts) {
4834
+ return getURLBasedOn(opts.base, opts.path);
4835
+ }
4836
+ function getURLBasedOn(baseURL, path) {
4837
+ return `${baseURL.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
4838
+ }
4688
4839
  const en = {
4689
4840
  /* Editor */
4690
4841
  placeholder: "Leave a comment",
@@ -4890,156 +5041,6 @@ const zhCN = {
4890
5041
  openName: "打开{name}"
4891
5042
  };
4892
5043
  const GLOBAL_LOCALES_KEY = "ArtalkI18n";
4893
- function createElement(htmlStr = "") {
4894
- const div = document.createElement("div");
4895
- div.innerHTML = htmlStr.trim();
4896
- return div.firstElementChild || div;
4897
- }
4898
- function getHeight(el) {
4899
- return parseFloat(getComputedStyle(el, null).height.replace("px", ""));
4900
- }
4901
- function htmlEncode(str) {
4902
- const temp = document.createElement("div");
4903
- temp.innerText = str;
4904
- const output = temp.innerHTML;
4905
- return output;
4906
- }
4907
- function getQueryParam(name) {
4908
- const match = RegExp(`[?&]${name}=([^&]*)`).exec(window.location.search);
4909
- return match && decodeURIComponent(match[1].replace(/\+/g, " "));
4910
- }
4911
- function getOffset(el, relativeTo) {
4912
- const getOffsetRecursive = (element) => {
4913
- const rect = element.getBoundingClientRect();
4914
- const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
4915
- const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
4916
- return {
4917
- top: rect.top + scrollTop,
4918
- left: rect.left + scrollLeft
4919
- };
4920
- };
4921
- const elOffset = getOffsetRecursive(el);
4922
- if (!relativeTo)
4923
- return elOffset;
4924
- const relativeToOffset = getOffsetRecursive(relativeTo);
4925
- return {
4926
- top: elOffset.top - relativeToOffset.top,
4927
- left: elOffset.left - relativeToOffset.left
4928
- };
4929
- }
4930
- function padWithZeros(vNumber, width) {
4931
- let numAsString = vNumber.toString();
4932
- while (numAsString.length < width) {
4933
- numAsString = `0${numAsString}`;
4934
- }
4935
- return numAsString;
4936
- }
4937
- function dateFormat(date) {
4938
- const vDay = padWithZeros(date.getDate(), 2);
4939
- const vMonth = padWithZeros(date.getMonth() + 1, 2);
4940
- const vYear = padWithZeros(date.getFullYear(), 2);
4941
- return `${vYear}-${vMonth}-${vDay}`;
4942
- }
4943
- function timeAgo(date, $t = (n) => n) {
4944
- try {
4945
- const oldTime = date.getTime();
4946
- const currTime = (/* @__PURE__ */ new Date()).getTime();
4947
- const diffValue = currTime - oldTime;
4948
- const days = Math.floor(diffValue / (24 * 3600 * 1e3));
4949
- if (days === 0) {
4950
- const leave1 = diffValue % (24 * 3600 * 1e3);
4951
- const hours = Math.floor(leave1 / (3600 * 1e3));
4952
- if (hours === 0) {
4953
- const leave2 = leave1 % (3600 * 1e3);
4954
- const minutes = Math.floor(leave2 / (60 * 1e3));
4955
- if (minutes === 0) {
4956
- const leave3 = leave2 % (60 * 1e3);
4957
- const seconds = Math.round(leave3 / 1e3);
4958
- if (seconds < 10)
4959
- return $t("now");
4960
- return `${seconds} ${$t("seconds")}`;
4961
- }
4962
- return `${minutes} ${$t("minutes")}`;
4963
- }
4964
- return `${hours} ${$t("hours")}`;
4965
- }
4966
- if (days < 0)
4967
- return $t("now");
4968
- if (days < 8) {
4969
- return `${days} ${$t("days")}`;
4970
- }
4971
- return dateFormat(date);
4972
- } catch (error) {
4973
- console.error(error);
4974
- return " - ";
4975
- }
4976
- }
4977
- function getGravatarURL(opts) {
4978
- return `${opts.mirror.replace(/\/$/, "")}/${opts.emailMD5}?${opts.params.replace(/^\?/, "")}`;
4979
- }
4980
- function versionCompare(a, b) {
4981
- const pa = a.split(".");
4982
- const pb = b.split(".");
4983
- for (let i = 0; i < 3; i++) {
4984
- const na = Number(pa[i]);
4985
- const nb = Number(pb[i]);
4986
- if (na > nb)
4987
- return 1;
4988
- if (nb > na)
4989
- return -1;
4990
- if (!Number.isNaN(na) && Number.isNaN(nb))
4991
- return 1;
4992
- if (Number.isNaN(na) && !Number.isNaN(nb))
4993
- return -1;
4994
- }
4995
- return 0;
4996
- }
4997
- function getCorrectUserAgent() {
4998
- return __async(this, null, function* () {
4999
- const uaRaw = navigator.userAgent;
5000
- if (!navigator.userAgentData || !navigator.userAgentData.getHighEntropyValues) {
5001
- return uaRaw;
5002
- }
5003
- const uaData = navigator.userAgentData;
5004
- let uaGot = null;
5005
- try {
5006
- uaGot = yield uaData.getHighEntropyValues(["platformVersion"]);
5007
- } catch (err) {
5008
- console.error(err);
5009
- return uaRaw;
5010
- }
5011
- const majorPlatformVersion = Number(uaGot.platformVersion.split(".")[0]);
5012
- if (uaData.platform === "Windows") {
5013
- if (majorPlatformVersion >= 13) {
5014
- return uaRaw.replace(/Windows NT 10.0/, "Windows NT 11.0");
5015
- }
5016
- }
5017
- if (uaData.platform === "macOS") {
5018
- if (majorPlatformVersion >= 11) {
5019
- return uaRaw.replace(
5020
- /(Mac OS X \d+_\d+_\d+|Mac OS X)/,
5021
- `Mac OS X ${uaGot.platformVersion.replace(/\./g, "_")}`
5022
- );
5023
- }
5024
- }
5025
- return uaRaw;
5026
- });
5027
- }
5028
- function isValidURL(urlRaw) {
5029
- let url;
5030
- try {
5031
- url = new URL(urlRaw);
5032
- } catch (_) {
5033
- return false;
5034
- }
5035
- return url.protocol === "http:" || url.protocol === "https:";
5036
- }
5037
- function getURLBasedOnApi(opts) {
5038
- return getURLBasedOn(opts.base, opts.path);
5039
- }
5040
- function getURLBasedOn(baseURL, path) {
5041
- return `${baseURL.replace(/\/$/, "")}/${path.replace(/^\//, "")}`;
5042
- }
5043
5044
  const internal = {
5044
5045
  en,
5045
5046
  "en-US": en,
@@ -5123,11 +5124,12 @@ const defaults = {
5123
5124
  uaBadge: true,
5124
5125
  listSort: true,
5125
5126
  preview: true,
5126
- countEl: "#ArtalkCount",
5127
- pvEl: "#ArtalkPV",
5127
+ countEl: ".artalk-comment-count",
5128
+ pvEl: ".artalk-pv-count",
5129
+ statPageKeyAttr: "data-page-key",
5128
5130
  gravatar: {
5129
- mirror: "https://cravatar.cn/avatar/",
5130
- params: "d=mp&s=240"
5131
+ mirror: "https://www.gravatar.com/avatar/",
5132
+ params: "sha256=1&d=mp&s=240"
5131
5133
  },
5132
5134
  pagination: {
5133
5135
  pageSize: 20,
@@ -5173,9 +5175,18 @@ function handelCustomConf(customConf, full = false) {
5173
5175
  return conf;
5174
5176
  }
5175
5177
  function handleConfFormServer(conf) {
5176
- const DisabledKeys = ["el", "pageKey", "pageTitle", "server", "site"];
5178
+ const ExcludedKeys = [
5179
+ "el",
5180
+ "pageKey",
5181
+ "pageTitle",
5182
+ "server",
5183
+ "site",
5184
+ "pvEl",
5185
+ "countEl",
5186
+ "statPageKeyAttr"
5187
+ ];
5177
5188
  Object.keys(conf).forEach((k) => {
5178
- if (DisabledKeys.includes(k))
5189
+ if (ExcludedKeys.includes(k))
5179
5190
  delete conf[k];
5180
5191
  if (k === "darkMode" && conf[k] !== "auto")
5181
5192
  delete conf[k];
@@ -5354,50 +5365,6 @@ class Context {
5354
5365
  watchConf(this, keys, effect);
5355
5366
  }
5356
5367
  }
5357
- class Dialog {
5358
- constructor(contentEl) {
5359
- __publicField(this, "$el");
5360
- __publicField(this, "$content");
5361
- __publicField(this, "$actions");
5362
- this.$el = createElement(
5363
- `<div class="atk-layer-dialog-wrap">
5364
- <div class="atk-layer-dialog">
5365
- <div class="atk-layer-dialog-content"></div>
5366
- <div class="atk-layer-dialog-actions"></div>
5367
- </div>
5368
- </div>`
5369
- );
5370
- this.$actions = this.$el.querySelector(".atk-layer-dialog-actions");
5371
- this.$content = this.$el.querySelector(".atk-layer-dialog-content");
5372
- this.$content.appendChild(contentEl);
5373
- }
5374
- /** 按钮 · 确定 */
5375
- setYes(handler) {
5376
- const btn = createElement(
5377
- `<button data-action="confirm">${t("confirm")}</button>`
5378
- );
5379
- btn.onclick = this.onBtnClick(handler);
5380
- this.$actions.appendChild(btn);
5381
- return this;
5382
- }
5383
- /** 按钮 · 取消 */
5384
- setNo(handler) {
5385
- const btn = createElement(
5386
- `<button data-action="cancel">${t("cancel")}</button>`
5387
- );
5388
- btn.onclick = this.onBtnClick(handler);
5389
- this.$actions.appendChild(btn);
5390
- return this;
5391
- }
5392
- onBtnClick(handler) {
5393
- return (evt) => {
5394
- const re = handler(evt.currentTarget, this);
5395
- if (re === void 0 || re === true) {
5396
- this.$el.remove();
5397
- }
5398
- };
5399
- }
5400
- }
5401
5368
  function showLoading(parentElem, conf) {
5402
5369
  let $loading = parentElem.querySelector(":scope > .atk-loading");
5403
5370
  if (!$loading) {
@@ -5643,6 +5610,50 @@ const AdminChecker = {
5643
5610
  onError(checker, err, inputVal, formEl) {
5644
5611
  }
5645
5612
  };
5613
+ class Dialog {
5614
+ constructor(contentEl) {
5615
+ __publicField(this, "$el");
5616
+ __publicField(this, "$content");
5617
+ __publicField(this, "$actions");
5618
+ this.$el = createElement(
5619
+ `<div class="atk-layer-dialog-wrap">
5620
+ <div class="atk-layer-dialog">
5621
+ <div class="atk-layer-dialog-content"></div>
5622
+ <div class="atk-layer-dialog-actions"></div>
5623
+ </div>
5624
+ </div>`
5625
+ );
5626
+ this.$actions = this.$el.querySelector(".atk-layer-dialog-actions");
5627
+ this.$content = this.$el.querySelector(".atk-layer-dialog-content");
5628
+ this.$content.appendChild(contentEl);
5629
+ }
5630
+ /** 按钮 · 确定 */
5631
+ setYes(handler) {
5632
+ const btn = createElement(
5633
+ `<button data-action="confirm">${t("confirm")}</button>`
5634
+ );
5635
+ btn.onclick = this.onBtnClick(handler);
5636
+ this.$actions.appendChild(btn);
5637
+ return this;
5638
+ }
5639
+ /** 按钮 · 取消 */
5640
+ setNo(handler) {
5641
+ const btn = createElement(
5642
+ `<button data-action="cancel">${t("cancel")}</button>`
5643
+ );
5644
+ btn.onclick = this.onBtnClick(handler);
5645
+ this.$actions.appendChild(btn);
5646
+ return this;
5647
+ }
5648
+ onBtnClick(handler) {
5649
+ return (evt) => {
5650
+ const re = handler(evt.currentTarget, this);
5651
+ if (re === void 0 || re === true) {
5652
+ this.$el.remove();
5653
+ }
5654
+ };
5655
+ }
5656
+ }
5646
5657
  function wrapPromise(fn) {
5647
5658
  return (payload) => new Promise((resolve, reject) => {
5648
5659
  const cancelFn = payload.onCancel;
@@ -6472,7 +6483,10 @@ function check(conf, rules) {
6472
6483
  };
6473
6484
  _check();
6474
6485
  if (imgCheck) {
6475
- el.querySelectorAll(".atk-content img").forEach((img) => {
6486
+ const imgs = el.querySelectorAll(".atk-content img");
6487
+ if (imgs.length === 0)
6488
+ el.style.maxHeight = "";
6489
+ imgs.forEach((img) => {
6476
6490
  img.onload = () => _check();
6477
6491
  });
6478
6492
  }
@@ -7270,7 +7284,7 @@ class CommentNode {
7270
7284
  return getGravatarURL({
7271
7285
  mirror: this.opts.gravatar.mirror,
7272
7286
  params: this.opts.gravatar.params,
7273
- emailMD5: this.data.email_encrypted
7287
+ emailHash: this.data.email_encrypted
7274
7288
  });
7275
7289
  }
7276
7290
  /** 获取评论 markdown 解析后的内容 */
@@ -7965,7 +7979,7 @@ const services = {
7965
7979
  }
7966
7980
  };
7967
7981
  const PvCountWidget = (ctx) => {
7968
- ctx.watchConf(["site", "pageKey", "pageTitle", "countEl", "pvEl"], (conf) => {
7982
+ ctx.watchConf(["site", "pageKey", "pageTitle", "countEl", "pvEl", "statPageKeyAttr"], (conf) => {
7969
7983
  initCountWidget({
7970
7984
  getApi: () => ctx.getApi(),
7971
7985
  siteName: conf.site,
@@ -7973,81 +7987,85 @@ const PvCountWidget = (ctx) => {
7973
7987
  pageTitle: conf.pageTitle,
7974
7988
  countEl: conf.countEl,
7975
7989
  pvEl: conf.pvEl,
7990
+ pageKeyAttr: conf.statPageKeyAttr,
7976
7991
  pvAdd: typeof ctx.conf.pvAdd === "boolean" ? ctx.conf.pvAdd : true
7977
7992
  });
7978
7993
  });
7979
7994
  };
7980
7995
  function initCountWidget(opt) {
7981
7996
  return __async(this, null, function* () {
7982
- if (opt.countEl && document.querySelector(opt.countEl)) {
7983
- refreshStatCount(opt, { query: "page_comment", numEl: opt.countEl });
7984
- }
7985
- const initialData = opt.pvAdd && opt.pageKey ? {
7986
- [opt.pageKey]: (yield opt.getApi().pages.logPv({
7987
- page_key: opt.pageKey,
7988
- page_title: opt.pageTitle,
7989
- site_name: opt.siteName
7990
- })).data.pv
7991
- // pv+1 and get pv count
7992
- } : void 0;
7993
- if (opt.pvEl && document.querySelector(opt.pvEl)) {
7994
- refreshStatCount(opt, {
7995
- query: "page_pv",
7996
- numEl: opt.pvEl,
7997
- data: initialData
7998
- });
7999
- }
7997
+ yield loadCommentCount(opt);
7998
+ const cacheData = yield incrementPvCount(opt);
7999
+ yield loadPvCount(opt, cacheData);
8000
8000
  });
8001
8001
  }
8002
- function refreshStatCount(opt, args) {
8002
+ function incrementPvCount(opt) {
8003
8003
  return __async(this, null, function* () {
8004
- let data = args.data || {};
8005
- let queryPageKeys = Array.from(document.querySelectorAll(args.numEl)).map((e) => e.getAttribute("data-page-key") || opt.pageKey).filter((k) => k && typeof data[k] !== "number");
8006
- queryPageKeys = [...new Set(queryPageKeys)];
8007
- if (queryPageKeys.length > 0) {
8004
+ if (!opt.pvAdd || !opt.pageKey)
8005
+ return void 0;
8006
+ const pvCount = (yield opt.getApi().pages.logPv({
8007
+ page_key: opt.pageKey,
8008
+ page_title: opt.pageTitle,
8009
+ site_name: opt.siteName
8010
+ })).data.pv;
8011
+ return {
8012
+ [opt.pageKey]: pvCount
8013
+ };
8014
+ });
8015
+ }
8016
+ function loadCommentCount(opt) {
8017
+ return __async(this, null, function* () {
8018
+ yield loadStatCount({ opt, query: "page_comment", containers: [opt.countEl, "#ArtalkCount"] });
8019
+ });
8020
+ }
8021
+ function loadPvCount(opt, cache) {
8022
+ return __async(this, null, function* () {
8023
+ yield loadStatCount({ opt, query: "page_pv", containers: [opt.pvEl, "#ArtalkPv"], cache });
8024
+ });
8025
+ }
8026
+ function loadStatCount(args) {
8027
+ return __async(this, null, function* () {
8028
+ const { opt } = args;
8029
+ let cache = args.cache || {};
8030
+ const els = retrieveElements(args.containers);
8031
+ const pageKeys = getPageKeys(els, opt.pageKeyAttr, opt.pageKey, cache);
8032
+ if (pageKeys.length > 0) {
8008
8033
  const res = (yield opt.getApi().stats.getStats(args.query, {
8009
- page_keys: queryPageKeys.join(","),
8034
+ page_keys: pageKeys.join(","),
8010
8035
  site_name: opt.siteName
8011
8036
  })).data.data;
8012
- data = __spreadValues(__spreadValues({}, data), res);
8037
+ cache = __spreadValues(__spreadValues({}, cache), res);
8013
8038
  }
8014
- const defaultCount = opt.pageKey ? data[opt.pageKey] : 0;
8015
- applyCountData(args.numEl, data, defaultCount);
8039
+ updateElementsText(els, cache, opt.pageKey);
8016
8040
  });
8017
8041
  }
8018
- function applyCountData(selector, data, defaultCount) {
8019
- document.querySelectorAll(selector).forEach((el) => {
8020
- const pageKey = el.getAttribute("data-page-key");
8021
- const count = Number(pageKey ? data[pageKey] : defaultCount);
8022
- el.innerHTML = `${count}`;
8042
+ function retrieveElements(containers) {
8043
+ const els = /* @__PURE__ */ new Set();
8044
+ new Set(containers).forEach((selector) => {
8045
+ document.querySelectorAll(selector).forEach((el) => els.add(el));
8023
8046
  });
8047
+ return els;
8024
8048
  }
8025
- function showErrorDialog(opts) {
8026
- const errEl = createElement(`<span><span class="error-message"></span><br/><br/></span>`);
8027
- errEl.querySelector(".error-message").innerText = `${t("listLoadFailMsg")}
8028
- ${opts.errMsg}`;
8029
- if (opts.retryFn) {
8030
- const $retryBtn = createElement(`<span style="cursor:pointer;">${t("listRetry")}</span>`);
8031
- $retryBtn.onclick = () => opts.retryFn && opts.retryFn();
8032
- errEl.appendChild($retryBtn);
8033
- }
8034
- if (opts.onOpenSidebar) {
8035
- const $openSidebar = createElement(
8036
- `<span atk-only-admin-show> | <span style="cursor:pointer;">${t("openName", { name: t("ctrlCenter") })}</span></span>`
8037
- );
8038
- errEl.appendChild($openSidebar);
8039
- $openSidebar.onclick = () => opts.onOpenSidebar && opts.onOpenSidebar();
8040
- }
8041
- setError(opts.$err, errEl);
8049
+ function getPageKeys(els, pageKeyAttr, pageKey, cache) {
8050
+ const pageKeys = Array.from(els).map((el) => el.getAttribute(pageKeyAttr) || pageKey).filter((key) => key && typeof cache[key] !== "number");
8051
+ return [...new Set(pageKeys)];
8052
+ }
8053
+ function updateElementsText(els, data, defaultPageKey) {
8054
+ els.forEach((el) => {
8055
+ const pageKey = el.getAttribute("data-page-key");
8056
+ const count = pageKey && data[pageKey] || defaultPageKey && data[defaultPageKey] || 0;
8057
+ el.innerText = `${Number(count)}`;
8058
+ });
8042
8059
  }
8043
8060
  const Markdown = (ctx) => {
8044
- ctx.watchConf(["markedReplacers", "imgLazyLoad", "markedOptions"], (conf) => {
8061
+ ctx.watchConf(["imgLazyLoad", "markedOptions"], (conf) => {
8045
8062
  initMarked({
8046
8063
  markedOptions: ctx.getConf().markedOptions,
8047
8064
  imgLazyLoad: ctx.getConf().imgLazyLoad
8048
8065
  });
8049
- if (conf.markedReplacers)
8050
- setReplacers(conf.markedReplacers);
8066
+ });
8067
+ ctx.watchConf(["markedReplacers"], (conf) => {
8068
+ conf.markedReplacers && setReplacers(conf.markedReplacers);
8051
8069
  });
8052
8070
  };
8053
8071
  const LocalStorageKey = "ArtalkContent";
@@ -9284,7 +9302,7 @@ const GotoFocus = (ctx) => {
9284
9302
  comment.focus();
9285
9303
  }));
9286
9304
  };
9287
- const version = "2.8.6";
9305
+ const version = "2.8.7";
9288
9306
  const Copyright = (ctx) => {
9289
9307
  ctx.on("mounted", () => {
9290
9308
  const list2 = ctx.get("list");
@@ -9389,8 +9407,7 @@ function renderDropdown(conf) {
9389
9407
  };
9390
9408
  const $dropdown = createElement(`<ul class="atk-dropdown atk-fade-in"></ul>`);
9391
9409
  dropdownList.forEach((item, i) => {
9392
- const name = item[0];
9393
- const action = item[1];
9410
+ const [name, action] = item;
9394
9411
  const $item = createElement(`<li class="atk-dropdown-item"><span></span></li>`);
9395
9412
  const $link = $item.querySelector("span");
9396
9413
  $link.innerText = name;
@@ -9425,6 +9442,24 @@ const TimeTicking = (ctx) => {
9425
9442
  timer && window.clearInterval(timer);
9426
9443
  });
9427
9444
  };
9445
+ function showErrorDialog(opts) {
9446
+ const errEl = createElement(`<span><span class="error-message"></span><br/><br/></span>`);
9447
+ errEl.querySelector(".error-message").innerText = `${t("listLoadFailMsg")}
9448
+ ${opts.errMsg}`;
9449
+ if (opts.retryFn) {
9450
+ const $retryBtn = createElement(`<span style="cursor:pointer;">${t("listRetry")}</span>`);
9451
+ $retryBtn.onclick = () => opts.retryFn && opts.retryFn();
9452
+ errEl.appendChild($retryBtn);
9453
+ }
9454
+ if (opts.onOpenSidebar) {
9455
+ const $openSidebar = createElement(
9456
+ `<span atk-only-admin-show> | <span style="cursor:pointer;">${t("openName", { name: t("ctrlCenter") })}</span></span>`
9457
+ );
9458
+ errEl.appendChild($openSidebar);
9459
+ $openSidebar.onclick = () => opts.onOpenSidebar && opts.onOpenSidebar();
9460
+ }
9461
+ setError(opts.$err, errEl);
9462
+ }
9428
9463
  const ErrorDialog = (ctx) => {
9429
9464
  ctx.on("list-fetch", () => {
9430
9465
  const list2 = ctx.get("list");
@@ -9689,16 +9724,16 @@ const DefaultPlugins = [
9689
9724
  VersionCheck,
9690
9725
  DarkMode
9691
9726
  ];
9692
- const GlobalPlugins = [...DefaultPlugins];
9727
+ const GlobalPlugins = /* @__PURE__ */ new Set([...DefaultPlugins]);
9693
9728
  function load(ctx) {
9694
9729
  return __async(this, null, function* () {
9695
9730
  var _a;
9696
- const loadedPlugins = [];
9731
+ const loadedPlugins = /* @__PURE__ */ new Set();
9697
9732
  const loadPlugins = (plugins) => {
9698
9733
  plugins.forEach((plugin) => {
9699
- if (typeof plugin === "function" && !loadedPlugins.includes(plugin)) {
9734
+ if (typeof plugin === "function" && !loadedPlugins.has(plugin)) {
9700
9735
  plugin(ctx);
9701
- loadedPlugins.push(plugin);
9736
+ loadedPlugins.add(plugin);
9702
9737
  }
9703
9738
  });
9704
9739
  };
@@ -9734,8 +9769,9 @@ function load(ctx) {
9734
9769
  }
9735
9770
  function loadNetworkPlugins(scripts, apiBase) {
9736
9771
  return __async(this, null, function* () {
9772
+ const networkPlugins = /* @__PURE__ */ new Set();
9737
9773
  if (!scripts || !Array.isArray(scripts))
9738
- return [];
9774
+ return networkPlugins;
9739
9775
  const tasks = [];
9740
9776
  scripts.forEach((url) => {
9741
9777
  if (!/^(http|https):\/\//.test(url))
@@ -9755,7 +9791,11 @@ function loadNetworkPlugins(scripts, apiBase) {
9755
9791
  );
9756
9792
  });
9757
9793
  yield Promise.all(tasks);
9758
- return Object.values(window.ArtalkPlugins || {});
9794
+ Object.values(window.ArtalkPlugins || {}).forEach((plugin) => {
9795
+ if (typeof plugin === "function")
9796
+ networkPlugins.add(plugin);
9797
+ });
9798
+ return networkPlugins;
9759
9799
  });
9760
9800
  }
9761
9801
  function onLoadErr(ctx, err) {
@@ -9841,9 +9881,7 @@ class Artalk {
9841
9881
  }
9842
9882
  /** Use plugin, the plugin will be used when Artalk.init */
9843
9883
  static use(plugin) {
9844
- if (GlobalPlugins.includes(plugin))
9845
- return;
9846
- GlobalPlugins.push(plugin);
9884
+ GlobalPlugins.add(plugin);
9847
9885
  }
9848
9886
  /** Load count widget */
9849
9887
  static loadCountWidget(c) {
@@ -9853,6 +9891,7 @@ class Artalk {
9853
9891
  siteName: conf.site,
9854
9892
  countEl: conf.countEl,
9855
9893
  pvEl: conf.pvEl,
9894
+ pageKeyAttr: conf.statPageKeyAttr,
9856
9895
  pvAdd: false
9857
9896
  });
9858
9897
  }