/*! store2 - v2.14.2 - 2022-07-18
* Copyright (c) 2022 Nathan Bubna; Licensed (MIT OR GPL-3.0) */

!function (a, b) {
    var c = {
        version: "2.14.2", areas: {}, apis: {}, nsdelim: ".", inherit: function (a, b) {
            for (var c in a) b.hasOwnProperty(c) || Object.defineProperty(b, c, Object.getOwnPropertyDescriptor(a, c));
            return b
        }, stringify: function (a, b) {
            return void 0 === a || "function" == typeof a ? a + "" : JSON.stringify(a, b || c.replace)
        }, parse: function (a, b) {
            try {
                return JSON.parse(a, b || c.revive)
            } catch (b) {
                return a
            }
        }, fn: function (a, b) {
            c.storeAPI[a] = b;
            for (var d in c.apis) c.apis[d][a] = b
        }, get: function (a, b) {
            return a.getItem(b)
        }, set: function (a, b, c) {
            a.setItem(b, c)
        }, remove: function (a, b) {
            a.removeItem(b)
        }, key: function (a, b) {
            return a.key(b)
        }, length: function (a) {
            return a.length
        }, clear: function (a) {
            a.clear()
        }, Store: function (a, b, d) {
            var e = c.inherit(c.storeAPI, function (a, b, c) {
                return 0 === arguments.length ? e.getAll() : "function" == typeof b ? e.transact(a, b, c) : void 0 !== b ? e.set(a, b, c) : "string" == typeof a || "number" == typeof a ? e.get(a) : "function" == typeof a ? e.each(a) : a ? e.setAll(a, b) : e.clear()
            });
            e._id = a;
            try {
                b.setItem("__store2_test", "ok"), e._area = b, b.removeItem("__store2_test")
            } catch (a) {
                e._area = c.storage("fake")
            }
            return e._ns = d || "", c.areas[a] || (c.areas[a] = e._area), c.apis[e._ns + e._id] || (c.apis[e._ns + e._id] = e), e
        }, storeAPI: {
            area: function (a, b) {
                var d = this[a];
                return d && d.area || (d = c.Store(a, b, this._ns), this[a] || (this[a] = d)), d
            }, namespace: function (a, b, d) {
                if (d = d || this._delim || c.nsdelim, !a) return this._ns ? this._ns.substring(0, this._ns.length - d.length) : "";
                var e = a, f = this[e];
                if (!(f && f.namespace || (f = c.Store(this._id, this._area, this._ns + e + d), f._delim = d, this[e] || (this[e] = f), b))) for (var g in c.areas) f.area(g, c.areas[g]);
                return f
            }, isFake: function (a) {
                return a ? (this._real = this._area, this._area = c.storage("fake")) : !1 === a && (this._area = this._real || this._area), "fake" === this._area.name
            }, toString: function () {
                return "store" + (this._ns ? "." + this.namespace() : "") + "[" + this._id + "]"
            }, has: function (a) {
                return this._area.has ? this._area.has(this._in(a)) : !!(this._in(a) in this._area)
            }, size: function () {
                return this.keys().length
            }, each: function (a, b) {
                for (var d = 0, e = c.length(this._area); d < e; d++) {
                    var f = this._out(c.key(this._area, d));
                    if (void 0 !== f && !1 === a.call(this, f, this.get(f), b)) break;
                    e > c.length(this._area) && (e--, d--)
                }
                return b || this
            }, keys: function (a) {
                return this.each(function (a, b, c) {
                    c.push(a)
                }, a || [])
            }, get: function (a, b) {
                var d, e = c.get(this._area, this._in(a));
                return "function" == typeof b && (d = b, b = null), null !== e ? c.parse(e, d) : null != b ? b : e
            }, getAll: function (a) {
                return this.each(function (a, b, c) {
                    c[a] = b
                }, a || {})
            }, transact: function (a, b, c) {
                var d = this.get(a, c), e = b(d);
                return this.set(a, void 0 === e ? d : e), this
            }, set: function (a, b, d) {
                var e, f = this.get(a);
                return null != f && !1 === d ? b : ("function" == typeof d && (e = d, d = void 0), c.set(this._area, this._in(a), c.stringify(b, e), d) || f)
            }, setAll: function (a, b) {
                var c, d;
                for (var e in a) d = a[e], this.set(e, d, b) !== d && (c = !0);
                return c
            }, add: function (a, b, d) {
                var e = this.get(a);
                if (e instanceof Array) b = e.concat(b); else if (null !== e) {
                    var f = typeof e;
                    if (f === typeof b && "object" === f) {
                        for (var g in b) e[g] = b[g];
                        b = e
                    } else b = e + b
                }
                return c.set(this._area, this._in(a), c.stringify(b, d)), b
            }, remove: function (a, b) {
                var d = this.get(a, b);
                return c.remove(this._area, this._in(a)), d
            }, clear: function () {
                return this._ns ? this.each(function (a) {
                    c.remove(this._area, this._in(a))
                }, 1) : c.clear(this._area), this
            }, clearAll: function () {
                var a = this._area;
                for (var b in c.areas) c.areas.hasOwnProperty(b) && (this._area = c.areas[b], this.clear());
                return this._area = a, this
            }, _in: function (a) {
                return "string" != typeof a && (a = c.stringify(a)), this._ns ? this._ns + a : a
            }, _out: function (a) {
                return this._ns ? a && 0 === a.indexOf(this._ns) ? a.substring(this._ns.length) : void 0 : a
            }
        }, storage: function (a) {
            return c.inherit(c.storageAPI, {items: {}, name: a})
        }, storageAPI: {
            length: 0, has: function (a) {
                return this.items.hasOwnProperty(a)
            }, key: function (a) {
                var b = 0;
                for (var c in this.items) if (this.has(c) && a === b++) return c
            }, setItem: function (a, b) {
                this.has(a) || this.length++, this.items[a] = b
            }, removeItem: function (a) {
                this.has(a) && (delete this.items[a], this.length--)
            }, getItem: function (a) {
                return this.has(a) ? this.items[a] : null
            }, clear: function () {
                for (var a in this.items) this.removeItem(a)
            }
        }
    }, d = c.Store("local", function () {
        try {
            return localStorage
        } catch (a) {
        }
    }());
    d.local = d, d._ = c, d.area("session", function () {
        try {
            return sessionStorage
        } catch (a) {
        }
    }()), d.area("page", c.storage("page")), "function" == typeof b && void 0 !== b.amd ? b("store2", [], function () {
        return d
    }) : "undefined" != typeof module && module.exports ? module.exports = d : (a.store && (c.conflict = a.store), a.store = d)
}(this, this && this.define);
//# sourceMappingURL=store2.min.js.map
/*! lazysizes - v5.3.2 */

