<template>
    <div>
        <el-button :loading="loading" type="primary" @click="doProgramVirus(false)">造简单病毒</el-button>
        <el-button :loading="loading" type="danger" @click="doProgramVirus(true)">取消病毒编程</el-button>
    </div>
    <div v-loading="loading" v-html="html"></div>
</template>

<script lang="ts">
export default {
    name: "VirusProgramming"
}
</script>

<script lang="ts" setup>
import { inject, ref } from "vue";
import { LoggerKey } from "../ts/class/Logger";

const logger = inject(LoggerKey);
const html = ref('');
const loading = ref(false);
const doProgramVirus = async (isCancel: boolean) => {
    loading.value = true;
    html.value = '';
    try {
        html.value = await (await fetch(window.addRFC("https://www.torn.com/pc.php"), {
            "headers": {
                "accept": "*/*",
                "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
                "sec-ch-ua-mobile": "?0",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-origin",
                "x-requested-with": "XMLHttpRequest"
            },
            "referrer": "https://www.torn.com/pc.php",
            "referrerPolicy": "strict-origin-when-cross-origin",
            "body": isCancel ? "step=cancelProgramming" : "step=startProgramming&type=simple",
            "method": "POST",
            "mode": "cors",
            "credentials": "include"
        })).text();
    } catch (e) {
        logger.error(e.stack);
    }
    loading.value = false;
};
</script>

<style scoped>

</style>