NitterCorpusNet

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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);