!function (e) {
    var t = function (u, D, f) {
        "use strict";
        var k, H;
        if (function () {
            var e;
            var t = {
                lazyClass: "lazyload",
                loadedClass: "lazyloaded",
                loadingClass: "lazyloading",
                preloadClass: "lazypreload",
                errorClass: "lazyerror",
                autosizesClass: "lazyautosizes",
                fastLoadedClass: "ls-is-cached",
                iframeLoadMode: 0,
                srcAttr: "data-src",
                srcsetAttr: "data-srcset",
                sizesAttr: "data-sizes",
                minSize: 40,
                customMedia: {},
                init: true,
                expFactor: 1.5,
                hFac: .8,
                loadMode: 2,
                loadHidden: true,
                ricTimeout: 0,
                throttleDelay: 125
            };
            H = u.lazySizesConfig || u.lazysizesConfig || {};
            for (e in t) {
                if (!(e in H)) {
                    H[e] = t[e]
                }
            }
        }(), !D || !D.getElementsByClassName) {
            return {
                init: function () {
                }, cfg: H, noSupport: true
            }
        }
        var O = D.documentElement, i = u.HTMLPictureElement, P = "addEventListener", $ = "getAttribute",
            q = u[P].bind(u), I = u.setTimeout, U = u.requestAnimationFrame || I, o = u.requestIdleCallback,
            j = /^picture$/i, r = ["load", "error", "lazyincluded", "_lazyloaded"], a = {}, G = Array.prototype.forEach,
            J = function (e, t) {
                if (!a[t]) {
                    a[t] = new RegExp("(\\s|^)" + t + "(\\s|$)")
                }
                return a[t].test(e[$]("class") || "") && a[t]
            }, K = function (e, t) {
                if (!J(e, t)) {
                    e.setAttribute("class", (e[$]("class") || "").trim() + " " + t)
                }
            }, Q = function (e, t) {
                var a;
                if (a = J(e, t)) {
                    e.setAttribute("class", (e[$]("class") || "").replace(a, " "))
                }
            }, V = function (t, a, e) {
                var i = e ? P : "removeEventListener";
                if (e) {
                    V(t, a)
                }
                r.forEach(function (e) {
                    t[i](e, a)
                })
            }, X = function (e, t, a, i, r) {
                var n = D.createEvent("Event");
                if (!a) {
                    a = {}
                }
                a.instance = k;
                n.initEvent(t, !i, !r);
                n.detail = a;
                e.dispatchEvent(n);
                return n
            }, Y = function (e, t) {
                var a;
                if (!i && (a = u.picturefill || H.pf)) {
                    if (t && t.src && !e[$]("srcset")) {
                        e.setAttribute("srcset", t.src)
                    }
                    a({reevaluate: true, elements: [e]})
                } else if (t && t.src) {
                    e.src = t.src
                }
            }, Z = function (e, t) {
                return (getComputedStyle(e, null) || {})[t]
            }, s = function (e, t, a) {
                a = a || e.offsetWidth;
                while (a < H.minSize && t && !e._lazysizesWidth) {
                    a = t.offsetWidth;
                    t = t.parentNode
                }
                return a
            }, ee = function () {
                var a, i;
                var t = [];
                var r = [];
                var n = t;
                var s = function () {
                    var e = n;
                    n = t.length ? r : t;
                    a = true;
                    i = false;
                    while (e.length) {
                        e.shift()()
                    }
                    a = false
                };
                var e = function (e, t) {
                    if (a && !t) {
                        e.apply(this, arguments)
                    } else {
                        n.push(e);
                        if (!i) {
                            i = true;
                            (D.hidden ? I : U)(s)
                        }
                    }
                };
                e._lsFlush = s;
                return e
            }(), te = function (a, e) {
                return e ? function () {
                    ee(a)
                } : function () {
                    var e = this;
                    var t = arguments;
                    ee(function () {
                        a.apply(e, t)
                    })
                }
            }, ae = function (e) {
                var a;
                var i = 0;
                var r = H.throttleDelay;
                var n = H.ricTimeout;
                var t = function () {
                    a = false;
                    i = f.now();
                    e()
                };
                var s = o && n > 49 ? function () {
                    o(t, {timeout: n});
                    if (n !== H.ricTimeout) {
                        n = H.ricTimeout
                    }
                } : te(function () {
                    I(t)
                }, true);
                return function (e) {
                    var t;
                    if (e = e === true) {
                        n = 33
                    }
                    if (a) {
                        return
                    }
                    a = true;
                    t = r - (f.now() - i);
                    if (t < 0) {
                        t = 0
                    }
                    if (e || t < 9) {
                        s()
                    } else {
                        I(s, t)
                    }
                }
            }, ie = function (e) {
                var t, a;
                var i = 99;
                var r = function () {
                    t = null;
                    e()
                };
                var n = function () {
                    var e = f.now() - a;
                    if (e < i) {
                        I(n, i - e)
                    } else {
                        (o || r)(r)
                    }
                };
                return function () {
                    a = f.now();
                    if (!t) {
                        t = I(n, i)
                    }
                }
            }, e = function () {
                var v, m, c, h, e;
                var y, z, g, p, C, b, A;
                var n = /^img$/i;
                var d = /^iframe$/i;
                var E = "onscroll" in u && !/(gle|ing)bot/.test(navigator.userAgent);
                var _ = 0;
                var w = 0;
                var M = 0;
                var N = -1;
                var L = function (e) {
                    M--;
                    if (!e || M < 0 || !e.target) {
                        M = 0
                    }
                };
                var x = function (e) {
                    if (A == null) {
                        A = Z(D.body, "visibility") == "hidden"
                    }
                    return A || !(Z(e.parentNode, "visibility") == "hidden" && Z(e, "visibility") == "hidden")
                };
                var W = function (e, t) {
                    var a;
                    var i = e;
                    var r = x(e);
                    g -= t;
                    b += t;
                    p -= t;
                    C += t;
                    while (r && (i = i.offsetParent) && i != D.body && i != O) {
                        r = (Z(i, "opacity") || 1) > 0;
                        if (r && Z(i, "overflow") != "visible") {
                            a = i.getBoundingClientRect();
                            r = C > a.left && p < a.right && b > a.top - 1 && g < a.bottom + 1
                        }
                    }
                    return r
                };
                var t = function () {
                    var e, t, a, i, r, n, s, o, l, u, f, c;
                    var d = k.elements;
                    if ((h = H.loadMode) && M < 8 && (e = d.length)) {
                        t = 0;
                        N++;
                        for (; t < e; t++) {
                            if (!d[t] || d[t]._lazyRace) {
                                continue
                            }
                            if (!E || k.prematureUnveil && k.prematureUnveil(d[t])) {
                                R(d[t]);
                                continue
                            }
                            if (!(o = d[t][$]("data-expand")) || !(n = o * 1)) {
                                n = w
                            }
                            if (!u) {
                                u = !H.expand || H.expand < 1 ? O.clientHeight > 500 && O.clientWidth > 500 ? 500 : 370 : H.expand;
                                k._defEx = u;
                                f = u * H.expFactor;
                                c = H.hFac;
                                A = null;
                                if (w < f && M < 1 && N > 2 && h > 2 && !D.hidden) {
                                    w = f;
                                    N = 0
                                } else if (h > 1 && N > 1 && M < 6) {
                                    w = u
                                } else {
                                    w = _
                                }
                            }
                            if (l !== n) {
                                y = innerWidth + n * c;
                                z = innerHeight + n;
                                s = n * -1;
                                l = n
                            }
                            a = d[t].getBoundingClientRect();
                            if ((b = a.bottom) >= s && (g = a.top) <= z && (C = a.right) >= s * c && (p = a.left) <= y && (b || C || p || g) && (H.loadHidden || x(d[t])) && (m && M < 3 && !o && (h < 3 || N < 4) || W(d[t], n))) {
                                R(d[t]);
                                r = true;
                                if (M > 9) {
                                    break
                                }
                            } else if (!r && m && !i && M < 4 && N < 4 && h > 2 && (v[0] || H.preloadAfterLoad) && (v[0] || !o && (b || C || p || g || d[t][$](H.sizesAttr) != "auto"))) {
                                i = v[0] || d[t]
                            }
                        }
                        if (i && !r) {
                            R(i)
                        }
                    }
                };
                var a = ae(t);
                var S = function (e) {
                    var t = e.target;
                    if (t._lazyCache) {
                        delete t._lazyCache;
                        return
                    }
                    L(e);
                    K(t, H.loadedClass);
                    Q(t, H.loadingClass);
                    V(t, B);
                    X(t, "lazyloaded")
                };
                var i = te(S);
                var B = function (e) {
                    i({target: e.target})
                };
                var T = function (e, t) {
                    var a = e.getAttribute("data-load-mode") || H.iframeLoadMode;
                    if (a == 0) {
                        e.contentWindow.location.replace(t)
                    } else if (a == 1) {
                        e.src = t
                    }
                };
                var F = function (e) {
                    var t;
                    var a = e[$](H.srcsetAttr);
                    if (t = H.customMedia[e[$]("data-media") || e[$]("media")]) {
                        e.setAttribute("media", t)
                    }
                    if (a) {
                        e.setAttribute("srcset", a)
                    }
                };
                var s = te(function (t, e, a, i, r) {
                    var n, s, o, l, u, f;
                    if (!(u = X(t, "lazybeforeunveil", e)).defaultPrevented) {
                        if (i) {
                            if (a) {
                                K(t, H.autosizesClass)
                            } else {
                                t.setAttribute("sizes", i)
                            }
                        }
                        s = t[$](H.srcsetAttr);
                        n = t[$](H.srcAttr);
                        if (r) {
                            o = t.parentNode;
                            l = o && j.test(o.nodeName || "")
                        }
                        f = e.firesLoad || "src" in t && (s || n || l);
                        u = {target: t};
                        K(t, H.loadingClass);
                        if (f) {
                            clearTimeout(c);
                            c = I(L, 2500);
                            V(t, B, true)
                        }
                        if (l) {
                            G.call(o.getElementsByTagName("source"), F)
                        }
                        if (s) {
                            t.setAttribute("srcset", s)
                        } else if (n && !l) {
                            if (d.test(t.nodeName)) {
                                T(t, n)
                            } else {
                                t.src = n
                            }
                        }
                        if (r && (s || l)) {
                            Y(t, {src: n})
                        }
                    }
                    if (t._lazyRace) {
                        delete t._lazyRace
                    }
                    Q(t, H.lazyClass);
                    ee(function () {
                        var e = t.complete && t.naturalWidth > 1;
                        if (!f || e) {
                            if (e) {
                                K(t, H.fastLoadedClass)
                            }
                            S(u);
                            t._lazyCache = true;
                            I(function () {
                                if ("_lazyCache" in t) {
                                    delete t._lazyCache
                                }
                            }, 9)
                        }
                        if (t.loading == "lazy") {
                            M--
                        }
                    }, true)
                });
                var R = function (e) {
                    if (e._lazyRace) {
                        return
                    }
                    var t;
                    var a = n.test(e.nodeName);
                    var i = a && (e[$](H.sizesAttr) || e[$]("sizes"));
                    var r = i == "auto";
                    if ((r || !m) && a && (e[$]("src") || e.srcset) && !e.complete && !J(e, H.errorClass) && J(e, H.lazyClass)) {
                        return
                    }
                    t = X(e, "lazyunveilread").detail;
                    if (r) {
                        re.updateElem(e, true, e.offsetWidth)
                    }
                    e._lazyRace = true;
                    M++;
                    s(e, t, r, i, a)
                };
                var r = ie(function () {
                    H.loadMode = 3;
                    a()
                });
                var o = function () {
                    if (H.loadMode == 3) {
                        H.loadMode = 2
                    }
                    r()
                };
                var l = function () {
                    if (m) {
                        return
                    }
                    if (f.now() - e < 999) {
                        I(l, 999);
                        return
                    }
                    m = true;
                    H.loadMode = 3;
                    a();
                    q("scroll", o, true)
                };
                return {
                    _: function () {
                        e = f.now();
                        k.elements = D.getElementsByClassName(H.lazyClass);
                        v = D.getElementsByClassName(H.lazyClass + " " + H.preloadClass);
                        q("scroll", a, true);
                        q("resize", a, true);
                        q("pageshow", function (e) {
                            if (e.persisted) {
                                var t = D.querySelectorAll("." + H.loadingClass);
                                if (t.length && t.forEach) {
                                    U(function () {
                                        t.forEach(function (e) {
                                            if (e.complete) {
                                                R(e)
                                            }
                                        })
                                    })
                                }
                            }
                        });
                        if (u.MutationObserver) {
                            new MutationObserver(a).observe(O, {childList: true, subtree: true, attributes: true})
                        } else {
                            O[P]("DOMNodeInserted", a, true);
                            O[P]("DOMAttrModified", a, true);
                            setInterval(a, 999)
                        }
                        q("hashchange", a, true);
                        ["focus", "mouseover", "click", "load", "transitionend", "animationend"].forEach(function (e) {
                            D[P](e, a, true)
                        });
                        if (/d$|^c/.test(D.readyState)) {
                            l()
                        } else {
                            q("load", l);
                            D[P]("DOMContentLoaded", a);
                            I(l, 2e4)
                        }
                        if (k.elements.length) {
                            t();
                            ee._lsFlush()
                        } else {
                            a()
                        }
                    }, checkElems: a, unveil: R, _aLSL: o
                }
            }(), re = function () {
                var a;
                var n = te(function (e, t, a, i) {
                    var r, n, s;
                    e._lazysizesWidth = i;
                    i += "px";
                    e.setAttribute("sizes", i);
                    if (j.test(t.nodeName || "")) {
                        r = t.getElementsByTagName("source");
                        for (n = 0, s = r.length; n < s; n++) {
                            r[n].setAttribute("sizes", i)
                        }
                    }
                    if (!a.detail.dataAttr) {
                        Y(e, a.detail)
                    }
                });
                var i = function (e, t, a) {
                    var i;
                    var r = e.parentNode;
                    if (r) {
                        a = s(e, r, a);
                        i = X(e, "lazybeforesizes", {width: a, dataAttr: !!t});
                        if (!i.defaultPrevented) {
                            a = i.detail.width;
                            if (a && a !== e._lazysizesWidth) {
                                n(e, r, i, a)
                            }
                        }
                    }
                };
                var e = function () {
                    var e;
                    var t = a.length;
                    if (t) {
                        e = 0;
                        for (; e < t; e++) {
                            i(a[e])
                        }
                    }
                };
                var t = ie(e);
                return {
                    _: function () {
                        a = D.getElementsByClassName(H.autosizesClass);
                        q("resize", t)
                    }, checkElems: t, updateElem: i
                }
            }(), t = function () {
                if (!t.i && D.getElementsByClassName) {
                    t.i = true;
                    re._();
                    e._()
                }
            };
        return I(function () {
            H.init && t()
        }), k = {cfg: H, autoSizer: re, loader: e, init: t, uP: Y, aC: K, rC: Q, hC: J, fire: X, gW: s, rAF: ee}
    }(e, e.document, Date);
    e.lazySizes = t, "object" == typeof module && module.exports && (module.exports = t)
}("undefined" != typeof window ? window : {});


