artalk 2.4.2 → 2.4.3

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.
@@ -237,18 +237,6 @@ class User {
237
237
  return !!this.data.nick && !!this.data.email;
238
238
  }
239
239
  }
240
- class Component {
241
- constructor(ctx) {
242
- __publicField(this, "$el");
243
- __publicField(this, "ctx");
244
- __publicField(this, "conf");
245
- this.ctx = ctx;
246
- this.conf = ctx.conf;
247
- }
248
- $t(key, args = {}) {
249
- return this.ctx.$t(key, args);
250
- }
251
- }
252
240
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
253
241
  var escapes = {
254
242
  "&": "&",
@@ -856,7 +844,12 @@ function marked(ctx, src) {
856
844
  }
857
845
  let dest = insane_1(markedContent, {
858
846
  allowedClasses: {},
859
- allowedSchemes: ["http", "https", "mailto"],
847
+ allowedSchemes: [
848
+ "http",
849
+ "https",
850
+ "mailto",
851
+ "data"
852
+ ],
860
853
  allowedTags: [
861
854
  "a",
862
855
  "abbr",
@@ -993,6 +986,18 @@ function mergeDeep(target, source) {
993
986
  });
994
987
  return target;
995
988
  }
989
+ class Component {
990
+ constructor(ctx) {
991
+ __publicField(this, "$el");
992
+ __publicField(this, "ctx");
993
+ __publicField(this, "conf");
994
+ this.ctx = ctx;
995
+ this.conf = ctx.conf;
996
+ }
997
+ $t(key, args = {}) {
998
+ return this.ctx.$t(key, args);
999
+ }
1000
+ }
996
1001
  function showLoading(parentElem, conf) {
997
1002
  let $loading = parentElem.querySelector(":scope > .atk-loading");
998
1003
  if (!$loading) {
@@ -1910,7 +1915,7 @@ class UserApi extends ApiBase {
1910
1915
  if (this.ctx.conf.site)
1911
1916
  params.site_name = this.ctx.conf.site;
1912
1917
  const data = yield this.POST("/login", params);
1913
- return data.token;
1918
+ return data;
1914
1919
  });
1915
1920
  }
1916
1921
  userGet(name, email) {
@@ -1964,6 +1969,58 @@ class UserApi extends ApiBase {
1964
1969
  }
1965
1970
  return this.POST(`/mark-read`, params);
1966
1971
  }
1972
+ userList(offset, limit, type) {
1973
+ return __async(this, null, function* () {
1974
+ const params = {
1975
+ offset: offset || 0,
1976
+ limit: limit || 15
1977
+ };
1978
+ if (type)
1979
+ params.type = type;
1980
+ const d = yield this.POST("/admin/user-get", params);
1981
+ return d;
1982
+ });
1983
+ }
1984
+ userAdd(user, password) {
1985
+ return __async(this, null, function* () {
1986
+ const params = {
1987
+ name: user.name || "",
1988
+ email: user.email || "",
1989
+ password: password || "",
1990
+ link: user.link || "",
1991
+ is_admin: user.is_admin || false,
1992
+ site_names: user.site_names_raw || "",
1993
+ receive_email: user.receive_email || true,
1994
+ badge_name: user.badge_name || "",
1995
+ badge_color: user.badge_color || ""
1996
+ };
1997
+ const d = yield this.POST("/admin/user-add", params);
1998
+ return d.user;
1999
+ });
2000
+ }
2001
+ userEdit(user, password) {
2002
+ return __async(this, null, function* () {
2003
+ const params = {
2004
+ id: user.id,
2005
+ name: user.name || "",
2006
+ email: user.email || "",
2007
+ password: password || "",
2008
+ link: user.link || "",
2009
+ is_admin: user.is_admin || false,
2010
+ site_names: user.site_names_raw || "",
2011
+ receive_email: user.receive_email || true,
2012
+ badge_name: user.badge_name || "",
2013
+ badge_color: user.badge_color || ""
2014
+ };
2015
+ const d = yield this.POST("/admin/user-edit", params);
2016
+ return d.user;
2017
+ });
2018
+ }
2019
+ userDel(userID) {
2020
+ return this.POST("/admin/user-del", {
2021
+ id: String(userID)
2022
+ });
2023
+ }
1967
2024
  }
1968
2025
  class SystemApi extends ApiBase {
1969
2026
  conf() {
@@ -1995,6 +2052,13 @@ class SystemApi extends ApiBase {
1995
2052
  return data;
1996
2053
  });
1997
2054
  }
2055
+ version() {
2056
+ return __async(this, null, function* () {
2057
+ const resp = yield fetch(`${this.api.baseURL}/version`, { method: "POST" });
2058
+ const data = yield resp.json();
2059
+ return data;
2060
+ });
2061
+ }
1998
2062
  }
