var __extends = this && this.__extends || function() { var n = function(e, t) { return (n = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array ? function(e, t) { e.__proto__ = t } : function(e, t) { for (var o in t) Object.prototype.hasOwnProperty.call(t, o) && (e[o] = t[o]) }))(e, t) }; return function(e, t) { if ("function" != typeof t && null !== t) throw new TypeError("Class extends value " + String(t) + " is not a constructor or null"); function o() { this.constructor = e } n(e, t), e.prototype = null === t ? Object.create(t) : (o.prototype = t.prototype, new o) } }(); function isEmailValid(e) { return e.includes("@") } function isUrlValid(e) { return e.includes("http") } var farallonBase = function() { function e() { this.is_single = !1, this.post_id = 0, this.is_archive = !1, this.darkmode = !1, this.is_single = obvInit.is_single, this.post_id = obvInit.post_id, this.is_archive = obvInit.is_archive, this.darkmode = obvInit.darkmode, this.VERSION = obvInit.version } return e.prototype.getCookie = function(e) { if (0 < document.cookie.length) { var t = document.cookie.indexOf(e + "="); if (-1 != t) return t = t + e.length + 1, -1 == (e = document.cookie.indexOf(";", t)) && (e = document.cookie.length), document.cookie.substring(t, e) } return "" }, e.prototype.setCookie = function(e, t, o) { var n = new Date, o = (n.setTime(n.getTime() + 24 * o * 60 * 60 * 1e3), "expires=" + n.toUTCString()); document.cookie = e + "=" + t + ";" + o + ";path=/" }, e.prototype.showNotice = function(e, t) { void 0 === t && (t = "success"); t = '
'.concat(e, "
"); document.querySelector("body").insertAdjacentHTML("beforeend", t), document.querySelector(".notice--wrapper").classList.add("is-active"), setTimeout(function() { document.querySelector(".notice--wrapper").remove() }, 3e3) }, e }(), farallonAction = function(o) { function e() { var e = o.call(this) || this, t = (e.selctor = ".like-btn", e.is_single = !1, e.post_id = 0, e.is_archive = !1, e.is_single = obvInit.is_single, e.post_id = obvInit.post_id, e.is_archive = obvInit.is_archive, e.like_btn = document.querySelector(e.selctor), e.like_btn && (e.like_btn.addEventListener("click", function() { e.handleLike() }), e.getCookie("like_" + e.post_id)) && e.like_btn.classList.add("is-active"), localStorage.getItem("theme") ? localStorage.getItem("theme") : "auto"), t = '
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
'), t = (e.darkmode && document.querySelector("body").insertAdjacentHTML("beforeend", t), document.querySelectorAll(".fixed--theme span").forEach(function(e) { e.addEventListener("click", function() { e.classList.contains("is-active") || (document.querySelectorAll(".fixed--theme span").forEach(function(e) { e.classList.remove("is-active") }), "dark" == e.dataset.actionValue ? (localStorage.setItem("theme", "dark"), document.querySelector("body").classList.remove("auto"), document.querySelector("body").classList.add("dark"), e.classList.add("is-active")) : "light" == e.dataset.actionValue ? (localStorage.setItem("theme", "light"), document.querySelector("body").classList.remove("auto"), document.querySelector("body").classList.remove("dark"), e.classList.add("is-active")) : "auto" == e.dataset.actionValue && (localStorage.setItem("theme", "auto"), document.querySelector("body").classList.remove("dark"), document.querySelector("body").classList.add("auto"), e.classList.add("is-active"))) }) }), document.querySelector(".post--share") && document.querySelector(".post--share").addEventListener("click", function() { navigator.clipboard.writeText(document.location.href).then(function() { e.showNotice("复制成功") }) }), document.querySelector('[data-action="show-search"]').addEventListener("click", function() { document.querySelector(".site--header__center .inner").classList.toggle("search--active") }), e.is_single && e.trackPostView(), e.is_archive && e.trackArchiveView(), console.log("theme version: ".concat(e.VERSION, " init success!")), '")); return document.querySelector(".site--footer__content").insertAdjacentHTML("afterend", t), document.querySelector(".icon--copryrights").addEventListener("click", function() { document.querySelector(".site--footer__info").classList.toggle("active") }), e } return __extends(e, o), e.prototype.trackPostView = function() { var e = obvInit.post_id, e = obvInit.restfulBase + "farallon/v1/view?id=" + e; fetch(e, { headers: { "X-WP-Nonce": obvInit.nonce, "Content-Type": "application/json" } }).then(function(e) { return e.json() }).then(function(e) { console.log(e) }) }, e.prototype.trackArchiveView = function() { var e; document.querySelector(".archive-header") && (e = obvInit.archive_id, fetch("".concat(obvInit.restfulBase, "farallon/v1/archive/").concat(e), { method: "POST", headers: { "X-WP-Nonce": obvInit.nonce, "Content-Type": "application/json" } }).then(function(e) { return e.json() }).then(function(e) {})) }, e.prototype.handleLike = function() { var t = this; if (this.getCookie("like_" + this.post_id)) return this.showNotice("You have already liked this post"); var e = obvInit.restfulBase + "farallon/v1/like"; fetch(e, { method: "POST", body: JSON.stringify({ id: this.post_id }), headers: { "X-WP-Nonce": obvInit.nonce, "Content-Type": "application/json" } }).then(function(e) { return e.json() }).then(function(e) { t.showNotice("Thanks for your like"), t.setCookie("like_" + t.post_id, "1", 1) }), this.like_btn.classList.add("is-active") }, e.prototype.refresh = function() {}, e }(farallonBase), farallonComment = (new farallonAction, function(t) { function e() { var e = t.call(this) || this; return e.loading = !1, e.init(), e } return __extends(e, t), e.prototype.init = function() { var e, r = this; document.querySelector(".comment-form") && null != (e = document.querySelector(".comment-form")) && e.addEventListener("submit", function(e) { var o; e.preventDefault(), r.loading || (e = document.querySelector(".comment-form"), e = new FormData(e), o = {}, e.forEach(function(e, t) { return o[t] = e }), r.loading = !0, fetch(obvInit.restfulBase + "farallon/v1/comment", { method: "POST", body: JSON.stringify(o), headers: { "X-WP-Nonce": obvInit.nonce, "Content-Type": "application/json" } }).then(function(e) { return e.json() }).then(function(e) { if (r.loading = !1, 200 != e.code) return r.showNotice(e.message, "error"); var t = document.getElementById("cancel-comment-reply-link"), o = document.getElementById("respond"), n = document.getElementById("wp-temp-form-div"), e = e.data, i = '
  • \n
    \n
    \n
    \n \n
    \n
    \n
    ').concat(e.comment_author, '\n \n
    \n
    \n
    \n
    \n ').concat(e.comment_content, "\n
    \n
    \n
  • "), c = null == (c = document.querySelector("#comment_parent")) ? void 0 : c.value, o = (t.style.display = "none", t.onclick = null, document.getElementById("comment_parent").value = "0", n && o && (n.parentNode.insertBefore(o, n), n.parentNode.removeChild(n)), document.querySelector(".comment-body__fresh") && null != (t = document.querySelector(".comment-body__fresh")) && t.classList.remove("comment-body__fresh"), document.getElementById("comment").value = "", "0" != c ? (null != (o = document.querySelector("#comment-" + c)) && o.insertAdjacentHTML("beforeend", '
      ' + i + "
    "), console.log(c)) : (document.querySelector(".no--comment") && null != (n = document.querySelector(".no--comment")) && n.remove(), null != (t = document.querySelector(".commentlist")) && t.insertAdjacentHTML("beforeend", i)), document.querySelector("#comment-".concat(e.comment_ID))); o && o.scrollIntoView({ behavior: "smooth" }), r.showNotice("评论成功") })) }) }, e }(farallonBase)), farallonDate = (new farallonComment, function() { function e(e) { var t = this; this.timeFormat = { second: "second ago", seconds: "seconds ago", minute: "minute ago", minutes: "minutes ago", hour: "hour ago", hours: "hours ago", day: "day ago", days: "days ago", week: "week ago", weeks: "weeks ago", month: "month ago", months: "months ago", year: "year ago", years: "years ago" }, this.doms = [], this.selector = e.selector, e.timeFormat && (this.timeFormat = e.timeFormat), this.init(), setTimeout(function() { t.refresh() }, 5e3) } return e.prototype.init = function() { var t = this; this.doms = Array.from(document.querySelectorAll(this.selector)), this.doms.forEach(function(e) { e.innerText = t.humanize_time_ago(e.attributes.datetime.value) }) }, e.prototype.humanize_time_ago = function(e) { var e = new Date(e), t = Date.now() / 1e3 - Number(e.getTime() / 1e3); return t < 3600 ? "".concat(Math.ceil(t / 60), " ").concat(1 == Math.ceil(t / 60) ? this.timeFormat.second : this.timeFormat.seconds) : t < 86400 ? "".concat(Math.ceil(t / 3600), " ").concat(1 == Math.ceil(t / 3660) ? this.timeFormat.hour : this.timeFormat.hours) : t < 2592e3 ? "".concat(Math.ceil(t / 86400), " ").concat(1 == Math.ceil(t / 86400) ? this.timeFormat.day : this.timeFormat.days) : t < 31104e3 ? "".concat(Math.ceil(t / 2592e3), " ").concat(1 == Math.ceil(t / 2592e3) ? this.timeFormat.month : this.timeFormat.months) : e.getFullYear() + "-" + (e.getMonth() + 1) + "-" + e.getDate() }, e.prototype.refresh = function() { var t = this; this.doms.forEach(function(e) { e.innerText = t.humanize_time_ago(e.attributes.datetime.value) }) }, e }()), farallonPost = (new farallonDate({ selector: ".humane--time", timeFormat: obvInit.timeFormat }), function(t) { function e() { var e = t.call(this) || this; return e.loading = !1, e.page = 1, e.init(), e } return __extends(e, t), e.prototype.init = function() { var e, t = this; document.querySelector(".loadmore") && (this.button = document.querySelector(".loadmore"), null != (e = document.querySelector(".loadmore"))) && e.addEventListener("click", function(e) { e.preventDefault(), t.loading || (t.loading = !0, t.page++, t.fetchPosts()) }) }, e.prototype.randerPosts = function(e) { var t, e = e.map(function(e) { var t = obvInit.hide_home_cover || !e.has_image ? "" : '\n ').concat(e.post_title, '\n '); return '
    \n
    \n

    \n \n ').concat(e.post_title, '\n

    \n
    ').concat(e.excerpt, '
    \n
    \n \n \n \n \n
    \n
    ").concat(t, "\n
    ") }).join(""); null != (t = document.querySelector(".posts--list")) && (t.innerHTML += e) }, e.prototype.fetchPosts = function() { var o = this; this.button.innerHTML = "加载中...", fetch(obvInit.restfulBase + "farallon/v1/posts?page=" + this.page, { method: "get", headers: { "X-WP-Nonce": obvInit.nonce, "Content-Type": "application/json" } }).then(function(e) { return e.json() }).then(function(e) { var t; if (o.loading = !1, 200 != e.code) return o.showNotice(e.message, "error"); 0 == e.data.length ? (null != (t = document.querySelector(".loadmore")) && t.remove(), o.showNotice("没有更多文章了", "error")) : (o.randerPosts(e.data), o.showNotice("加载成功", "error")), o.button.innerHTML = "加载更多" }) }, e }(farallonBase)), farallonScroll = (new farallonPost, function() { function e() { var e; this.is_single = !1, this.is_single = obvInit.is_single, this.init(), document.querySelector(".backToTop") && (e = document.querySelector(".backToTop"), window.addEventListener("scroll", function() { 200 < (window.scrollY || window.pageYOffset) ? e.classList.add("is-active") : e.classList.remove("is-active") }), e.addEventListener("click", function() { window.scrollTo({ top: 0, behavior: "smooth" }) })) } return e.prototype.init = function() { this.scroll() }, e.prototype.scroll = function() { var t = this, e = document.querySelector(".post-navigation"), o = e ? e.offsetTop : 0, n = window.innerHeight; window.addEventListener("scroll", function() { var e; 10 < window.scrollY ? null != (e = document.querySelector(".site--header")) && e.classList.add("is-active") : null != (e = document.querySelector(".site--header")) && e.classList.remove("is-active"), t.is_single && (window.scrollY > o - n ? null != (e = document.querySelector(".post-navigation")) && e.classList.add("is-active") : null != (e = document.querySelector(".post-navigation")) && e.classList.remove("is-active")) }) }, e }()); new farallonScroll;