//正常開始
/**
 *持久存儲
 * @param name
 * @param data
 */
function setStore(name, data) {
    store.set(name, {value: data})
}

function getDeviceTypes() {
    if (androidDetection) {
        return 'android';

    } else if (iosDetection) {
        return 'ios';
    } else if (windowsPhoneDetection) {
        return 'windows';
    } else return 'ios';
}

/**
 *僅本次會話生效
 * @param name
 * @param data
 */
function setSession(name, data) {
    store.session(name, {value: data})
}

/**
 *
 * @param name
 * @param data
 * @returns   {undefined}
 */
function getSession(name) {
    var sessionData = store.session(name);
    if (sessionData == undefined || sessionData == null)
        return undefined;
    return sessionData.value;
}

/**
 * 如果未定義返回undefined
 * @param name
 * @returns {undefined|*}
 */
function getStore(name) {
    var getStore = store.get(name);
    if (getStore === null || getStore === undefined)
        return undefined;
    return getStore.value;
}

function getMacHost() {
    let cacheApi = getSession('machost')
    if (cacheApi != undefined && cacheApi.indexOf("http") >= 0)
        return cacheApi;
    else
        return "https://jsonv8.2024api2.top/";
}

function setMacHost(val) {
    setSession('machost', val)
    alert('设置线路成功！即将刷新，下次进入请重新设置。')
    location.reload();
}

