Civitai 增强

获得更佳的 Civitai 体验,功能解锁

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name Civitai 增强
// @author Hyun
// @license MIT
// @description 获得更佳的 Civitai 体验,功能解锁
// @version 0.0.1
// @icon https://civitai.com/favicon.ico
// @match https://civitai.com/*
// @grant unsafeWindow
// @run-at document-start
// @namespace https://greasyfork.org/users/718868
// ==/UserScript==

function patchUser(user) {
    user.isModerator = true;
    user.permissions = ["dev", "mod", "public", "user", "founder", "granted"];
}

const observer = new MutationObserver((mutationList, observer)=>{
    const target = document.getElementById('__NEXT_DATA__');
    if(!target) return;

    const json = JSON.parse(target.innerText);
    for(const k of Object.keys(json.props.pageProps.flags)) {
        json.props.pageProps.flags[k] = true;
    }
    patchUser(json.props.pageProps.session.user);
    target.innerText = JSON.stringify(json);
    console.log('[*] Patched!', target);
    observer.disconnect();
});

observer.observe(document.documentElement, { childList: true, subtree: true });

async function myFetch(uri, ...rest) {
    const res = await fetch(uri, ...rest);
    if(uri == '/api/auth/session') {
        const json = await res.json();
        console.log('[*] session', json);
        patchUser(json.user);

        Object.defineProperty(res, 'json', {
            get: ()=> () => Promise.resolve(json)
        });
    }

    return res;
}

Object.defineProperty(unsafeWindow, 'fetch', {
    get: ()=> myFetch,
    set() {},
    configurable: false
});