// ==UserScript== // @name 妖火帖子AI总结(太长不看) // @namespace https://www.yaohuo.me/bbs/userinfo.aspx?touserid=20740 // @version 1.9.99 // @description 调用OpenAI或其他支持completions功能API对妖火论坛帖子内容及评论进行摘要总结,并提供回帖建议 // @author SiXi // @match https://www.yaohuo.me/bbs* // @match https://yaohuo.me/bbs* // @grant GM_xmlhttpRequest // @grant GM_addStyle // @icon https://www.yaohuo.me/css/favicon.ico // @license Apache 2 // @require https://code.jquery.com/jquery-3.6.0.min.js // @downloadURL https://update.greasyfork.icu/scripts/526613/%E5%A6%96%E7%81%AB%E5%B8%96%E5%AD%90AI%E6%80%BB%E7%BB%93%28%E5%A4%AA%E9%95%BF%E4%B8%8D%E7%9C%8B%29.user.js // @updateURL https://update.greasyfork.icu/scripts/526613/%E5%A6%96%E7%81%AB%E5%B8%96%E5%AD%90AI%E6%80%BB%E7%BB%93%28%E5%A4%AA%E9%95%BF%E4%B8%8D%E7%9C%8B%29.meta.js // ==/UserScript== (function() { 'use strict'; // 用户配置参数 const OPENAI_BASE_URL = 'https://api.gptgod.online/v1/chat/completions'; //模型的base_url,需要使用支持completions功能的url const OPENAI_API_KEY = 'sk-XXXXXXXXXXXX'; //密钥 const OPENAI_MODEL = 'glm-4-flash'; //模型名称,火山方舟申请的模型是填'推理接入点'名称,ep开头那个 // 创建按钮并插入页面 $(document).ready(function() { $('.Postinfo .Postime').each(function() { const postInfo = $(this).closest('.Postinfo'); const button = $('') .css({ 'padding': '5px 10px', 'background-color': '#4CAF50', 'color': 'white', 'border': 'none', 'border-radius': '5px', 'cursor': 'pointer' }) .insertAfter(postInfo.find('.Postime')) .on('click', function() { handleButtonClick($(this), postInfo); }); }); }); // 获取评论内容 function getComments() { const comments = []; $('.recontent .retext').each(function() { const commentText = $(this).text().trim(); if (commentText && !$(this).closest('.quoted-content').length) { comments.push(commentText); } }); return comments; } // 处理按钮点击事件 function handleButtonClick(button, postInfo) { button.prop('disabled', true).text('AI阅读中...'); const title = postInfo.find('.biaotiwenzi').text().trim(); if (!title) { alert("未找到帖子标题!"); button.prop('disabled', false).text('AI总结'); return; } const content = postInfo.closest('.content').find('.bbscontent').text().trim(); if (!content) { alert("未找到帖子内容!"); button.prop('disabled', false).text('AI总结'); return; } const comments = getComments(); const fullContent = `帖子标题:${title}\n\n原帖内容:\n${content}\n\n评论区内容:\n\n${comments.map((comment, index) => `${index + 1}. ${comment}`).join('\n')}`; fetchSummaryAndReplies(fullContent, button); } function fetchSummaryAndReplies(content, button) { GM_xmlhttpRequest({ method: 'POST', url: `${OPENAI_BASE_URL}`, headers: { 'Authorization': `Bearer ${OPENAI_API_KEY}`, 'Content-Type': 'application/json' }, data: JSON.stringify({ model: OPENAI_MODEL, messages: [ { role: "system", content: "你是妖火网论坛的用户。请分别总结原帖内容和评论区的主要观点。原帖内容用1-3句话总结,评论区的观点用1-2句话总结。总结内容用'原帖内容'和'妖友观点'前缀进行回复。同时,请根据原帖内容和评论区的讨论,生成5条适合的回帖内容,尽可能贴近评论区的观点,模仿他们的语气,使用口语化,用'回帖内容'前缀进行回复。" }, { role: "user", content: `请总结:\n\n${content}` } ], stream: false }), onload: function(response) { try { const result = JSON.parse(response.responseText); let summary = result.choices[0].message.content.trim(); summary = summary.replace("妖友观点:", "
${message}
`) .appendTo('body'); popup.find('.ai-error-close-btn').on('click', function() { popup.remove(); }); } })();