// ==UserScript== // @name pseudo-Benben - tiger0132 // @namespace request://tampermonkey.net/ // @version 0.3 // @description qwq // @author tiger0132 // @match https://*.luogu.com.cn/ // @grant unsafeWindow // @grant GM_setValue // @grant GM_getValue // @grant GM_removeValue // @downloadURL none // ==/UserScript== (function () { 'use strict'; const $ = unsafeWindow.$; const request = ({ url, data }) => { return new Promise((resolve, reject) => { unsafeWindow.handleData = data => { const keys = Object.keys(data); const keysLen = keys.length; return keys.reduce((pre, cur, index) => { const value = encodeURIComponent(data[cur]); const flag = index !== keysLen - 1 ? '&' : ''; return `${pre}${cur}=${value}${flag}`; }, ''); }; const script = document.createElement('script'); unsafeWindow.handleResponse = res => { document.body.removeChild(script); delete unsafeWindow.handleResponse; resolve(res); }; script.src = `${url}?${handleData(data)}`; document.body.appendChild(script); }); }; function verifyToken(token) { console.log(token); fetch("https://www.luogu.com.cn/paste/new", { "headers": { "content-type": "application/json;charset=UTF-8", "x-csrf-token": document.getElementsByName('csrf-token')[0].content, }, "body": `{"public":true,"data":"${token}"}`, "method": "POST", }).then(resp => resp.json()).then(resp => { request({ url: 'https://akioi.ml:8204/api/verifyToken', data: { pasteId: resp.id } }).then(res => { if (res.status != 200) { console.error(res.data); return alert('[Benben\'] 出了一点问题 >_<'); } console.log(`[Benben'] token: ${token}, paste: ${resp.id}`); GM_setValue('benben_token', token); fetch(`https://www.luogu.com.cn/paste/delete/${resp.id}`, { "credentials": "include", "headers": { "content-type": "application/json;charset=UTF-8", "x-csrf-token": document.getElementsByName('csrf-token')[0].content, }, "referrer": "https://www.luogu.com.cn/paste/nzqcvntn", "referrerPolicy": "no-referrer-when-downgrade", "body": `{\"data\":\"${token}\",\"id\":\"${resp.id}\",\"public\":true}`, "method": "POST", "mode": "cors" }).then(res => res.json()).then(res => { if (res.id != resp.id) { console.error(`error when deleting paste: ${res.id} != ${resp.id}`); return alert('[Benben\'] 出了一点问题 >_<'); } alert('[Benben\'] 验证成功,请刷新'); }); }); }); } function genNewToken() { request({ url: 'https://akioi.ml:8204/api/getToken', data: { uid: _feInstance.currentUser.uid } }).then(token => { if (token.status != 200) { console.error(res.data); return alert('[Benben\'] 出了一点问题 >_<'); } verifyToken(token.data); }); } const token = GM_getValue('benben_token'); var sendMode = 1; // 1 是伪犇,0 是原 var origSend; function injectPostFeed() { origSend = $._data($('#feed-submit')[0], 'events').click[0].handler; $('#feed-submit').unbind(); document.getElementById('feed-submit').onclick = function () { console.log(sendMode); if (sendMode) { this.classList.add('am-disabled'); var content = document.getElementById('feed-content').value; request({ url: 'https://akioi.ml:8204/api/postFeed', data: { content: content, token: token } }).then(resp => { if (resp.status !== 200) { show_alert('好像哪里有点问题', resp.data); } else { document.getElementById('feed-content').value = ''; switchMode('pbenben-all'); } this.classList.remove('am-disabled'); }); } else origSend(); }; } const selector_html = `伪犇犇`; var origLoadFeed = unsafeWindow.loadFeed; unsafeWindow.loadFeed = () => { if (unsafeWindow.feedMode.indexOf('pbenben') != -1) p_loadFeed(); else origLoadFeed(); } function p_loadFeed() { request({ url: 'https://akioi.ml:8204/feed/' + unsafeWindow.feedMode.substr(8), data: { page: unsafeWindow.feedPage, uid: _feInstance.currentUser.uid } }).then(resp => { $feed.append(resp.data); $('#feed-more').children('a').text('点击查看更多...') $('[name=feed-reply]').click(function () { var content = $(this).parents('li.feed-li').find('.feed-comment').text(); $('#feed-content').val(' || @' + $(this).attr('data-username') + ' : ' + content) }) }); feedPage++; } function addSelector() { var node = document.createElement('li'); node.className = 'feed-selector'; node.setAttribute('data-mode', 'pbenben-all'); node.id = 'pbenben-all'; node.innerHTML = selector_html; document.getElementById('home-center-nav').appendChild(node); $('#pbenben-all').click(() => { switchMode('pbenben-all'); sendMode = 1; }); } const status_html = `