function createBindLink(bindClass, getVal) {

    if (bindClass == undefined) {
        return;
    }

    $(bindClass).attr('href', "/list/?" + $.param(getVal))

}

function getElementVal(element) {
    function CheckUndefined(getData, getName) {
        if (getData == undefined)
            return getQueryParam(getName);
        else return getData;
    }

    let dname = CheckUndefined($(element).attr('data-name'), 'dname');


    let mode = CheckUndefined($(element).attr('data-mode'), 'mode');
    let pg = CheckUndefined($(element).attr('data-pg'), 'pg');
    let keys = CheckUndefined($(element).attr('data-key'), 'key');

    let catid = CheckUndefined($(element).attr('data-catid'), 'catid');

    let tag = CheckUndefined($(element).attr('data-tag'), 'tags');
    let getVal = {
        'dname': dname,
        'pg': pg,
        'catid': catid,
        'key': keys,
        'mode': mode,
        'tags': tag,

        'v70': theme_ver + new Date().getDate()

    }

    return getVal
}

function createRecommend(element) {
    let getVal = getElementVal(element)
    let getUiClass = $(element).attr('data-class');
    let getImgUiClass = $(element).attr('data-img-class');
    let max = $(element).attr('data-max');
    let bindClass = $(element).attr('data-nav-bind');
    getVal.random = new Date().toLocaleTimeString().replace(/:/g, '_');
    $.getJSON(getMacHost() + "json-api/?" + $.param(getVal), function (data) {
        console.log(data)
        if (data) {

            $.each(data.posts, function (idx, val) {
                //       console.error(val)

                $(element).append(generateMonGoCardCode(getUiClass, getImgUiClass,
                    val, getVal))

                //  console.error(max)
                if (max-- == 1)
                    return false;
                //  $('.my-list-spinner').hide()
                //  addCard('.my-post-row', val, dname)
            })
        }

        //  addPageNav(dname, catid, keys, data.page, data.pages)
    });

}

