一元网络论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 103|回复: 0

L站帖子及回复总结 (基于 Gemini 1.5 pro API 油猴脚本)

[复制链接]

3万

主题

3万

帖子

9万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
96158
发表于 2024-9-29 21:52:04 | 显示全部楼层 |阅读模式

首先要感谢 @neo 提供的L站数据,没有这些数据,这个功能就无法实现。大家在使用过程中,请注意不要对L站造成访问压力。

最近很多用户想要使用这个工具,考虑到API已经可以直接获取,所以现在把代码放出来供大家使用。
代码中拉取数据的方法进行了加密,以防止被恶意利用对社区造成压力。
话不多说,直接上源码,自行体验。

源码
// ==UserScript==
// @name         Linux.do 回复内容总结
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  总结Linux.do论坛帖子中指定楼层之间的回复内容
// @author       NullUser
// @match        https://linux.do/*
// @icon         https://linux.do/uploads/default/optimized/1X/3a18b4b0da3e8cf96f7eea15241c3d251f28a39b_2_180x180.png
// @grant        none
// @license      MIT
// ==/UserScript==
(function () {
    'use strict';
    async function summarizeSomething(txt) {
        // 定义请求的URL
        const apiKey = ''; // 请替换为您的API密钥
        const url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent';

        // 定义请求的headers和body
        const headers = {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
        };
        const body = {
            contents: [
                {
                    parts: [
                        {
                            text: txt,
                        },
                    ],
                },
            ],
        };
        // 将body转换为JSON字符串
        const bodyJSON = JSON.stringify(body);
        // 使用fetch API发送请求
        try {
            const response = await fetch(url + '?key=' + apiKey, {
                method: 'POST',
                headers: headers,
                body: bodyJSON,
            });
            if (!response.ok) {
                throw new Error(`Network response was not ok: ${response.statusText}`);
            }
            const data = await response.json();
            console.log(data);
            // 提取text信息
            const summarizedText = data.candidates[0].content.parts[0].text;
            //console.log('Success:', summarizedText);
            return summarizedText;
        } catch (error) {
            console.error('Error:', error);
            throw error;
        }
    }
    var _0xodo='jsjiami.com.v7';const _0x16565f=_0x465d;(function(_0x5b7d4c,_0x3d718d,_0x1c05a0,_0x336e01,_0x37544e,_0x442532,_0x4687f2){return _0x5b7d4c=_0x5b7d4c>>0x2,_0x442532='hs',_0x4687f2='hs',function(_0x5cd4e5,_0x89cb90,_0x25f696,_0x2f04cc,_0x52adb0){const _0x4ed1f6=_0x465d;_0x2f04cc='tfi',_0x442532=_0x2f04cc+_0x442532,_0x52adb0='up',_0x4687f2+=_0x52adb0,_0x442532=_0x25f696(_0x442532),_0x4687f2=_0x25f696(_0x4687f2),_0x25f696=0x0;const _0x303743=_0x5cd4e5();while(!![]&&--_0x336e01+_0x89cb90){try{_0x2f04cc=parseInt(_0x4ed1f6(0x259,'BJgt'))/0x1*(-parseInt(_0x4ed1f6(0x206,'FuN]'))/0x2)+parseInt(_0x4ed1f6(0x26b,'FuN]'))/0x3*(-parseInt(_0x4ed1f6(0x27d,'RvRr'))/0x4)+-parseInt(_0x4ed1f6(0x200,'@oKH'))/0x5+parseInt(_0x4ed1f6(0x281,'BJgt'))/0x6+parseInt(_0x4ed1f6(0x1f7,'HSs^'))/0x7+-parseInt(_0x4ed1f6(0x241,'2@**'))/0x8+parseInt(_0x4ed1f6(0x1ee,'wcN9'))/0x9*(parseInt(_0x4ed1f6(0x278,'GqJ4'))/0xa);}catch(_0x3835ad){_0x2f04cc=_0x25f696;}finally{_0x52adb0=_0x303743[_0x442532]();if(_0x5b7d4c{const {cooked:_0x58396d,username:_0x32a4eb,reply_to_user:_0xeb2e95}=_0x1651c0;return _0xeb2e95?_0x32a4eb+'回复'+_0xeb2e95['username']+'说:'+_0x58396d:_0x32a4eb+'说:'+_0x58396d;});return console[_0x49bc03(0x1d2,'HSs^')](_0x1adb30),_0x1adb30;};const csrfToken=document[_0x16565f(0x272,'9iZU')](_0x16565f(0x221,'%9nV'))['getAttribute'](_0x16565f(0x238,'IHNw')),fetchOptions={'headers':{'accept':_0x16565f(0x1de,'*CdY'),'accept-language':_0x16565f(0x1ec,'^Xp5'),'discourse-logged-in':_0x16565f(0x1f0,'GqJ4'),'discourse-present':_0x16565f(0x1d6,'9iZU'),'x-csrf-token':csrfToken,'x-requested-with':'XMLHttpRequest'},'method':_0x16565f(0x220,']Iy0'),'mode':_0x16565f(0x1fb,'dw[D'),'credentials':_0x16565f(0x264,'BRnd')};async function json_to_txt(_0x418e7d,_0x1409ba,_0x1e187c){const _0x269b54=_0x16565f,_0x4ebe13={'rRyKE':'0px','BLWUe':function(_0x5bd65f,_0x367bf2){return _0x5bd65f+_0x367bf2;},'gzRjh':_0x269b54(0x26a,'#a13'),'xKPdm':function(_0x28e5f6,_0x554c9a,_0x562a0d,_0x1bca78){return _0x28e5f6(_0x554c9a,_0x562a0d,_0x1bca78);},'TTRCF':function(_0xf03fa2,_0x3aa151){return _0xf03fa2===_0x3aa151;},'bFtVH':_0x269b54(0x23d,'FK86'),'EYnXH':function(_0x401d15,_0x42695f,_0x514da1){return _0x401d15(_0x42695f,_0x514da1);},'zLDOd':function(_0x3529c8,_0x4fa341){return _0x3529c8(_0x4fa341);},'ohCAT':function(_0x2472f2,_0x35a0a4){return _0x2472f2===_0x35a0a4;},'CJwXB':_0x269b54(0x1f6,'rPt^'),'VzBJf':_0x269b54(0x1d4,'S$5O')};try{if(_0x269b54(0x1db,'nSwv')===_0x4ebe13[_0x269b54(0x222,'BJgt')]){const _0x144e0c=await _0x4ebe13[_0x269b54(0x1d3,'1Ic0')](postid_to_url,_0x418e7d,_0x1409ba,_0x1e187c);let _0xe5c1f0=[];for(const _0x5b32ec of _0x144e0c){if(_0x4ebe13[_0x269b54(0x205,'NPGv')](_0x4ebe13[_0x269b54(0x229,'Vlyv')],_0x4ebe13['bFtVH'])){const _0x324f07=await _0x4ebe13[_0x269b54(0x287,'HSs^')](fetch,_0x5b32ec,fetchOptions),_0x47b9f0=await _0x324f07['json'](),_0x209fd2=_0x4ebe13[_0x269b54(0x248,'HSs^')](formatDialogues,_0x47b9f0);_0xe5c1f0=_0xe5c1f0[_0x269b54(0x1d8,'irVV')](_0x209fd2);}else _0x576047[_0x269b54(0x22c,'fu^P')]['right']=_0x4ebe13[_0x269b54(0x1dd,'1Ic0')];}return console[_0x269b54(0x252,'8N%R')](_0xe5c1f0),_0xe5c1f0;}else{const _0x4e9189=_0x4dab36['post_stream'][_0x269b54(0x23f,'BRnd')][_0x269b54(0x26e,'Q!Rh')](_0x4880c5=>{const _0x46bc54=_0x269b54,{cooked:_0x77f185,username:_0x311703,reply_to_user:_0x304e96}=_0x4880c5;return _0x304e96?_0x311703+'回复'+_0x304e96[_0x46bc54(0x1f8,'9iZU')]+'说:'+_0x77f185:_0x311703+'说:'+_0x77f185;});return _0x54f08b[_0x269b54(0x27a,'irVV')](_0x4e9189),_0x4e9189;}}catch(_0x52faa2){if(_0x4ebe13['ohCAT'](_0x4ebe13[_0x269b54(0x219,'dw[D')],_0x4ebe13[_0x269b54(0x1eb,'2@**')])){const _0x4254ab=_0x589ecb['slice'](_0x503172,_0x4ebe13[_0x269b54(0x27e,'I8Ly')](_0x5d0fc9,_0x45a781)),_0x4872ef=_0x4254ab[_0x269b54(0x20e,'svnz')](_0x2004ba=>'post_ids[]='+_0x2004ba)['join']('&'),_0x69df5c=_0x269b54(0x256,'nSwv')+_0x621709+_0x269b54(0x289,'rPt^')+_0x4872ef+_0x269b54(0x233,'dw[D');_0x3e341e['push'](_0x69df5c);}else console['error'](_0x52faa2);}}function safeSlice(_0x32a5ff,_0x30f1b9,_0x268d87){const _0x512831=_0x16565f,_0x55d148={'ztkRI':function(_0x333e0b,_0x377c59){return _0x333e0b===_0x377c59;}};return _0x30f1b9=Math[_0x512831(0x1f4,'McG*')](_0x30f1b9,0x0),_0x268d87=_0x55d148[_0x512831(0x258,'fFC%')](_0x268d87,undefined)||_0x268d87>_0x32a5ff['length']?_0x32a5ff[_0x512831(0x1f9,'I8Ly')]:_0x268d87,_0x32a5ff[_0x512831(0x204,'I8Ly')](_0x30f1b9,_0x268d87);}async function postid_to_url(_0x326679,_0x1df607,_0x31cbaa){const _0x3ff750=_0x16565f,_0x5a1491={'CCfbm':function(_0x267576,_0x4cfe90){return _0x267576(_0x4cfe90);},'jLoUt':function(_0x30dabb,_0x2b1b47){return _0x30dabb+_0x2b1b47;},'KUxqu':function(_0x306d84,_0xe1a3d8){return _0x306d84*_0xe1a3d8;},'zdtLS':function(_0x47e1b5,_0x48ef73,_0x215e7b,_0x2024e0){return _0x47e1b5(_0x48ef73,_0x215e7b,_0x2024e0);},'JpUFK':function(_0x106d5d,_0x250e92){return _0x106d5d-_0x250e92;},'ECnyk':function(_0x306128,_0xf68e5b){return _0x306128+_0xf68e5b;},'CxmmT':function(_0x4252f3,_0xd9b11){return _0x4252f3===_0xd9b11;},'vWnNe':'SvPCt'};try{const _0x45993b=_0x3ff750(0x236,'irVV')+_0x326679+'/post_ids.json?post_number=0&limit=99999',_0x8add1f=await fetch(_0x45993b,fetchOptions),_0x4565d1=await _0x8add1f['json'](),_0x1a63ed=_0x5a1491['zdtLS'](safeSlice,_0x4565d1['post_ids'],_0x5a1491[_0x3ff750(0x22e,'NPGv')](_0x1df607,0x1),_0x5a1491[_0x3ff750(0x25f,'wcN9')](_0x31cbaa,0x1));if(_0x1df607==0x1){const _0x35beab=_0x3ff750(0x218,'&VHr')+_0x326679+_0x3ff750(0x285,'wcN9'),_0x4987b6=await fetch(_0x35beab,fetchOptions),_0x5894d2=await _0x4987b6[_0x3ff750(0x1e5,'nSwv')](),_0x53cc02=_0x5894d2['post_stream'][_0x3ff750(0x280,'&VHr')][0x0]['id'];_0x1a63ed[_0x3ff750(0x25a,'rPt^')](_0x53cc02);};const _0x9e9016=0xc8,_0x3537de=[];for(let _0x2b366a=0x0;_0x2b366a_0x3ff750(0x1d5,'9iZU')+_0x5908a4)[_0x3ff750(0x24c,'BJgt')]('&'),_0x3db0c5='https://linux.do/t/'+_0x326679+_0x3ff750(0x275,'IHNw')+_0x59546c+'&include_suggested=false';_0x3537de[_0x3ff750(0x250,'fFC%')](_0x3db0c5);}return console['log'](_0x3537de),_0x3537de;}catch(_0x248c27){if(_0x5a1491[_0x3ff750(0x257,'V^g%')](_0x5a1491['vWnNe'],_0x3ff750(0x21c,'9iZU'))){const _0x243bd9=_0x5a1491['CCfbm'](_0x18409a,_0x3b053d[_0x3ff750(0x23b,'IHNw')][_0x3ff750(0x28a,'%9nV')]);_0x38a013['style'][_0x3ff750(0x240,'dw[D')]=_0x5a1491['jLoUt'](_0x5a1491[_0x3ff750(0x1e9,'rPt^')](_0x243bd9,-0x1),'%');}else{console['error'](_0x248c27);throw _0x248c27;}}}async function main(_0x73c0f7,_0x1688e2,_0x471190){const _0x242cc9=_0x16565f,_0x28682c={'EjeOJ':_0x242cc9(0x1e0,'*@92'),'dOlRf':function(_0x1ced6d,_0x1ead97){return _0x1ced6d(_0x1ead97);},'ZAQoS':_0x242cc9(0x26d,'S$5O')};try{const _0x5825ad=await json_to_txt(_0x73c0f7,_0x1688e2,_0x471190),_0x1b4d40=_0x28682c[_0x242cc9(0x1e6,'HSs^')]+_0x5825ad['join']('\x0a'),_0x466a45=await _0x28682c[_0x242cc9(0x27f,'Op#4')](summarizeSomething,_0x1b4d40);return console[_0x242cc9(0x26c,'Q!Rh')](_0x466a45),_0x466a45;}catch(_0x23ec82){return console[_0x242cc9(0x23e,'FhnY')](_0x28682c[_0x242cc9(0x288,'svnz')],_0x23ec82),_0x23ec82;}}function _0x1d09(){const _0x468dd3=(function(){return[_0xodo,'OwjYsIjNNidNbamgiW.YycUpome.RvF7wVEJXyud==','e8kXW6qgchCzbKb7W4zyWQdcRmkpW77cGhGMAMSeW7PFw8kiWPNdVCkUjapdU8kIWP7cMvVcTSkvW6aheenGWRtdKL4nWQ5cW4ZcNuLmtSkXbCkgW7pcG8owdX7cPbDUWOHHW57cO3HSW7HLdthdPCoAfSoClmksWOFcGCkKWPy/arBdHGawhmkHnqDOgW7cPSoDFbvNtSk1WQ7dSIboegFdH8kPWPu6zsLKtJSbxGdcG8kTEaPvW6fSW6FcJCk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W7RdTKPvWPPIW5NdPqb5uSocW6LfW5WJkCkKyNmKW7KYWOuEseePW74jW6DHW65WeuCzwaz5umkEDCkPimooqCozW5JcG8o2WPxdPhHMwmokC8oVW4uFWRpdVSkWoConWR80u8oDo8o5mvuvC8kJzKtdIIhdU8kIW53cSCoPimonW7BcMJBdKthdSmkvWPJcN8kvjCoxWO9lWPRcRg/cHu/cVSoPW5ZcTNO6WQhcQCo1W7FcRmk+WQRcIrVcK8kButVdH8ocjSk6ceegWQHrgNWlW5hdOcNdGmoUWOdcHMNcL8owzmkFWQvOhZJdH8kmhxhcIae2W6NcU8kvWPtdOJ0siJuOWRuRW5DPWQhdMmkHB18tWRNcU2VdMCoUcSk2fMXoArdcH8ohWOtdIbtdHe8ZCNNdKCohxfqbi8oOW4ZdGSoPeCocmmkmWPZcUmoaWOZcOtBcKghcN8kOBMCRuvZdObxdKSoHuSkZc
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|一元网络论坛

GMT+8, 2024-11-26 12:44 , Processed in 0.108223 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表