NitterCorpusEnv

拾荒小猫控制矩阵 - 基础环境、卡槽状态与本地沙箱固化中枢

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.greasyfork.org/scripts/579924/1835587/NitterCorpusEnv.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         NitterCorpusEnv
// @version      1.2.6_Env
// @description  拾荒小猫控制矩阵 - 基础环境、卡槽状态与本地沙箱固化中枢
// @author       Gemini Collaborator
// @grant        none
// ==/UserScript==

(function(window) {
    'use strict';

    window.NitterEnv = {
        DB_KEY: '',
        HISTORY_KEY: 'rp_asset_history_pool',
        localStore: null,
        assetHistory: [],
        snapshottedBackup: null,
        defaultSlots: [
            { id: 'slot_1', name: '🎭 赛博拾荒者', content: '你是一个专业的推文分析师...' },
            { id: 'slot_2', name: '🎭 语料解构师', content: '提取并精炼以下推文的技术内核...' },
            { id: 'slot_3', name: '🎭 仿生复刻机', content: '克隆以下目标用户的发帖逻辑与语气...' }
        ],

        setup(host, username, metaText, tweets) {
            this.DB_KEY = `rp_corpus_${host}_${username}`;
            let rawStore = localStorage.getItem(this.DB_KEY);
            
            if (!rawStore) {
                this.localStore = {
                    currentPage: 1, lastUrl: "", tweets: [], metaText: metaText, activeSlotId: 'slot_1',
                    slots: JSON.parse(JSON.stringify(this.defaultSlots)),
                    config: { img: true, video: true, stamp: true, hot: true, level: 2, customPrompt: '你是一个专业的推文分析师...' }
                };
            } else {
                this.localStore = JSON.parse(rawStore);
                if (!this.localStore.slots || this.localStore.slots.length === 0) this.localStore.slots = JSON.parse(JSON.stringify(this.defaultSlots));
                if (!this.localStore.config) this.localStore.config = { img: true, video: true, stamp: true, hot: true, level: 2, customPrompt: this.localStore.slots[0].content };
            }

            tweets.forEach(t => {
                let existIndex = this.localStore.tweets.findIndex(old => old.includes(`[BASETEXT]${t.baseText}[/BASETEXT]`) || old.includes(t.baseText));
                if (existIndex !== -1) {
                    let oldBlock = this.localStore.tweets[existIndex];
                    if ((oldBlock.includes('💬评论: 0 | 🔄转推: 0') || !oldBlock.includes('[HOTMETRIC]')) && (t.replyCount !== "0" || t.retweetCount !== "0")) {
                        this.localStore.tweets[existIndex] = t.rawContentBlock;
                    }
                } else { this.localStore.tweets.push(t.rawContentBlock); }
            });
            
            this.localStore.metaText = metaText || this.localStore.metaText;
            this.save();

            try { this.assetHistory = JSON.parse(localStorage.getItem(this.HISTORY_KEY)) || []; } catch(e) { this.assetHistory = []; }
        },

        save() {
            localStorage.setItem(this.DB_KEY, JSON.stringify(this.localStore));
        },

        showToast(title, desc, isErr = false) {
            const container = document.getElementById('rp-toast-container');
            if (!container) return;
            const toast = document.createElement('div');
            toast.className = 'rp-toast';
            if (isErr) toast.style.borderLeftColor = '#f38ba8';
            toast.innerHTML = `<div style="font-weight:bold;margin-bottom:2px;">${title}</div><div style="color:#a6adc8;font-size:10px;">${desc}</div>`;
            container.appendChild(toast);
            setTimeout(() => toast.classList.add('show'), 50);
            setTimeout(() => { toast.classList.remove('show'); setTimeout(() => toast.remove(), 300); }, 3500);
        }
    };
})(window);