Civitai 增强

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

当前为 2023-10-18 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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
});