// ==UserScript== // @name 查看S1不可见内容(审核中/禁言)自动版 // @namespace http://tampermonkey.net/ // @version 0.1.6 // @description 查看S1正在审核中的帖子和被禁言用户的回帖 // @author ShienPro // @match https://*.saraba1st.com/2b/thread-* // @match https://*.saraba1st.com/2b/forum.php*tid=* // @grant none // @require https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js // @require https://cdn.staticfile.org/jsrender/1.0.8/jsrender.min.js // @license WTFPL // @downloadURL https://update.greasyfork.icu/scripts/470638/%E6%9F%A5%E7%9C%8BS1%E4%B8%8D%E5%8F%AF%E8%A7%81%E5%86%85%E5%AE%B9%28%E5%AE%A1%E6%A0%B8%E4%B8%AD%E7%A6%81%E8%A8%80%29%E8%87%AA%E5%8A%A8%E7%89%88.user.js // @updateURL https://update.greasyfork.icu/scripts/470638/%E6%9F%A5%E7%9C%8BS1%E4%B8%8D%E5%8F%AF%E8%A7%81%E5%86%85%E5%AE%B9%28%E5%AE%A1%E6%A0%B8%E4%B8%AD%E7%A6%81%E8%A8%80%29%E8%87%AA%E5%8A%A8%E7%89%88.meta.js // ==/UserScript== (function () { 'use strict'; const $ = jQuery.noConflict(); const api = 'https://app.saraba1st.com/2b/api/app'; const dialogTmpl = $.templates(`
通过s1官方app接口查看不可见内容,需要单独登录
{{:msg}}
`); const postTmpl = $.templates(`
{{:message}}
`); const threadTmpl = $.templates(`
{{if nextPage != null}} 下一页 {{/if}}
返回列表
查看: {{:views}}|回复: {{:replies}}
打印 上一主题 下一主题

{{:subject}}

{{if nextPage != null}}
下一页 »
{{/if}}
{{if nextPage != null}} 下一页 {{/if}}
`) const postInThreadTmpl = $.templates(`

{{:grouptitle}}

{{:position}}#
发表于 {{:time}} | 只看该作者
{{:message}}
回复

评分 举报

`) function login(username, password, questionId, answer) { const data = { username: username, password: password } if (questionId !== '0') { data.questionid = questionId; data.answer = answer; } $.ajax({ type: 'POST', url: api + '/user/login', data: data, success: function (resp) { const code = resp.code.toString(); if (code.startsWith('50')) { loginAndReplaceThreadContent({username, password, msg: resp.message}); return; } localStorage.setItem('app_sid', resp.data.sid); $('#login-dialog').remove(); main(); }, error: function (err) { loginAndReplaceThreadContent({username, password, msg: '请求错误'}); } }); } function loginAndReplaceThreadContent(data) { $('#login-dialog').remove(); $('body').append(dialogTmpl.render(data)); const rawHeight = $('#login-dialog').height(); $('#questionId').change(function () { let questionId = $(this).val(); if (questionId === '0') { $('#login-dialog').height(rawHeight); $('#answer-row').hide(); } else { $('#login-dialog').height(rawHeight + 44); $('#answer-row').show(); } }); $('#login-confirm').click(function () { const username = $('#username').val(); const password = $('#password').val(); const questionId = $('#questionId').val(); const answer = $('#answer').val(); login(username, password, questionId, answer); }); } function replaceThreadContent() { // 整个帖子 if ($('#messagetext:contains(内容审核中,即将开放)').html()||$('#messagetext:contains(你无权访问)').html()) { getThreadInfo() .then(info => { info.pageNo = parseInt(pageNo); info.totalPage = (parseInt(info.replies / 30)) + 1; info.nextPage = info.pageNo < info.totalPage ? info.pageNo + 1 : null; $('#wp').html(threadTmpl.render(info)); document.title = document.title.replace('提示信息', info.subject + ' - ' + info.fname); return getThreadContent(); }) .then(data => { const postList = $('#postlist'); data.list.forEach(post => { const date = new Date(post.dateline * 1000); post.time = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes(); const content = postInThreadTmpl.render(post); postList.append(content); }); }) .catch(() => main({msg: "登录失效"})); } // 部分回复 else { const blockedPost = $('.plhin:contains(作者被禁止或删除 内容自动屏蔽)'); if (blockedPost.length === 0) return; getThreadContent() .then(data => { const postList = data.list; let pi = 0; blockedPost.each((i, post) => { const postId = post.id.substr(3); let postData; for (; pi < postList.length && (postData = postList[pi]).pid.toString() !== postId; pi++) ; $(post).find('.pcb').html(postTmpl.render(postData)); }); }) .catch(() => main({msg: "登录失效"})); } } function getThreadInfo() { return new Promise(function (resolve, reject) { $.ajax({ type: 'POST', url: api + '/thread', data: { sid: sid, tid: tid }, success: resp => handleRequest(resp, resolve, reject), error: function () { localStorage.removeItem('app_sid'); reject(); } }); }); } function getThreadContent() { return new Promise(function (resolve, reject) { $.ajax({ type: 'POST', url: api + '/thread/page', data: { sid: sid, tid: tid, pageNo: pageNo }, success: resp => handleRequest(resp, resolve, reject), error: function () { localStorage.removeItem('app_sid'); reject(); } }); }); } function handleRequest(resp, resolve, reject) { // content-type返回text/html可还行 resp = typeof resp === 'string' ? JSON.parse(resp) : resp; const code = resp.code.toString(); if (code.startsWith('50')) { localStorage.removeItem('app_sid'); reject(); return; } resolve(resp.data); } let sid, tid, pageNo; function getThreadId() { const pathname = window.location.pathname; if (pathname.startsWith('/2b/thread-')) { // [前缀, tid, pageNo, ...] const threadParams = location.pathname.split('-'); tid = threadParams[1]; pageNo = threadParams[2]; } else if (pathname.startsWith('/2b/forum.php')) { const urlParams = new URLSearchParams(window.location.search); tid = urlParams.get('tid'); pageNo = urlParams.get('page') || 1; } } function main(data) { data = data || {}; getThreadId(); if (!tid) return; sid = localStorage.getItem('app_sid'); if (sid) { replaceThreadContent(); } else { loginAndReplaceThreadContent(data); } } const text = $('#wp').text(); if (!(text.includes('作者被禁止或删除') || text.includes('内容审核中,即将开放')|| text.includes('你无权访问'))) { return; } main(); })();