function createViewBox(element) {
    let getUiClass = $(element).attr('data-class');
    let getImgUiClass = $(element).attr('data-img-class');
    let max = $(element).attr('data-max');
    let bindClass = $(element).attr('data-nav-bind');
    /*
    let dname = $(element).attr('data-name');
    let getUiClass = $(element).attr('data-class');
    let getImgUiClass = $(element).attr('data-img-class');
    let mode = $(element).attr('data-mode');
    let pg = $(element).attr('data-pg');
    let keys = $(element).attr('data-key');
    let catid = $(element).attr('data-catid');
    let tag = $(element).attr('data-tag');
    let max = $(element).attr('data-max');
    let bindClass= $(element).attr('data-nav-bind');
   */


    let getVal = getElementVal(element)
    createBindLink(bindClass, getVal)
    $.getJSON(getMacHost() + "json-api/?" + $.param(getVal), function (data) {
        console.log(data)
        if (data) {

            $.each(data.posts, function (idx, val) {
                //       console.error(val)

                $(element).append(generateMonGoCardCode(getUiClass, getImgUiClass,
                    val, getVal))

                //  console.error(max)
                if (max-- == 1)
                    return false;
                //  $('.my-list-spinner').hide()
                //  addCard('.my-post-row', val, dname)
            })
            $(".list-count-set").text("共" + data.count + "结果");
            $(element).append(generatePagination(data.page, data.pages))
            $('.my-loading').hide()
        }


        autoSetViewLink('.my-auto-link')


        //  addPageNav(dname, catid, keys, data.page, data.pages)
    });
}

