package com.mime.dualscreenview.webcontents.contentsinfo

import com.mime.dualscreenview.webcontents.BaseWebContents

object Booktoki : BaseWebContents() {

    override var lastNumber : Int = 283

    override fun getWebcontentsName(): String {
        return "Booktoki"
    }

    override fun getLastedDoamin(): String {
        return String.format("https://booktoki%d.com/", lastNumber)
    }

    override fun getContentsList(): String {
        return  "" +
                "function getList()  {\n" +
                "\t\t\t var children = document.getElementsByName('wr_id')[0].children;\n" +
                "                var maxCount =  children.length\n" +
                "                const contentsArray = []\n" +
                "                for (i= 0; i < maxCount; i++) {\n" +
                "                contentsArray.push({'title' : children[i].text ,\n" +
                "                'link' : children[i].value})\n" +
                "                }\n" +
                "                contentsArray.reverse() \n" +
                "return  {'list' :contentsArray}\n" +
                "}\n" +
                "getList()\n"
    }

    override fun acccceptResourceKeyword(): String {
        return "toki"
    }

    override fun getNextButtonJs(): String {
        return "goNextBtn"
    }

    override fun getPrevButtonJs(): String {
        return "goPrevBtn"
    }

    override fun getTitleJs(): String {
        return "document.getElementsByClassName(\"toon-title\").length > 0 ? document.getElementsByClassName(\"toon-title\")[0].title : null"
    }

    override fun getFindContentsJs(): String {
        return "document.getElementById(\"novel_content\") != null ? document.getElementById(\"novel_content\").innerText : null"
    }

    override fun checkCorrectContents(contents: String): String {
        return if (contents != null && !contents.isNullOrEmpty()) {
            contents
        } else {
            "fail load"
        }
    }

    override fun onLoadedJs(): String {
        return "if(document.getElementsByClassName(\"hd_pops\") != null && document.getElementsByClassName(\"hd_pops\").length > 0) document.getElementsByClassName(\"hd_pops\")[0].remove();" +
                "if(document.getElementsByClassName(\"hd_pops\") != null && document.getElementsByClassName(\"hd_pops\").length > 0) document.getElementsByClassName(\"hd_pops\")[0].remove();" +
                "if(document.getElementById(\"main-banner-view\") != null) document.getElementById(\"main-banner-view\").remove();" +
                "if(document.getElementsByClassName(\"board-tail-banner\") != null && document.getElementsByClassName(\"board-tail-banner\").length > 0)document.getElementsByClassName(\"board-tail-banner\")[0].remove();" +
                "if(document.getElementById(\"id_mbv\") != null)document.getElementById(\"id_mbv\").remove();"
    }
}