NitterCorpusNet

拾荒小猫控制矩阵 - GM特权网络、TextDB分布式网络流与重度格式拼装机

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greatest.deepsurf.us/scripts/579925/1835588/NitterCorpusNet.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         NitterCorpusNet
// @version      1.2.6_Net
// @description  拾荒小猫控制矩阵 - GM特权网络、TextDB分布式网络流与重度格式拼装机
// @author       Gemini Collaborator
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function(window) {
    'use strict';

    window.NitterNet = {
        async cloudUpdate(url, key, value, action, callback) {
            let dataPayload = `key=${encodeURIComponent(key)}&value=`;
            if (action !== 'delete') dataPayload += encodeURIComponent(value);
            GM_xmlhttpRequest({
                method: 'POST',
                url: action === 'delete' ? `${url}?key=${key}&value=` : url,
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                data: action === 'delete' ? '' : dataPayload,
                onload: (res) => {
                    try { callback(null, JSON.parse(res.responseText)); } catch(e) { callback(new Error("回执结构断裂: " + e.message)); }
                },
                onerror: () => callback(new Error("特权泵入流遭遇阻断。"))
            });
        },

        async remoteFetch(url, callback) {
            GM_xmlhttpRequest({
                method: 'GET', url: url,
                onload: (res) => callback(null, res.responseText),
                onerror: () => callback(new Error("远端同步流路径死锁"))
            });
        },

        buildPromptText(envStore, username, host) {
            const cfg = envStore.config;
            const processed = envStore.tweets.map(rawBlock => {
                let prefix = rawBlock.match(/\[METAPREFIX\]([\s\S]*?)\[\/METAPREFIX\]/)?.[1] || '';
                let hot = rawBlock.match(/\[HOTMETRIC\]([\s\S]*?)\[\/HOTMETRIC\]/)?.[1] || '';
                let base = rawBlock.match(/\[BASETEXT\]([\s\S]*?)\[\/BASETEXT\]/)?.[1] || '';
                let mediaLines = [];
                rawBlock.split('\n').forEach(line => {
                    if (line.startsWith('__IMG__') && cfg.img) mediaLines.push(line.replace('__IMG__', ''));
                    if (line.startsWith('__VID__') && cfg.video) mediaLines.push(line.replace('__VID__', ''));
                });
                let finalPrefix = cfg.stamp ? prefix : (prefix.includes('[🔄 转推自:') ? (prefix.match(/\[🔄 转推自:.*?\]/)?.[0] || '') : '');
                let blockParts = [];
                if (finalPrefix.trim()) blockParts.push(finalPrefix.trim());
                if (cfg.hot && hot.trim()) blockParts.push(hot.trim());
                if (base.trim()) blockParts.push(base.trim());
                if (mediaLines.length > 0) blockParts.push(mediaLines.join('\n'));
                return blockParts.join('\n').trim();
            }).filter(t => t && t.trim().length > 0);

            return `${cfg.customPrompt}\n\n以下是目标用户的真实账号元数据与推文语料库(共 ${processed.length} 条):\n--------------------------------------------------\n【原始主页元数据纯文本】\n${envStore.metaText || '未抓取到描述'}\n\n【清洗过滤后的大批量推文语料库】\n${processed.join('\n---\n')}\n--------------------------------------------------`;
        },

        generateGfCode(envStore) {
            let lines = [ "// ==UserScript==", "// @name         拾荒小猫_云端扩展组件", `// @version      ${Date.now()}`, "// ==/UserScript==", "", "window.CloudPrompts = {" ];
            envStore.slots.forEach((s, idx) => {
                const key = s.name.replace(/[^\w\u4e00-\u9fa5]/g, '') || `slot_${idx}`;
                const formatter = s.content.split('\n').map(line => `        ${JSON.stringify(line)}`).join(',\n');
                lines.push(`    ${JSON.stringify(key)}: [\n${formatter}\n    ].join('\\n')${idx === envStore.slots.length - 1 ? '' : ','}`);
            });
            lines.push("};"); return lines.join('\n');
        }
    };
})(window);