docsify-darklight-theme icon indicating copy to clipboard operation
docsify-darklight-theme copied to clipboard

Error with docsify option onlyCover=true

Open BlackRose01 opened this issue 2 years ago • 2 comments

Hello,

The problem is that when I set the option "onlyCover" to true then docsify is in an infinite render loop.

In my opinion the plugin tries to set the theme switcher button on the cover but on the HTML page of the cover there is no hook for it. But now your script tries to find the HTML tag and use the property "setAttribute". Here it needs a check for NULL.

A Screenshot from the error

image

The content from the specified file

window.$docsify.plugins=[].concat((e,t)=>{let o={siteFont:"PT Sans",defaultTheme:"dark",codeFontFamily:"Roboto Mono, Monaco, courier, monospace",bodyFontSize:"17px",dark:{accent:"#42b983",toogleBackground:"#ffffff",background:"#091a28",toogleImage:"url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/sun.svg)"},light:{accent:"#42b983",toogleBackground:"#091a28",background:"#ffffff",toogleImage:"url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/moon.svg)"}};if(t.config.hasOwnProperty("darklightTheme")){for(var[r,d]of Object.entries(t.config.darklightTheme))"light"!==r&&"dark"!==r&&"defaultTheme"!==r&&(o[r]=d);for(var[r,d]of Object.entries(o))"light"!==r&&"dark"!==r&&(o[r]=d,document.documentElement.style.setProperty("--"+r,d));if(t.config.darklightTheme.hasOwnProperty("dark"))for(var[r,d]of Object.entries(t.config.darklightTheme.dark))o.dark[r]=d;if(t.config.darklightTheme.hasOwnProperty("light"))for(var[r,d]of Object.entries(t.config.darklightTheme.light))o.light[r]=d}else for(var[r,d]of Object.entries(o))"light"!==r&&"dark"!==r&&(o[r]=d,document.documentElement.style.setProperty("--"+r,d));window.matchMedia("(prefers-color-scheme: dark)").matches?o.defaultTheme="dark":window.matchMedia("(prefers-color-scheme: light)").matches&&(o.defaultTheme="light");var i=e=>{if(document.getElementById("docsify-darklight-theme").setAttribute("data-link-title",e),document.getElementById("docsify-darklight-theme").click(),localStorage.setItem("DARK_LIGHT_THEME",e),o.defaultTheme=e,"light"==e)for(var[t,r]of Object.entries(o.light))document.documentElement.style.setProperty("--"+t,r);else if("dark"==e)for(var[t,r]of Object.entries(o.dark))document.documentElement.style.setProperty("--"+t,r)};e.afterEach((function(e,t){t(e='<div id="docsify-darklight-theme"><p>.</p></div>'+e)})),e.doneEach((function(){let e=localStorage.getItem("DARK_LIGHT_THEME");"light"==e||"dark"==e?(o.defaultTheme=e,i(o.defaultTheme)):i(o.defaultTheme),document.getElementById("docsify-darklight-theme").addEventListener("click",(function(){"light"===o.defaultTheme?i("dark"):i("light")}))}))},window.$docsify.plugins);

BlackRose01 avatar Jun 02 '22 12:06 BlackRose01

Maybe a quick-and-dirty fix for this problem