1999
2063
  class CaptchaApi extends ApiBase {
2000
2064
  captchaGet() {
@@ -2060,16 +2124,17 @@ const ApiComponents = {
2060
2124
  class Api {
2061
2125
  constructor(ctx) {
2062
2126
  __publicField(this, "ctx");
2063
- __publicField(this, "baseURL");
2064
2127
  this.ctx = ctx;
2065
- this.baseURL = `${ctx.conf.server}/api`;
2066
2128
  Object.entries(ApiComponents).forEach(([key, ApiComponent]) => {
2067
2129
  this[key] = new ApiComponent(this, this.ctx);
2068
2130
  });
2069
2131
  }
2132
+ get baseURL() {
2133
+ return `${this.ctx.conf.server}/api`;
2134
+ }
2070
2135
  }
2071
- const version = "2.4.2";
2072
- const backendMinVersion = "2.2.0";
2136
+ const version = "2.4.3";
2137
+ const backendMinVersion = "2.3.0";
2073
2138
  const ListHTML = '<div class="atk-list">\n <div class="atk-list-header">\n <div class="atk-comment-count">\n <div class="atk-text"></div>\n </div>\n <div class="atk-right-action">\n <span data-action="admin-close-comment" class="atk-hide" atk-only-admin-show></span>\n <span data-action="open-sidebar" class="atk-hide atk-on">\n <span class="atk-unread-badge" style="display: none;"></span>\n <div class="atk-text"></div>\n </span>\n </div>\n </div>\n <div class="atk-list-body"></div>\n <div class="atk-list-footer">\n <div class="atk-copyright"></div>\n </div>\n</div>\n';
2074
2139
  const win = window || {};
2075
2140
  const nav = navigator || {};
@@ -2428,7 +2493,8 @@ class CommentRender {
2428
2493
  renderAvatar() {
2429
2494
  const $avatar = this.$el.querySelector(".atk-avatar");
2430
2495
  const $avatarImg = createElement("<img />");
2431
- $avatarImg.src = this.comment.getGravatarURL();
2496
+ const avatarURLBuilder = this.ctx.conf.avatarURLBuilder;
2497
+ $avatarImg.src = avatarURLBuilder ? avatarURLBuilder(this.data) : this.comment.getGravatarURL();
2432
2498
  if (this.data.link) {
2433
2499
  const $avatarA = createElement('<a target="_blank" rel="noreferrer noopener nofollow"></a>');
2434
2500
  $avatarA.href = isValidURL(this.data.link) ? this.data.link : `https://${this.data.link}`;
@@ -3214,10 +3280,10 @@ class ListLite extends Component {
3214
3280
  __publicField(this, "data");
3215
3281
  __publicField(this, "isLoading", false);
3216
3282
  __publicField(this, "noCommentText");
3217
- __publicField(this, "flatMode", false);
3218
- __publicField(this, "nestSortBy");
3219
- __publicField(this, "pageMode", "pagination");
3220
- __publicField(this, "pageSize", 20);
3283
+ __publicField(this, "_nestSortBy");
3284
+ __publicField(this, "_flatMode");
3285
+ __publicField(this, "_pageMode");
3286
+ __publicField(this, "_pageSize");
3221
3287
  __publicField(this, "scrollListenerAt");
3222
3288
  __publicField(this, "repositionAt");
3223
3289
  __publicField(this, "pagination");
@@ -3228,20 +3294,53 @@ class ListLite extends Component {
3228
3294
  __publicField(this, "onAfterLoad");
3229
3295
  __publicField(this, "unread", []);
3230
3296
  __publicField(this, "unreadHighlight");
3297
+ __publicField(this, "confLoaded", false);
3231
3298
  this.$el = createElement(
3232
3299
  `<div class="atk-list-lite">
3233
3300
  <div class="atk-list-comments-wrap"></div>
3234
3301
  </div>`
3235
3302
  );
3236
3303
  this.$commentsWrap = this.$el.querySelector(".atk-list-comments-wrap");
3237
- this.noCommentText = ctx.conf.noComment || ctx.$t("noComment");
3238
- this.nestSortBy = this.ctx.conf.nestSort || "DATE_ASC";
3239
3304
  window.setInterval(() => {
3240
3305
  this.$el.querySelectorAll("[data-atk-comment-date]").forEach((el) => {
3241
3306
  const date = el.getAttribute("data-atk-comment-date");
3242
3307
  el.innerText = timeAgo(new Date(Number(date)), this.ctx);
3243
3308
  });
3244
3309
  }, 30 * 1e3);
3310
+ this.ctx.on("conf-loaded", () => {
3311
+ });
3312
+ }
3313
+ get nestSortBy() {
3314
+ if (this._nestSortBy !== void 0)
3315
+ return this._nestSortBy;
3316
+ return this.ctx.conf.nestSort || "DATE_ASC";
3317
+ }
3318
+ set nestSortBy(val) {
3319
+ this._nestSortBy = val;
3320
+ }
3321
+ get flatMode() {
3322
+ if (this._flatMode !== void 0)
3323
+ return this._flatMode;
3324
+ if (this.ctx.conf.flatMode === true || Number(this.ctx.conf.nestMax) <= 1)
3325
+ return true;
3326
+ if (this.ctx.conf.flatMode === "auto" && window.matchMedia("(max-width: 768px)").matches)
3327
+ return true;
3328
+ return false;
3329
+ }
3330
+ set flatMode(val) {
3331
+ this._flatMode = val;
3332
+ }
3333
+ get pageMode() {
3334
+ return this._pageMode || (this.conf.pagination.readMore ? "read-more" : "pagination");
3335
+ }
3336
+ set pageMode(val) {
3337
+ this._pageMode = val;
3338
+ }
3339
+ get pageSize() {
3340
+ return this._pageSize || this.conf.pagination.pageSize;
3341
+ }
3342
+ set pageSize(val) {
3343
+ this._pageSize = val;
3245
3344
  }
3246
3345
  getData() {
3247
3346
  return this.data;
@@ -3269,7 +3368,7 @@ class ListLite extends Component {
3269
3368
  const setLoading2 = (val) => this.setLoading(val, isFirstLoad);
3270
3369
  setLoading2(true);
3271
3370
  this.ctx.trigger("list-load");
3272
- if (isFirstLoad && this.pageMode === "read-more") {
3371
+ if (this.pageMode === "read-more" && isFirstLoad || this.pageMode === "pagination") {
3273
3372
  this.ctx.clearAllComments();
3274
3373
  }
3275
3374
  let listData;
@@ -3294,24 +3393,24 @@ class ListLite extends Component {
3294
3393
  }
3295
3394
  onLoad(data, offset) {
3296
3395
  var _a, _b;
3297
- if (this.pageMode === "pagination") {
3298
- this.ctx.clearAllComments();
3299
- }
3300
3396
  this.data = data;
3397
+ if (!this.confLoaded) {
3398
+ if (this.conf.useBackendConf)
3399
+ this.ctx.updateConf(data.conf.frontend_conf);
3400
+ else
3401
+ this.ctx.updateConf({});
3402
+ this.confLoaded = true;
3403
+ }
3301
3404
  const feMinVersion = ((_a = data.api_version) == null ? void 0 : _a.fe_min_version) || "0.0.0";
3302
3405
  if (this.ctx.conf.versionCheck && this.versionCheck("frontend", feMinVersion, version))
3303
3406
  return;
3304
3407
  if (this.ctx.conf.versionCheck && this.versionCheck("backend", backendMinVersion, (_b = data.api_version) == null ? void 0 : _b.version))
3305
3408
  return;
3306
- if (data.conf && typeof data.conf.img_upload === "boolean") {
3307
- this.ctx.conf.imgUpload = data.conf.img_upload;
3308
- }
3309
3409
  this.importComments(data.comments);
3310
3410
  this.refreshPagination(offset, this.flatMode ? data.total : data.total_roots);
3311
3411
  this.refreshUI();
3312
3412
  this.ctx.updateNotifies(data.unread || []);
3313
3413
  this.ctx.trigger("list-loaded");
3314
- this.ctx.trigger("conf-updated");
3315
3414
  if (this.onAfterLoad)
3316
3415
  this.onAfterLoad(data);
3317
3416
  }
@@ -3375,6 +3474,9 @@ class ListLite extends Component {
3375
3474
  }
3376
3475
  onError(msg, offset, errData) {
3377
3476
  var _a;
3477
+ if (!this.confLoaded) {
3478
+ this.ctx.updateConf({});
3479
+ }
3378
3480
  msg = String(msg);
3379
3481
  console.error(msg);
3380
3482
  if (offset !== 0 && this.pageMode === "read-more") {
@@ -3408,7 +3510,7 @@ class ListLite extends Component {
3408
3510
  if (isNoComment) {
3409
3511
  if (!$noComment) {
3410
3512
  $noComment = createElement('<div class="atk-list-no-comment"></div>');
3411
- $noComment.innerHTML = this.noCommentText;
3513
+ $noComment.innerHTML = this.noCommentText || this.ctx.conf.noComment || this.ctx.$t("noComment");
3412
3514
  this.$commentsWrap.appendChild($noComment);
3413
3515
  }
3414
3516
  } else {
@@ -3538,7 +3640,6 @@ class ListLite extends Component {
3538
3640
  ignoreBtn.onclick = () => {
3539
3641
  setError(this.$el.parentElement, null);
3540
3642
  this.ctx.conf.versionCheck = false;
3541
- this.ctx.trigger("conf-updated");
3542
3643
  this.fetchComments(0);
3543
3644
  };
3544
3645
  errEl.append(ignoreBtn);
@@ -3559,18 +3660,9 @@ class List extends ListLite {
3559
3660
  __publicField(this, "$dropdownWrap");
3560
3661
  __publicField(this, "goToCommentFounded", false);
3561
3662
  __publicField(this, "goToCommentDelay", true);
3663
+ __publicField(this, "dropdownLoaded", false);
3562
3664
  el.querySelector(".atk-list-body").append(this.$el);
3563
3665
  this.$el = el;
3564
- if (this.ctx.conf.flatMode === true) {
3565
- this.flatMode = true;
3566
- } else if (this.conf.nestMax && this.conf.nestMax <= 1) {
3567
- this.flatMode = true;
3568
- } else if (this.ctx.conf.flatMode === "auto") {
3569
- if (window.matchMedia("(max-width: 768px)").matches)
3570
- this.flatMode = true;
3571
- }
3572
- this.pageMode = this.conf.pagination.readMore ? "read-more" : "pagination";
3573
- this.pageSize = this.conf.pagination.pageSize || 20;
3574
3666
  this.repositionAt = this.$el;
3575
3667
  this.initListActionBtn();
3576
3668
  this.$commentCount = this.$el.querySelector(".atk-comment-count");
@@ -3578,9 +3670,6 @@ class List extends ListLite {
3578
3670
  count: '<span class="atk-comment-count-num">0</span>'
3579
3671
  });
3580
3672
  this.$commentCountNum = this.$commentCount.querySelector(".atk-comment-count-num");
3581
- if (this.ctx.conf.listSort) {
3582
- this.initDropdown();
3583
- }
3584
3673
  this.$el.querySelector(".atk-copyright").innerHTML = `Powered By <a href="https://artalk.js.org" target="_blank" title="Artalk v${version}">Artalk</a>`;
3585
3674
  }
3586
3675
  initListActionBtn() {
@@ -3615,6 +3704,9 @@ class List extends ListLite {
3615
3704
  this.ctx.editorOpen();
3616
3705
  this.$closeCommentBtn.innerHTML = this.$t("closeComment");
3617
3706
  }
3707
+ if (this.ctx.conf.listSort) {
3708
+ this.initDropdown();
3709
+ }
3618
3710
  }
3619
3711
  onLoad(data, offset) {
3620
3712
  super.onLoad(data, offset);
@@ -3688,6 +3780,9 @@ class List extends ListLite {
3688
3780
  }
3689
3781
  }
3690
3782
  initDropdown() {
3783
+ if (this.dropdownLoaded)
3784
+ return;
3785
+ this.dropdownLoaded = true;
3691
3786
  this.$dropdownWrap = this.$commentCount;
3692
3787
  this.$commentCount.classList.add("atk-dropdown-wrap");
3693
3788
  this.$dropdownWrap.append(createElement(`<span class="atk-arrow-down-icon"></span>`));
@@ -3768,6 +3863,8 @@ class Context {
3768
3863
  __publicField(this, "markedReplacers", []);
3769
3864
  __publicField(this, "commentList", []);
3770
3865
  __publicField(this, "eventList", []);
3866
+ __publicField(this, "darkModeMedia", window.matchMedia("(prefers-color-scheme: dark)"));
3867
+ __publicField(this, "darkModeAutoFunc");
3771
3868
  this.cid = +new Date();
3772
3869
  this.conf = conf;
3773
3870
  this.user = new User(this);
@@ -3776,6 +3873,9 @@ class Context {
3776
3873
  this.$root.classList.add("artalk");
3777
3874
  this.$root.innerHTML = "";
3778
3875
  this.api = new Api(this);
3876
+ this.on("conf-loaded", () => {
3877
+ this.refreshDarkModeConf();
3878
+ });
3779
3879
  }
3780
3880
  setApi(api) {
3781
3881
  this.api = api;
@@ -3937,21 +4037,42 @@ class Context {
3937
4037
  return getI18n(this.conf.locale, key, args);
3938
4038
  }
3939
4039
  setDarkMode(darkMode) {
4040
+ if (this.conf.darkMode === darkMode)
4041
+ return;
3940
4042
  const darkModeClassName = "atk-dark-mode";
3941
4043
  this.conf.darkMode = darkMode;
3942
- this.trigger("conf-updated");
3943
- if (this.conf.darkMode)
4044
+ if (darkMode)
3944
4045
  this.$root.classList.add(darkModeClassName);
3945
4046
  else
3946
4047
  this.$root.classList.remove(darkModeClassName);
3947
4048
  const { $wrap: $layerWrap } = GetLayerWrap(this);
3948
4049
  if ($layerWrap) {
3949
- if (this.conf.darkMode)
4050
+ if (darkMode)
3950
4051
  $layerWrap.classList.add(darkModeClassName);
3951
4052
  else
3952
4053
  $layerWrap.classList.remove(darkModeClassName);
3953
4054
  }
3954
4055
  }
4056
+ refreshDarkModeConf() {
4057
+ if (this.conf.darkMode === "auto") {
4058
+ this.setDarkMode(this.darkModeMedia.matches);
4059
+ if (!this.darkModeAutoFunc) {
4060
+ this.darkModeAutoFunc = (evt) => {
4061
+ this.setDarkMode(evt.matches);
4062
+ };
4063
+ this.darkModeMedia.addEventListener("change", this.darkModeAutoFunc);
4064
+ }
4065
+ } else {
4066
+ if (this.darkModeAutoFunc) {
4067
+ this.darkModeMedia.removeEventListener("change", this.darkModeAutoFunc);
4068
+ }
4069
+ this.setDarkMode(this.conf.darkMode || false);
4070
+ }
4071
+ }
4072
+ updateConf(conf) {
4073
+ this.conf = mergeDeep(this.conf, conf);
4074
+ this.trigger("conf-loaded");
4075
+ }
3955
4076
  }
3956
4077
  const defaults = {
3957
4078
  el: "",
@@ -3977,7 +4098,7 @@ const defaults = {
3977
4098
  pvEl: "#ArtalkPV",
3978
4099
  gravatar: {
3979
4100
  default: "mp",
3980
- mirror: "https://sdn.geekzu.org/avatar/"
4101
+ mirror: "https://cravatar.cn/avatar/"
3981
4102
  },
3982
4103
  pagination: {
3983
4104
  pageSize: 20,
@@ -3991,7 +4112,7 @@ const defaults = {
3991
4112
  imgUpload: true,
3992
4113
  reqTimeout: 15e3,
3993
4114
  versionCheck: true,
3994
- useBackendConf: false,
4115
+ useBackendConf: true,
3995
4116
  locale: "zh-CN"
3996
4117
  };
3997
4118
  {
@@ -4112,6 +4233,7 @@ const CaptchaChecker = {
4112
4233
  },
4113
4234
  onError(that, ctx, err, inputVal, formEl) {
4114
4235
  formEl.querySelector(".atk-captcha-img").click();
4236
+ formEl.querySelector('input[type="text"]').value = "";
4115
4237
  }
4116
4238
  };
4117
4239
  const AdminChecker = {
@@ -4122,7 +4244,10 @@ const AdminChecker = {
4122
4244
  email: that.ctx.user.data.email,
4123
4245
  password: inputVal
4124
4246
  };
4125
- return that.ctx.getApi().user.login(data.name, data.email, data.password);
4247
+ return (() => __async(this, null, function* () {
4248
+ const resp = yield that.ctx.getApi().user.login(data.name, data.email, data.password);
4249
+ return resp.token;
4250
+ }))();
4126
4251
  },
4127
4252
  body(that, ctx) {
4128
4253
  return createElement(`<span>${that.ctx.$t("adminCheck")}</span>`);
@@ -4536,7 +4661,7 @@ class UploadPlug extends EditorPlug {
4536
4661
  };
4537
4662
  $input.click();
4538
4663
  };
4539
- this.ctx.on("conf-updated", () => {
4664
+ this.ctx.on("conf-loaded", () => {
4540
4665
  if (!this.ctx.conf.imgUpload) {
4541
4666
  this.getBtn().setAttribute("atk-only-admin-show", "");
4542
4667
  this.ctx.checkAdminShowEl();
@@ -4731,12 +4856,12 @@ class Editor extends Component {
4731
4856
  this.$notifyWrap = this.$el.querySelector(".atk-notify-wrap");
4732
4857
  this.$plugBtnWrap = this.$el.querySelector(".atk-plug-btn-wrap");
4733
4858
  this.$plugPanelWrap = this.$el.querySelector(".atk-plug-panel-wrap");
4734
- this.initLocalStorage();
4735
- this.initHeader();
4736
- this.initTextarea();
4737
- this.initPlugs();
4738
- this.initSubmitBtn();
4739
- this.ctx.on("conf-updated", () => {
4859
+ this.ctx.on("conf-loaded", () => {
4860
+ this.initLocalStorage();
4861
+ this.initHeader();
4862
+ this.initTextarea();
4863
+ this.initSubmitBtn();
4864
+ this.initPlugs();
4740
4865
  });
4741
4866
  }
4742
4867
  get user() {
@@ -5126,9 +5251,6 @@ class SidebarLayer extends Component {
5126
5251
  };
5127
5252
  }
5128
5253
  this.layer.show();
5129
- setTimeout(() => {
5130
- this.$el.style.transform = "translate(0, 0)";
5131
- }, 20);
5132
5254
  (() => __async(this, null, function* () {
5133
5255
  var _a;
5134
5256
  const resp = yield this.ctx.getApi().user.loginStatus();
@@ -5146,7 +5268,6 @@ class SidebarLayer extends Component {
5146
5268
  });
5147
5269
  }
5148
5270
  }))();
5149
- this.ctx.updateNotifies([]);
5150
5271
  if (this.firstShow) {
5151
5272
  this.$iframeWrap.innerHTML = "";
5152
5273
  this.$iframe = createElement("<iframe></iframe>");
@@ -5172,6 +5293,12 @@ class SidebarLayer extends Component {
5172
5293
  if (!this.conf.darkMode && isIframeSrcDarkMode)
5173
5294
  this.iframeLoad(this.$iframe.src.replace("&darkMode=1", ""));
5174
5295
  }
5296
+ setTimeout(() => {
5297
+ this.$el.style.transform = "translate(0, 0)";
5298
+ }, 100);
5299
+ setTimeout(() => {
5300
+ this.ctx.updateNotifies([]);
5301
+ }, 0);
5175
5302
  this.ctx.trigger("sidebar-show");
5176
5303
  });
5177
5304
  }
@@ -5192,7 +5319,13 @@ class SidebarLayer extends Component {
5192
5319
  }
5193
5320
  }
5194
5321
  const PvCountWidget = (ctx) => {
5195
- initCountWidget({ ctx, pvAdd: true });
5322
+ if (!ctx.conf.useBackendConf) {
5323
+ initCountWidget({ ctx, pvAdd: true });
5324
+ } else {
5325
+ ctx.on("list-loaded", () => {
5326
+ initCountWidget({ ctx, pvAdd: true });
5327
+ });
5328
+ }
5196
5329
  };
5197
5330
  function initCountWidget(p) {
5198
5331
  return __async(this, null, function* () {
@@ -5239,14 +5372,11 @@ const _Artalk = class {
5239
5372
  if (this.conf.el instanceof HTMLElement)
5240
5373
  this.$root = this.conf.el;
5241
5374
  this.ctx = new Context(this.conf, this.$root);
5242
- if (this.conf.useBackendConf)
5243
- return this.loadConfRemoteAndInitComponents();
5244
5375
  this.initComponents();
5245
5376
  }
5246
5377
  initComponents() {
5247
5378
  this.initLocale();
5248
5379
  this.initLayer();
5249
- this.initDarkMode();
5250
5380
  initMarked(this.ctx);
5251
5381
  const Components = {
5252
5382
  checkerLauncher: () => {
@@ -5267,7 +5397,6 @@ const _Artalk = class {
5267
5397
  sidebarLayer: () => {
5268
5398
  const sidebarLayer = new SidebarLayer(this.ctx);
5269
5399
  this.ctx.setSidebarLayer(sidebarLayer);
5270
- this.$root.appendChild(sidebarLayer.$el);
5271
5400
  },
5272
5401
  eventsDefault: () => {
5273
5402
  this.initEventBind();
@@ -5305,26 +5434,6 @@ const _Artalk = class {
5305
5434
  }
5306
5435
  return conf;
5307
5436
  }
5308
- loadConfRemoteAndInitComponents() {
5309
- return __async(this, null, function* () {
5310
- yield this.loadConfRemote();
5311
- this.initComponents();
5312
- return this;
5313
- });
5314
- }
5315
- loadConfRemote() {
5316
- return __async(this, null, function* () {
5317
- showLoading(this.$root);
5318
- let backendConf = {};
5319
- try {
5320
- backendConf = yield this.ctx.getApi().system.conf();
5321
- } catch (err) {
5322
- console.error("Load config from remote err", err);
5323
- }
5324
- this.ctx.conf = mergeDeep(this.ctx.conf, backendConf);
5325
- hideLoading(this.$root);
5326
- });
5327
- }
5328
5437
  initEventBind() {
5329
5438
  window.addEventListener("hashchange", () => {
5330
5439
  this.ctx.listHashGotoCheck();
@@ -5343,17 +5452,6 @@ const _Artalk = class {
5343
5452
  Layer.BodyOrgOverflow = document.body.style.overflow;
5344
5453
  Layer.BodyOrgPaddingRight = document.body.style.paddingRight;
5345
5454
  }
5346
- initDarkMode() {
5347
- if (this.conf.darkMode === "auto") {
5348
- const darkModeMedia = window.matchMedia("(prefers-color-scheme: dark)");
5349
- darkModeMedia.addEventListener("change", (e) => {
5350
- this.setDarkMode(e.matches);
5351
- });
5352
- this.setDarkMode(darkModeMedia.matches);
5353
- } else {
5354
- this.setDarkMode(this.conf.darkMode || false);
5355
- }
5356
- }
5357
5455
  on(name, handler) {
5358
5456
  this.ctx.on(name, handler, "external");
5359
5457
  }