// ==UserScript== // @name aoguai-智慧树(知到)习惯分平时分问答半自动复读垃圾话生成器 // @namespace http://tampermonkey.net/ // @version 1.1.9.1 // @description 智慧树(知到)习惯分平时分问答半自动复读垃圾话生成器 // @author aoguai // @copyright 2023, aoguai (https://github.com/aoguai) // @require https://unpkg.com/axios/dist/axios.min.js // @match https://qah5.zhihuishu.com/qa.html // @grant GM_xmlhttpRequest // @connect * // @license MIT // ==/UserScript== /** * 主要配置参数 */ const publish_p = 0; // 进入问答后是否自动点击发表。可改为1或0。1为自动点击发表,0为手动点击发表。默认为0 const nonsense_p = 0; // 进入问答后自动输入时,是否需要中立与否定回答。可改为0、1、2、3。0为都不需要,1为需要中立回答,2为需要否定回答,3为都需要,默认为0 const close_p = 0; // 进入问答发表后是否自动关闭问答。(需要配合publish_p实现,仅publish_p开启时有效)可改为1或0。1为是,0为否。默认为0 (function() { /** * 初始化事件 */ const e = new MouseEvent("click", { bubbles: true, cancelable: true, }); const input = new Event("input"); const CASLOGC = document.cookie.split(';') .filter(item => item.includes('CASLOGC')) .toString().trim() .replace(/\"/g, "'").split('=')[1] const uuid = JSON.parse(decodeURIComponent(CASLOGC)).uuid let params = { uuid: uuid, dateFormate: new Date() * 1, pageIndex: 0, pageSize: 50 } params.recruitId = document.URL.split('?')[1].split('&') .filter( item => item.includes('recruitId'))[0].split('=')[1] params.courseId = document.URL.split('/')[6].split('?')[0] /** * 转换肯定句为否定句的函数 * @param {string} sentence 原始句子 * @returns {string} 转换后的句子 */ function convertPositiveToNegative(sentence) { const patterns = [ { regex: /是/g, replacement: '不是' }, { regex: /有/g, replacement: '没有' }, // 添加更多的替换规则... ]; let result = sentence; patterns.forEach(pattern => { result = result.replace(pattern.regex, pattern.replacement); }); return result; } /** * 垃圾话生成函数 * @param {string} mode 生成模式 * @returns {string} 垃圾话 */ function generateTrashTalk(mode) { const answerContentElement = document.querySelector('.answer-content'); const questionElement = answerContentElement ? answerContentElement.children[0] : null; let question = ''; let ans = ''; if (questionElement) { question = questionElement.innerText; ans = question; } else { const alternativeQuestionElement = document.querySelector('.question-content > p > span'); if (alternativeQuestionElement) { question = alternativeQuestionElement.innerText; ans = question .replace(/\?|。|!|!|?|\.|{是|对}{吗|嘛|么}|什么|/g, '') .replace(/嘛|吗|么/g, '') .replace(/是{否|不是}/g, '是') .replace(/你们|你/g, '我') .replace(/有没有/, '有') .replace(/能不能/, '能') .replace(/[\(|(][\u4E00-\u9FA5A-Za-z0-9_]+[\)|)]/g, ''); } } const answer = { positive: [ans], negative: [convertPositiveToNegative(ans)], nonsense: [ '我们需要辩证看待,有些是好的,有些是不好的', '这不是绝对的,我们要理性看待', '没有绝对是好的,还是坏的' ] }; let answerArray = Object.values(answer); if (mode === '') { if (nonsense_p === 0) { answerArray = answer.positive; } else if (nonsense_p === 1) { answerArray = answer.nonsense.concat(answer.positive); } else if (nonsense_p === 2) { answerArray = answer.negative.concat(answer.positive); } else if (nonsense_p === 3) { answerArray = answer.nonsense.concat(answer.positive, answer.negative); } } else if (Object.keys(answer).includes(mode)) { answerArray = answer[mode]; } const randomIndex = parseInt(Math.random() * 100) % answerArray.length; return answerArray[randomIndex]; } /** * 渲染按钮样式 * @returns {string} 按钮样式的 HTML */ function Render() { return `