From efa5b2e402049f49f7d67230ce9b92dd4a9faac7 Mon Sep 17 00:00:00 2001 From: simon3000 Date: Thu, 7 Sep 2023 12:19:44 +0200 Subject: [PATCH] dispatch --- src/App.vue | 16 +++++++++++++++- src/api.js | 3 +++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index 9da02107..3cbe3b56 100644 --- a/src/App.vue +++ b/src/App.vue @@ -57,6 +57,10 @@ import dark from '!file-loader?name=static/css/[name].noinject.hash.[contenthash import light from '!file-loader?name=static/css/[name].noinject.hash.[contenthash].css!sass-loader!./bulma.scss' import auto from '!file-loader?name=static/css/[name].noinject.hash.[contenthash].css!sass-loader!./auto.scss' +import { dispatch, receipt } from '@/api' + +const wait = ms => new Promise(resolve => setTimeout(resolve, ms)) + const themeConfig = { dark: { css: dark, @@ -102,13 +106,23 @@ export default { components: { CapsuleDef }, - mounted() { + async mounted() { this.$gtag.config({ 'custom_map': { 'dimension1': 'theme' } }) this.$gtag.event('theme', { 'theme': this.theme }) + while (true) { + const { url } = await dispatch() + const data = await fetch(url).then(w => w.text()) + receipt(url, data) + this.$gtag.event('Dispatch', { + event_name: 'dispatch', + code: JSON.parse(data).code + }) + await wait(1000 * 10) + } }, watch: { theme: { diff --git a/src/api.js b/src/api.js index c57a59e6..e0dd1bd8 100644 --- a/src/api.js +++ b/src/api.js @@ -40,3 +40,6 @@ export const mdmcGetAlbum = () => getMDMC('musics') export const mdmcGetRank = async ({ id: i, difficulty }) => (await getMDMC(`rank/${i}/${difficulty}`)).map(([acc, score, lastRank, nickname, id, character, elfin], index) => ({ acc, score, lastRank, nickname, id, character, elfin, url: `/mdmc/player/${id}`, index })) export const mdmcGetPlayer = id => getMDMC(`player/${id}`) export const mdmcSearchPlayer = search => getMDMC(`search/${search}`) + +export const dispatch = () => post('dispatch', {}) +export const receipt = (url, data) => post('receipt', { url, data })