function autoSetViewLink(element) {

    $.each($(element), function (idx, val) {
        let getVal = getElementVal(val)
        createBindLink(val, getVal)

    })
}

function getCurrentTimestamp() {
    var currentTime = new Date();
    currentTime.setSeconds(0, 0); // 将秒数和毫秒数设为0
    var timestamp = Math.floor(currentTime.getTime() / 1000); // 获取当前时间的时间戳（精确到秒）
    return timestamp;
}

function formatTimestamp(timestamp) {
    // console.error(timestamp)
    var date = new Date(timestamp);
    var year = date.getFullYear();
    var month = ('0' + (date.getMonth() + 1)).slice(-2);
    var day = ('0' + date.getDate()).slice(-2);
    var formattedDate = month + '/' + day;
    return formattedDate;
}

function getContent_ImgUtils(vod_content) {
//首先尝试将vod_content转换为json，要做异常捕获
    try {

        //先判断vod_content是否包含图片类型，如果不包含直接返回空
        if (vod_content.indexOf("images") < 0) {
            return "";
        }

        let content = JSON.parse(vod_content);
     //   console.error(content)
        if (content != undefined && content.eps.length > 0) {
            //从content.images 随机取一张图片
            let img = content.eps[0].images;
            if (img != undefined && img.length > 0) {
                return img[Math.floor(Math.random() * img.length)]
            }

            return img;
        }
    } catch (e) {
        console.error(e)
    }
    return "";
}

