<commit_before>package net.perfectdreams.loritta.sweetmorenitta.views

import com.mrpowergamerbr.loritta.utils.locale.BaseLocale
import kotlinx.html.*
import kotlinx.html.stream.appendHTML
import net.perfectdreams.loritta.website.LorittaWebsite
import net.perfectdreams.loritta.website.utils.WebsiteAssetsHashes

abstract class BaseView(
        val locale: BaseLocale,
        val path: String
) {
    companion object {
        val versionPrefix = "/v2"
        val websiteUrl = LorittaWebsite.INSTANCE.config.websiteUrl
    }

    fun generateHtml(): String {
        val supportUrl = "https://loritta.website/support"
        val firefoxUrl = "https://www.mozilla.org/firefox"
        val chromeUrl = "https://www.google.com/chrome"
        val edgeUrl = "https://www.microsoft.com/edge"

        return StringBuilder().appendHTML().html {
            head {
                // Usado para login: A SpicyMorenitta usa esse código ao autenticar via "auth_popup.kts"
                // Já que é meio difícil chamar códigos de Kotlin/JS na parent window, existe esse método auxiliar para facilitar.
                // authenticate(p) sendo p = "user identification do Discord"
                // Também tem umas coisinhas do Google reCAPTCHA
                script(type = ScriptType.textJavaScript) {
                    unsafe {
                        raw("""
function authenticate(p) { output.net.perfectdreams.spicymorenitta.utils.AuthUtils.handlePostAuth(p); };

document.domain = "loritta.website";

function onGoogleRecaptchaLoadCallback() { this['spicy-morenitta'].net.perfectdreams.spicymorenitta.utils.GoogleRecaptchaUtils.onRecaptchaLoadCallback(); };

window.addEventListener('load', function () {
    // Verificar se o usuário está usando o antigo Edge ou MSIE, já que nós não suportamos nenhum desses dois
    // ; MSIE == MS Internet Explorer
    // Trident/7.0 == MSIE11
    if (/(?:\b(MS)?IE\s+|\bTrident\/7\.0;.*\s+rv:|\bEdge\/)(\d+)/.test(navigator.userAgent)) {
        alert("${locale.getList("website.unsupportedBrowser").joinToString("\\n\\n", transform = { java.text.MessageFormat.format(it, supportUrl, firefoxUrl, chromeUrl, edgeUrl); })}")
    }
    // Verificar se o SpicyMorenitta foi carregado corretamente
    if (window.spicyMorenittaLoaded === undefined) {
        alert("${locale.getList("website.failedToLoadScripts").joinToString("\\n\\n", transform = { java.text.MessageFormat.format(it, supportUrl, firefoxUrl, chromeUrl, edgeUrl); })}")
    }
});
""")
                    }
                }

                title(getFullTitle())

                unsafe {
                    raw("""
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest" />
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
<meta name="msapplication-TileColor" content="#5bbad5" />
""")
                }
                meta(name = "viewport", content = "width=device-width, initial-scale=1")


                if (false && com.mrpowergamerbr.loritta.LorittaLauncher.loritta.config.loritta.environment == com.mrpowergamerbr.loritta.utils.config.EnvironmentType.CANARY)
                    styleLink("${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/css/style.css?v12345")
                else
                    styleLink("${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/css/style.css?hash=${assetHash("assets/css/style.css")}")

                styleLink("https://use.fontawesome.com/releases/v5.8.1/css/all.css")

                // Google Analytics
                script(src = "https://www.googletagmanager.com/gtag/js?id=UA-53518408-9") {}

                script(type = ScriptType.textJavaScript) {
                    unsafe {
                        raw("""window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-53518408-9');""")
                    }
                }

                // Detect AdBlock
                script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/adsbygoogle.js") {}

                if (false && com.mrpowergamerbr.loritta.LorittaLauncher.loritta.config.loritta.environment == com.mrpowergamerbr.loritta.utils.config.EnvironmentType.CANARY) {
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/jquery-3.2.1.min.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/countUp.min.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/showdown.min.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/tingle.min.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/autosize.min.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/toastr.min.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/select2.min.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/moment-with-locales.min.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/kotlin.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/kotlinx-coroutines-core.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/kotlinx-serialization-runtime-js.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/kotlinx-html-js.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/kotlinx-io.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/ktor-ktor-io.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/kotlinx-coroutines-io.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/ktor-ktor-utils.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/ktor-ktor-http.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/ktor-ktor-http-cio.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/ktor-ktor-client-core.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/ktor-ktor-client-js.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/kotlin-logging.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/loritta-parent-loritta-api.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/spicy-morenitta.js?hash=${assetHash("assets/js/spicy-morenitta.js")}") {}
                } else {
                    // App itself
                    script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/app.js?hash=${assetHash("assets/js/app.js")}") {}
                }

                // Google AdSense
                script(src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js") {}

                // Google ReCAPTCHA
                script(src = "https://www.google.com/recaptcha/api.js?render=explicit&onload=onGoogleRecaptchaLoadCallback") {}

                // NitroPay
                unsafe {
                    raw("""
<script type="text/javascript">
  window["nitroAds"] = window["nitroAds"] || {
    createAd: function() {<commit_msg>Remove old dummied out code from the BaseView<commit_after>package net.perfectdreams.loritta.sweetmorenitta.views

import com.mrpowergamerbr.loritta.utils.locale.BaseLocale
import kotlinx.html.*
import kotlinx.html.stream.appendHTML
import net.perfectdreams.loritta.website.LorittaWebsite
import net.perfectdreams.loritta.website.utils.WebsiteAssetsHashes

abstract class BaseView(
        val locale: BaseLocale,
        val path: String
) {
    companion object {
        val versionPrefix = "/v2"
        val websiteUrl = LorittaWebsite.INSTANCE.config.websiteUrl
    }

    fun generateHtml(): String {
        val supportUrl = "https://loritta.website/support"
        val firefoxUrl = "https://www.mozilla.org/firefox"
        val chromeUrl = "https://www.google.com/chrome"
        val edgeUrl = "https://www.microsoft.com/edge"

        return StringBuilder().appendHTML().html {
            head {
                // Usado para login: A SpicyMorenitta usa esse código ao autenticar via "auth_popup.kts"
                // Já que é meio difícil chamar códigos de Kotlin/JS na parent window, existe esse método auxiliar para facilitar.
                // authenticate(p) sendo p = "user identification do Discord"
                // Também tem umas coisinhas do Google reCAPTCHA
                script(type = ScriptType.textJavaScript) {
                    unsafe {
                        raw("""
function authenticate(p) { output.net.perfectdreams.spicymorenitta.utils.AuthUtils.handlePostAuth(p); };

document.domain = "loritta.website";

function onGoogleRecaptchaLoadCallback() { this['spicy-morenitta'].net.perfectdreams.spicymorenitta.utils.GoogleRecaptchaUtils.onRecaptchaLoadCallback(); };

window.addEventListener('load', function () {
    // Verificar se o usuário está usando o antigo Edge ou MSIE, já que nós não suportamos nenhum desses dois
    // ; MSIE == MS Internet Explorer
    // Trident/7.0 == MSIE11
    if (/(?:\b(MS)?IE\s+|\bTrident\/7\.0;.*\s+rv:|\bEdge\/)(\d+)/.test(navigator.userAgent)) {
        alert("${locale.getList("website.unsupportedBrowser").joinToString("\\n\\n", transform = { java.text.MessageFormat.format(it, supportUrl, firefoxUrl, chromeUrl, edgeUrl); })}")
    }
    // Verificar se o SpicyMorenitta foi carregado corretamente
    if (window.spicyMorenittaLoaded === undefined) {
        alert("${locale.getList("website.failedToLoadScripts").joinToString("\\n\\n", transform = { java.text.MessageFormat.format(it, supportUrl, firefoxUrl, chromeUrl, edgeUrl); })}")
    }
});
""")
                    }
                }

                title(getFullTitle())

                unsafe {
                    raw("""
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest" />
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
<meta name="msapplication-TileColor" content="#5bbad5" />
""")
                }
                meta(name = "viewport", content = "width=device-width, initial-scale=1")


                if (false && com.mrpowergamerbr.loritta.LorittaLauncher.loritta.config.loritta.environment == com.mrpowergamerbr.loritta.utils.config.EnvironmentType.CANARY)
                    styleLink("${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/css/style.css?v12345")
                else
                    styleLink("${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/css/style.css?hash=${assetHash("assets/css/style.css")}")

                styleLink("https://use.fontawesome.com/releases/v5.8.1/css/all.css")

                // Google Analytics
                script(src = "https://www.googletagmanager.com/gtag/js?id=UA-53518408-9") {}

                script(type = ScriptType.textJavaScript) {
                    unsafe {
                        raw("""window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-53518408-9');""")
                    }
                }

                // Detect AdBlock
                script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/adsbygoogle.js") {}

                // App itself
                script(src = "${LorittaWebsite.INSTANCE.config.websiteUrl}$versionPrefix/assets/js/app.js?hash=${assetHash("assets/js/app.js")}") {}

                // Google AdSense
                script(src = "https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js") {}

                // Google ReCAPTCHA
                script(src = "https://www.google.com/recaptcha/api.js?render=explicit&onload=onGoogleRecaptchaLoadCallback") {}

                // NitroPay
                unsafe {
                    raw("""
<script type="text/javascript">
  window["nitroAds"] = window["nitroAds"] || {
    createAd: function() {
{'fraction_non_alphanumeric': 0.1529246935201401, 'fraction_numerical': 0.00882661996497373, 'mean_word_length': 2.843834141087776, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 16, 'lorem ipsum': 0, 'www.': 10, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5665532', 'n_tokens_mistral': 4611, 'n_tokens_neox': 4331, 'n_words': 532}