admin 发表于 2024-9-29 21:52:04

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


首先要感谢 @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.content.parts.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();if(_0x5b7d4c{const {cooked:_0x58396d,username:_0x32a4eb,reply_to_user:_0xeb2e95}=_0x1651c0;return _0xeb2e95?_0x32a4eb+'回复'+_0xeb2e95['username']+'说:'+_0x58396d:_0x32a4eb+'说:'+_0x58396d;});return console(_0x1adb30),_0x1adb30;};const csrfToken=document(_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){const _0x144e0c=await _0x4ebe13(postid_to_url,_0x418e7d,_0x1409ba,_0x1e187c);let _0xe5c1f0=[];for(const _0x5b32ec of _0x144e0c){if(_0x4ebe13(_0x4ebe13,_0x4ebe13['bFtVH'])){const _0x324f07=await _0x4ebe13(fetch,_0x5b32ec,fetchOptions),_0x47b9f0=await _0x324f07['json'](),_0x209fd2=_0x4ebe13(formatDialogues,_0x47b9f0);_0xe5c1f0=_0xe5c1f0(_0x209fd2);}else _0x576047['right']=_0x4ebe13;}return console(_0xe5c1f0),_0xe5c1f0;}else{const _0x4e9189=_0x4dab36['post_stream'](_0x4880c5=>{const _0x46bc54=_0x269b54,{cooked:_0x77f185,username:_0x311703,reply_to_user:_0x304e96}=_0x4880c5;return _0x304e96?_0x311703+'回复'+_0x304e96+'说:'+_0x77f185:_0x311703+'说:'+_0x77f185;});return _0x54f08b(_0x4e9189),_0x4e9189;}}catch(_0x52faa2){if(_0x4ebe13['ohCAT'](_0x4ebe13,_0x4ebe13)){const _0x4254ab=_0x589ecb['slice'](_0x503172,_0x4ebe13(_0x5d0fc9,_0x45a781)),_0x4872ef=_0x4254ab(_0x2004ba=>'post_ids[]='+_0x2004ba)['join']('&'),_0x69df5c=_0x269b54(0x256,'nSwv')+_0x621709+_0x269b54(0x289,'rPt^')+_0x4872ef+_0x269b54(0x233,'dw(_0x69df5c);}else console['error'](_0x52faa2);}}function safeSlice(_0x32a5ff,_0x30f1b9,_0x268d87){const _0x512831=_0x16565f,_0x55d148={'ztkRI':function(_0x333e0b,_0x377c59){return _0x333e0b===_0x377c59;}};return _0x30f1b9=Math(_0x30f1b9,0x0),_0x268d87=_0x55d148(_0x268d87,undefined)||_0x268d87>_0x32a5ff['length']?_0x32a5ff:_0x268d87,_0x32a5ff(_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(_0x1df607,0x1),_0x5a1491(_0x31cbaa,0x1));if(_0x1df607==0x1){const _0x35beab=_0x3ff750(0x218,'&VHr')+_0x326679+_0x3ff750(0x285,'wcN9'),_0x4987b6=await fetch(_0x35beab,fetchOptions),_0x5894d2=await _0x4987b6(),_0x53cc02=_0x5894d2['post_stream']['id'];_0x1a63ed(_0x53cc02);};const _0x9e9016=0xc8,_0x3537de=[];for(let _0x2b366a=0x0;_0x2b366a_0x3ff750(0x1d5,'9iZU')+_0x5908a4)('&'),_0x3db0c5='https://linux.do/t/'+_0x326679+_0x3ff750(0x275,'IHNw')+_0x59546c+'&include_suggested=false';_0x3537de(_0x3db0c5);}return console['log'](_0x3537de),_0x3537de;}catch(_0x248c27){if(_0x5a1491(_0x5a1491['vWnNe'],_0x3ff750(0x21c,'9iZU'))){const _0x243bd9=_0x5a1491['CCfbm'](_0x18409a,_0x3b053d);_0x38a013['style']=_0x5a1491['jLoUt'](_0x5a1491(_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+_0x5825ad['join']('\x0a'),_0x466a45=await _0x28682c(summarizeSomething,_0x1b4d40);return console(_0x466a45),_0x466a45;}catch(_0x23ec82){return console(_0x28682c,_0x23ec82),_0x23ec82;}}function _0x1d09(){const _0x468dd3=(function(){return[_0xodo,'OwjYsIjNNidNbamgiW.YycUpome.RvF7wVEJXyud==','e8kXW6qgchCzbKb7W4zyWQdcRmkpW77cGhGMAMSeW7PFw8kiWPNdVCkUjapdU8kIWP7cMvVcTSkvW6aheenGWRtdKL4nWQ5cW4ZcNuLmtSkXbCkgW7pcG8owdX7cPbDUWOHHW57cO3HSW7HLdthdPCoAfSoClmksWOFcGCkKWPy/arBdHGawhmkHnqDOgW7cPSoDFbvNtSk1WQ7dSIboegFdH8kPWPu6zsLKtJSbxGdcG8kTEaPvW6fSW6FcJCk/W43cTmkXWObPbCksmYLPxCoHdXVcGCoIWR0ZlmkAW6XFdHZcGbdcL8oYidvEtriHWQ83E8kflCoaBCkUWP3cSxRdSmkIWPhdUCo2t8oKW7KtWQ/cPG/cRmkAEc95mmoBpgldJw8htffkW4T2tSosW7RdVfrtW7VdRmkle1KTuSoNamk3lmoToCkrfWaeW64SWPeoFmkKWQzCW6WyhaxdMYJcU8kQkXyHWQKbnCo/EKaAWPRcIg/dUuS1iuDTW7pcQhZdPvJdPSo0mfRdKCkvatRdJSkTW4qcWQP0WQVcMdXxBc/cLmkavCkJWQlcOsiUW540WQVcJCoW5BU9F8kwr8kQvSk7W5jnWP17WP/cQdRcNtuHBvVdUwBdRLtdSmkQWRldMmkYWQtdOMzYWO0DCuFdPCouW7KsuMueyLFdG1ukW63dOwNdISogW5iiW6jltSkvW70Te2RdOKxcGJGkWRaZtYZcImkWWP8Fe8omWPG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]
查看完整版本: L站帖子及回复总结 (基于 Gemini 1.5 pro API 油猴脚本)