MikuTools vip

mikutools always vip

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         MikuTools vip
// @namespace    MikuTools-vip
// @version      0.1
// @description  mikutools always vip
// @author       pq
// @match        https://tools.miku.ac/*
// @grant        none
// @run-at      document-end
// ==/UserScript==

'use strict';

// 引用自[https://kantv-helper.mutoo.im/dist/kantv-helper.user.js]
/**
 * get a vue instance from selector
 * @param selector
 * @return {any | null}
 */
function getVueInstance(selector) {
    return detectElement(selector).then(dom => dom.__vue__);
}

/**
 * resolve once a element is on the page
 * @param selector
 * @param interval
 * @param retry
 * @return {Promise<any>}
 */
function detectElement(selector, interval = 500, retry = 10) {
    return new Promise((resolve, reject) => {
        setTimeout(function detect() {
            let dom = document.querySelector(selector);
            if (dom) {
                resolve(dom);
            } else if (retry > 0) {
                setTimeout(detect, interval);
                retry -= 1;
            } else {
                reject(`can not found ${selector} on the page`);
            }
        }, interval);
    });
}

function mikuTools() {
    return getVueInstance('#__nuxt')
        .then(vue => {
        const $state = vue.$store.app.store.state
        $state.vip = true
    })
        .catch(err => {
        console.warn('qr vue is not detected.');
    });
}

(()=>{
    mikuTools()
})();