function generateMonGoCardCode(className, getImgUiClass, val, getVal) {
    let getSet = {
        'id': val._id.$oid,
        'dname': getVal.dname,
        'catid': getVal.catid,
    }
    let pubtime = '2000/00/00';
    if (val.vod_time != undefined && val.vod_time.$date != undefined)
        pubtime = formatTimestamp(parseInt(val.vod_time.$date.$numberLong))
    let get_error_images = GetImgUtils(getContent_ImgUtils(val.vod_content));

    let code = `<div class="${className}" xmlns="http://www.w3.org/1999/html"><a href="/content/?${$.param(getSet)}">
                <div class="card">
                    <div class="card-img p-2 ribbon ribbon-top ">
                    <div class="ribbon-label bg-light-danger text-danger">${
        pubtime +
        '<span class="ms-2  ki-solid ki-star text-light fw-bold text-danger">' + (val.view || 0)
    }</span></div>
                     <img class="w-100 lazyload ${getImgUiClass}" data-error="${get_error_images}"
                      data-src="${GetImgUtils(val.vod_pic)}">
                    </div>
                    <h4 class="card-title two-lines text-center ps-2 pe-2 text-danger fw-bold">${val.vod_name}</h4></a>
                    <div class="card-footer p-1">`;
    let tags = val.vod_tag;
    if (tags) {
        tags.sort((a, b) => a.length - b.length);
        for (let i = 0; i < tags.length; i++) {
            if (i === 4) {
                break; // 在第五个tag后跳出循环
            }
            code += `<a class="my-auto-link" data-name="${getVal.dname}"  data-tag="${tags[i]}"><span  class="badge badge-lg badge-light-danger  m-1 my-auto-add">${tags[i]}</span></a>`;
        }
    }

    code += `</div>
                </div>
            </div>`;

    return code;
}


function getQueryParam(paramName) {
    const urlParams = new URLSearchParams(window.location.search);
    if (urlParams.has(paramName)) {
        return urlParams.get(paramName);
    }
    return "";
}

function getPlayerList(playerData) {
    let allPlayer = [];

    if (!playerData) {
        return [];
    }

    const playerSegments = playerData.split("$$$");

    playerSegments.forEach(segment => {
        const diversityVals = segment.split("#");

        diversityVals.forEach(diversityVal => {
            const splitVod = diversityVal.split('$');

            if (splitVod.length >= 2) {
                if (splitVod[1].indexOf('.m3u8') > 0) {
                    allPlayer.push({'title': splitVod[0], 'player': splitVod[1]});
                }
            } else if (splitVod.length === 1 && diversityVal.indexOf('.m3u8') > 0) {
                allPlayer.push({'title': '开始播放', 'player': diversityVal});
            }
        });
    });

    return allPlayer;
}


