hate novel

likenovel 개선 유저스크립트

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name hate novel
// @version 1.0.0
// @author ㅇㅇ
// @description likenovel 개선 유저스크립트
// @match http*://likenovel.net/*
// @namespace hate-novel
// @rut-at document-start
// @grant GM_getValue
// @grant GM_setValue
// @noframes
// @license GPLv3
// @homepageURL https://greasyfork.org/ko/scripts/439336-hate-novel
// ==/UserScript==

window.addEventListener("DOMContentLoaded", () => {
    "use strict";

    const itemLength = () => {
        document.querySelector(".lengthChecker").innerHTML += `문단 수 <span class="item-length">0</span>`;

        /** @param ev {InputEvent} */
        const inputEvent = (ev) => {
            setLength(ev.target.textContent.length);
        };

        /** @param length {Number} */
        const setLength = (length) => {
            document.querySelector(".item-length").textContent = String(length).replace(/\n/g, "");
        };

        /** @type {Element} */
        let oldItem = null;

        const observer = new MutationObserver(() => {
            const item = document.querySelector("div[class*=focused]");

            if (item === null) {
                setLength(0);
                oldItem?.removeEventListener("input", inputEvent);
                return;
            }

            const p = item.querySelector("p[contenteditable]");

            p.addEventListener("input", inputEvent);
            setLength(p.textContent.length);

            if (p === oldItem) return;

            oldItem = p;
        });

        observer.observe(document.querySelector("#novelEditor div[class=editable]"), {
            attributes: true,
            subtree: true
        });
    };

    const backup = () => {
        const button = document.createElement("button");
        button.innerText = "복원";
        button.onclick = (ev) => {
            ev.preventDefault();

            const contents = GM_getValue("backup", "");

            if (contents === "") alert("백업이 없습니다.");

            document.querySelector("div#novelEditor > div[class=editable]").innerHTML = contents;
        };

        document.querySelector(".paywallCoinAmountContainer").parentElement.appendChild(button);

        setInterval(() => {
            GM_setValue("backup", document.querySelector("div#novelEditor > div[class=editable]").innerHTML);
        }, 180000);
    };

    /** 소설 작성 */
    const writeNovel = /^\/novels\/\d*\/write$/;

    /** 소설 수성 */
    const editNovel = /^\/novels\/\d*\/\d*\/edit$/;

    if (!writeNovel.test(location.pathname) && !editNovel.test(location.pathname)) return;

    try {
        itemLength();
    } catch {

    }

    try {
        backup();
    } catch {

    }
});