window.$docsify.plugins = [].concat((e, t) => {
    let o = {
        siteFont: "PT Sans",
        defaultTheme: "dark",
        codeFontFamily: "Roboto Mono, Monaco, courier, monospace",
        bodyFontSize: "17px",
        dark: { accent: "#42b983", toogleBackground: "#ffffff", background: "#091a28", toogleImage: "url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/sun.svg)" },
        light: { accent: "#42b983", toogleBackground: "#091a28", background: "#ffffff", toogleImage: "url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/moon.svg)" },
    };
    if (t.config.hasOwnProperty("darklightTheme")) {
        for (var [r, d] of Object.entries(t.config.darklightTheme)) "light" !== r && "dark" !== r && "defaultTheme" !== r && (o[r] = d);
        for (var [r, d] of Object.entries(o)) "light" !== r && "dark" !== r && ((o[r] = d), document.documentElement.style.setProperty("--" + r, d));
        if (t.config.darklightTheme.hasOwnProperty("dark")) for (var [r, d] of Object.entries(t.config.darklightTheme.dark)) o.dark[r] = d;
        if (t.config.darklightTheme.hasOwnProperty("light")) for (var [r, d] of Object.entries(t.config.darklightTheme.light)) o.light[r] = d;
    } else for (var [r, d] of Object.entries(o)) "light" !== r && "dark" !== r && ((o[r] = d), document.documentElement.style.setProperty("--" + r, d));
    window.matchMedia("(prefers-color-scheme: dark)").matches ? (o.defaultTheme = "dark") : window.matchMedia("(prefers-color-scheme: light)").matches && (o.defaultTheme = "light");
#### FIX START
    if (document.getElementById("docsify-darklight-theme") == null) return;
#### FIX END
    var i = (e) => {
        if (
            (document.getElementById("docsify-darklight-theme").setAttribute("data-link-title", e), document.getElementById("docsify-darklight-theme").click(), localStorage.setItem("DARK_LIGHT_THEME", e), (o.defaultTheme = e), "light" == e)
        )
            for (var [t, r] of Object.entries(o.light)) document.documentElement.style.setProperty("--" + t, r);
        else if ("dark" == e) for (var [t, r] of Object.entries(o.dark)) document.documentElement.style.setProperty("--" + t, r);
    };
    e.afterEach(function (e, t) {
        t((e = '<div id="docsify-darklight-theme"><p>.</p></div>' + e));
    }),
    e.doneEach(function () {
        let e = localStorage.getItem("DARK_LIGHT_THEME");
        "light" == e || "dark" == e ? ((o.defaultTheme = e), i(o.defaultTheme)) : i(o.defaultTheme),
            document.getElementById("docsify-darklight-theme").addEventListener("click", function () {
                "light" === o.defaultTheme ? i("dark") : i("light");
            });
    });
}, window.$docsify.plugins);

BlackRose01 avatar Jun 02 '22 12:06 BlackRose01

Maybe a quick-and-dirty fix for this problem

window.$docsify.plugins = [].concat((e, t) => {
    let o = {
        siteFont: "PT Sans",
        defaultTheme: "dark",
        codeFontFamily: "Roboto Mono, Monaco, courier, monospace",
        bodyFontSize: "17px",
        dark: { accent: "#42b983", toogleBackground: "#ffffff", background: "#091a28", toogleImage: "url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/sun.svg)" },
        light: { accent: "#42b983", toogleBackground: "#091a28", background: "#ffffff", toogleImage: "url(https://cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/icons/moon.svg)" },
    };
    if (t.config.hasOwnProperty("darklightTheme")) {
        for (var [r, d] of Object.entries(t.config.darklightTheme)) "light" !== r && "dark" !== r && "defaultTheme" !== r && (o[r] = d);
        for (var [r, d] of Object.entries(o)) "light" !== r && "dark" !== r && ((o[r] = d), document.documentElement.style.setProperty("--" + r, d));
        if (t.config.darklightTheme.hasOwnProperty("dark")) for (var [r, d] of Object.entries(t.config.darklightTheme.dark)) o.dark[r] = d;
        if (t.config.darklightTheme.hasOwnProperty("light")) for (var [r, d] of Object.entries(t.config.darklightTheme.light)) o.light[r] = d;
    } else for (var [r, d] of Object.entries(o)) "light" !== r && "dark" !== r && ((o[r] = d), document.documentElement.style.setProperty("--" + r, d));
    window.matchMedia("(prefers-color-scheme: dark)").matches ? (o.defaultTheme = "dark") : window.matchMedia("(prefers-color-scheme: light)").matches && (o.defaultTheme = "light");
    var i = (e) => {
        if (
            document.getElementById("docsify-darklight-theme").setAttribute("data-link-title", e), document.getElementById("docsify-darklight-theme").click(), localStorage.setItem("DARK_LIGHT_THEME", e), (o.defaultTheme = e), "light" == e
        )
            for (var [t, r] of Object.entries(o.light)) document.documentElement.style.setProperty("--" + t, r);
        else if ("dark" == e) for (var [t, r] of Object.entries(o.dark)) document.documentElement.style.setProperty("--" + t, r);
    };
    e.afterEach((e, t) => t((e = '<div id="docsify-darklight-theme"><p>.</p></div>' + e)));
    e.doneEach((e = localStorage.getItem("DARK_LIGHT_THEME")) => {
#### FIX START
        if (document.getElementById("docsify-darklight-theme") === null) return;
#### FIX END
        "light" == e || "dark" == e ? ((o.defaultTheme = e), i(o.defaultTheme)) : i(o.defaultTheme),
            document.getElementById("docsify-darklight-theme").addEventListener("click", () => "light" === o.defaultTheme ? i("dark") : i("light"));
    });
}, window.$docsify.plugins);

BlackRose01 avatar Jun 02 '22 14:06 BlackRose01