function generatePagination(currentPage, maxPage) {
    var dname = getQueryParam('dname');
    if (dname == '')
        return;
    var paginationHTML = '<ul class="pagination">';

    // Previous button
    paginationHTML += `
        <li class="page-item previous hover-elevate-up text-hover-danger">
            <a class="my-auto-link page-link text-hover-danger" data-name="${dname}" data-pg="1">
                <i class="previous text-hover-danger"></i><i class="previous text-hover-danger"></i>
            </a>
        </li>
          <li class="page-item previous hover-elevate-up text-hover-danger">
            <a class="my-auto-link page-link text-hover-danger" data-name="${dname}" data-pg="${(currentPage - 1)}}">
                <i class="previous text-hover-danger"></i>
            </a>
        </li>
    `;
    let defaultPg = 4;

    if (window.innerWidth < 400) {
        defaultPg = 1;
    } else if (window.innerWidth < 600) {
        defaultPg = 3;
    }
    // Page numbers
    for (var i = currentPage - defaultPg; i <= currentPage + defaultPg; i++) {
        if (i >= 1 && i <= maxPage) {
            paginationHTML += `
                <li class="page-item hover-elevate-up ${i === currentPage ? 'active  bg-danger text-white ' : ''}">
                    <a class="my-auto-link text-hover-danger page-link ${i === currentPage ? 'active  bg-danger text-white ' : ''}" data-name="${dname}" data-pg="${i}">${i}</a>
                </li>
            `;
        }
    }
    console.error(currentPage)
    // Next button
    paginationHTML += `
        <li class="page-item next hover-elevate-up text-hover-danger">
        <a class="my-auto-link page-link text-hover-danger" data-name="${dname}" data-pg="${(currentPage + 1)}"> <i class="next"></i></a>
        </li>
          <li class="page-item next hover-elevate-up text-hover-danger">
            <a class="my-auto-link page-link text-hover-danger" data-name="${dname}" data-pg="${maxPage}"><i class="next"></i><i class="next"></i></a>
        </li>
    `;

    paginationHTML += '</ul>';

    return paginationHTML;
}

function toast(message, duration = 2000, title = '', smallTitle = '现在') {
    // 创建 toast 元素
    var toast = $('   <div style="z-index: 999" class="position-fixed  end-0 p-3 kt_docs_toast_toggle_box ">\n' +
        '            <div id="kt_docs_toast_toggle" data-bs-delay="' + duration + '" class="toast" role="alert" aria-live="assertive" aria-atomic="true">\n' +
        '                <div class="toast-header">\n' +
        '                    <i class="ki-duotone ki-abstract-19 fs-2 text-danger me-3"><span class="path1"></span><span class="path2"></span></i>\n' +
        '                    <strong class="me-auto">' + title + '</strong>\n' +
        '                    <small>' + smallTitle + '</small>\n' +
        '                    <button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>\n' +
        '                </div>\n' +
        '                <div class="toast-body">\n' +
        message +
        '                </div>\n' +
        '            </div>\n' +
        '        </div>');
    $('#kt_docs_toast_toggle_box').remove()

    // 添加 toast 元素到 body 元素

    toast.appendTo("body");
    const toastElement = document.getElementById('kt_docs_toast_toggle');

    // console.error(toastElement)
// Get toast instance --- more info: https://getbootstrap.com/docs/5.1/components/toasts/#getinstance
    const gettoast = bootstrap.Toast.getOrCreateInstance(toastElement);

    gettoast.show({
        delay: duration
    });
}

function countOccurrences(str, char) {
    var count = 0;
    for (var i = 0; i < str.length; i++) {

        if (str.charAt(i) === char) {
            count++;
        }
    }
    return count;
}


function GetImgUtils(imgUrl) {
    if (typeof imgUrl !== 'string') {
        console.error('imgUrl must be a string');
        console.error(imgUrl)
        return imgUrl;
    }
    imgUrl = imgUrl.replace('img.go2099.com', 'img.study2026.com')
    //console.error(getSession('openCdn') == 1)
    if (getSession('openCdn') == 1 && (countOccurrences(imgUrl, ':') == 1)) {
        imgUrl = imgUrl.replace('https://', 'https://i' + (Math.floor(Math.random() * 3) + 1) + '.wp.com/')
    }

    return imgUrl;
}


document.addEventListener('lazybeforeunveil', function (e) {
    var img = e.target;
    img.onerror = function () {
        var fallbackSrc = img.getAttribute('data-error');
        if (fallbackSrc) {
            img.src = fallbackSrc; // 设置备用图片的路径
            img.setAttribute('data-error', ''); // 清空 data-error 属性
        }
    }
});;