<template>
  <el-button @click="doCrime(11,'warehouse')">烧仓库</el-button>
  <el-button @click="doCrime(15,'napcop')">做15-3</el-button>
  <el-button @click="doCrime(18,'hackbank')">做18-1</el-button>
  <div v-if="results" v-html="results"></div>
  <el-skeleton v-if="loading" :rows="3" animated/>
</template>

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

const logger = inject(LoggerKey);
const results = ref("");
const loading = ref(false);
const doCrime = async (nerve, crime: "hackbank" | "warehouse" | 'napcop') => {
  loading.value = true;
  results.value = '';
  try {
    results.value = await (await fetch(window.addRFC("https://www.torn.com/crimes.php?step=docrime4&timestamp=" + Date.now()), {
      "headers": {
        "accept": "text/plain, */*; q=0.01",
        "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/crimes.php",
      "referrerPolicy": "strict-origin-when-cross-origin",
      "body": `nervetake=${ nerve }&crime=${ crime }`,
      "method": "POST",
      "mode": "cors",
      "credentials": "include"
    })).text();
  } catch (e) {
    logger.error(e.stack);
    results.value = e.message;
  }
  let err;
  try {
    err = JSON.parse(results.value).error;
  } catch (e) {
  }
  if (err) {
    results.value = '出错了';
    ElMessage.error('错误: ' + err);
    logger.error(err);
  }
  loading.value = false;
};
</script>

<style scoped>

</style>