首页 > 其他分享 >智慧树(知到)习惯分问答生成器结合ai改写 需要自己的cookie,我找了半天,也没找到完全免费的或者有很多次数的网站

智慧树(知到)习惯分问答生成器结合ai改写 需要自己的cookie,我找了半天,也没找到完全免费的或者有很多次数的网站

时间:2022-10-10 16:33:46浏览次数:50  
标签:function const ai text 生成器 item cookie let document

仅作用于问答详情界面,未设置自动发布

 

// ==UserScript==
// @name         Whee1-智慧树(知到)习惯分问答生成器结合ai改写
// @namespace    http://tampermonkey.net/
// @version      1.1.6
// @description  半自动回答习惯分问题
// @author       ch3cknull
// @require      https://unpkg.com/axios/dist/axios.min.js
// @match        https://qah5.zhihuishu.com/qa.html
// @license      MIT
// @grant        GM_xmlhttpRequest
// ==/UserScript==
function serialize(obj) {
    return "object" == typeof obj ? "" + new URLSearchParams(Object.entries(obj)) : "string" == typeof obj ? obj : "" + obj
    // let t = [];
    // switch (Object.prototype.toString.call(e)) {
    //  case "[object Array]":
    //  case "[object Object]":
    //      return Object.keys(e).forEach(n => {
    //          t.push(u.serialize(e[n], o ? o + "[" + n + "]" : n))
    //      }), 0 == t.length ? "" : t.join("&");
    //  default:
    //      return o + "=" + encodeURIComponent("" + e)
    // }
}

(function () {
    const e = document.createEvent("MouseEvents");
    e.initEvent("click", true, true);
    const input = document.createEvent("HTMLEvents");
    input.initEvent("input", true, false);
    const state = (document.URL.includes('home')) ? 'home' : 'detail'
    const MY_ANSWER_API = "https://creditqa.zhihuishu.com/creditqa/web/qa/myAnswerList"
    const HOT_QUESTION = "https://creditqa.zhihuishu.com/creditqa/web/qa/getHotQuestionList"
    const NEW_QUESTION = "https://creditqa.zhihuishu.com/creditqa/web/qa/getRecommendList"
    const config = {
        offset: 0,
        currURL: HOT_QUESTION
    }
    const CASLOGC = document.cookie.split(';')
        .filter(item => item.includes('CASLOGC'))
        .toString().trim()
        .replace(/\"/g, "'").split('=')[1]
    const uuid = JSON.parse(decodeURIComponent(CASLOGC)).uuid
    let reqCount = 0
    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]

    function Grama(mode) {
        const question = document.querySelector('.question-content').children[0].innerText
        const ans = question.replace(/\?|。|!|!|?|\.|{是|对}{吗|嘛|么}|什么|/g, "").replace(/嘛|吗|么/g, '')
            .replace(/是{否|不是}/g, '是').replace(/你们|你/g, '我').replace(/有没有/, '有').replace(/能不能/, '能')
            .replace(/[\(|(][\u4E00-\u9FA5A-Za-z0-9_]+[\)|)]/g, '')
        const answer = {
            positive: [
                `我个人认为${ans}`,
                `我觉得是的,${ans}`,
            ],
            negative: [
                `我觉得不对,${ans}是不对的`
            ],
            nonsence: [
                `我们需要辩证看待,有些是正确的,有些是错误的`,
                `问题不是绝对的,我们要理性客观看待`,
                `这没有绝对是好的,还是坏的`
            ]
        }
        let arr = Object.values(answer).flat()
        if (Object.keys(answer).includes(mode)) arr = answer[mode]
        return arr[parseInt(Math.random() * 100) % arr.length] + "。"
    }

    function Render() {
        return `<div class="wheel-pannel"><button class="wheel-button wheel-positive">是的</button><button class="wheel-button wheel-negative">不是</button><button class="wheel-button wheel-nonsence">中立</button></div><style>.wheel-pannel{position:fixed;right:300px;top:120px;width:80px;height:30px;z-index:3000}.wheel-button{margin:5px 0;padding:0 5px;height:30px;width:80px;border:0;outline:0;border-radius:8px;color:#f0f8ff;font-size:16px;letter-spacing:1px}.wheel-positive{background:#7fd826}.wheel-negative{background:#d82626}.wheel-positive:hover{background:#99e051}.wheel-negative:hover{background:#e05151}.wheel-nonsence{background:black}.wheel-nonsence:hover{background:#333333}</style>`
    }

    function binding() {
        const panel = document.querySelector('.wheel-pannel')
        if (!panel) console.log('not panel')
        document.querySelector('.wheel-pannel').addEventListener('click', (e) => {
            const text = document.querySelector('textarea')
            const mode = e.target.classList[1].split('wheel-')[1]
            text.innerText = Grama(mode)
            text.dispatchEvent(input)
        })
        document.querySelector('.up-btn').addEventListener('click', () => {
            const questionId = location.hash.split('/')[4].split('?')[0]
            let answered = getMyAnswer()
            answered.push(questionId)
            localStorage.setItem('answered', JSON.stringify(answered))
        })
    }

    function bindingHome() {
        let list = document.querySelector('.el-scrollbar__view').children[0]
        document.querySelector('.tab-container').addEventListener('click', (e) => {
            let text = e.target.innerText
            if (text == "热门") config.currURL = HOT_QUESTION
            if (text == "最新") config.currURL = NEW_QUESTION
            if (text == "热门" || text == "最新") diffImprove(config.currURL)
        })
        let observer = new MutationObserver(mutations => {
            mutations.forEach(mutation => {
                if (mutation.type === 'childList') {
                    reqCount++;
                    if (reqCount == 50 && list.children.length !== 51) {
                        diffImprove(config.currURL)
                    }
                }
            })
        })
        observer.observe(list, {
            attributes: false,
            childList: true,
            subtree: false,
        })
    }
    async function getMyAnswer() {
        const courseId = document.URL.split('/')[6].split('?')[0]
        let answered = JSON.parse(localStorage.getItem('answered')) || {}
        let currentCourse = answered[courseId] || null
        let lastModified = JSON.parse(localStorage.getItem('lastModified')) || new Date() * 1
        let current = new Date() * 1
        if (currentCourse == null || current - lastModified > 600 * 1000) {
            const data = Object.assign(params)
            data.pageSize = 200
            await axios.get(MY_ANSWER_API, {
                params: data
            }).then(res => {
                currentCourse = res.data.rt.myAnswers.map(item => item.qid)
                console.log(currentCourse)
                answered[courseId] = currentCourse
                console.log(currentCourse);
                localStorage.setItem('answered', JSON.stringify(answered))
                localStorage.setItem('lastModified', JSON.stringify(new Date() * 1))
            })
        }
        return answered[courseId]
    }

    async function diffImprove(url = HOT_QUESTION, offset = 0) {
        if (url.includes('home')) return
        let myAnswer, pageAnswer, arr, ans
        //params and offset
        const data = Object.assign(params)
        data.pageIndex = config.offset
        config.offset = data.pageIndex + offset
        // get data
        myAnswer = await getMyAnswer()
        await axios.get(url, {
            params: data
        }).then(res => {
            pageAnswer = res.data.rt.questionInfoList
            arr = pageAnswer.map(item => item.questionId)
                .filter(item => myAnswer.includes(item))
            ans = pageAnswer.filter(item => arr.includes(item.questionId))
                .map(item => `${item.userDto.username}${item.content}`)
            patchImprove(ans)
        })
    }
    async function patchImprove(res) {
        // iterate dom list and add marks
        const list = Array.from(document.querySelectorAll('.question-item'))
        list.forEach(item => {
            const flag = item.querySelector('.user-name').title + item.querySelector('.question-content').title
            if (res.includes(flag)) {
                const child = item.querySelector(".question-content")
                child.innerText += "(已作答)"
                child.style.color = 'red'
                reqCount = 0
            }
        })
    }
    window.onload = () => {
        // if (state == 'home') setTimeout(home, 1000)
        // else setTimeout(detail, 1000)
        if (detail == 'detail') {
            setTimeout(detail, 1000)
        }

        async function detail() {
            const btn = document.querySelector('.my-answer-btn')
            if (btn == null) return
            btn.dispatchEvent(e)
            setTimeout(() => {
                let list = document.querySelectorAll("#app > div > div.question-all.clearfix > div.question-left > div.answer-box > ul > li > div.answer-content > p")
                var num = 0;
                for (let index = 0; index < list.length; index++) {
                    const ll = list[index].innerText.length;
                    if (ll > 10 && num == 0) {
                        num++;
                        var put1 = list[index].innerText
                    }
                    if (ll > 10 && num == 1) {
                        var put2 = list[index].innerText
                    }
                }

                const text = document.querySelector('textarea')
                const dialog = document.querySelector('.header-title')
                if (!text) return
                //   text.innerText = Grama("default")

                var put12 = put1 + ',' + put2
                GM_xmlhttpRequest({
                    method: 'POST',
                    url: 'https://www.aigaixie.com/zb_users/theme/aigaixie/api/api.php',
                    headers: {
                        'authority': 'www.aigaixie.com',
                        'accept': 'application/json, text/javascript, */*; q=0.01',
                        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
                        'x-requested-with': 'XMLHttpRequest',
                        'origin': 'https://www.aigaixie.com',
                        'referer': 'https://www.aigaixie.com/aiwriter.html',
                        'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,ru;q=0.7,zh-TW;q=0.6,ja;q=0.5',
                        'cookie': '需要自己的cookie,我找了半天,也没找到完全免费的或者有很多次数的网站'
                    },
                    data: serialize({
                        'act': 'aiwriter',
                        'Centont': put12,
                        'V': '3',
                        'Type': '0'
                    }),
                    onl oad: function (response) {
                        console.log(put12)
                        console.log(response.response)
                        let jsonn = JSON.parse(response.response)
                        var aiput12 = jsonn.html
                        debugger
                        text.innerText = aiput12
                        text.dispatchEvent(input)
                        // dialog.innerHTML += Render()
                        // binding()
                    },
                    one rror: function (err) {
                        console.log('error')
                        console.log(err)
                    }
                });


            }, 200)
        }
        async function home() {
            bindingHome()
            diffImprove()
        }
    }
})();

 

标签:function,const,ai,text,生成器,item,cookie,let,document
From: https://www.cnblogs.com/hhdom/p/16776164.html

相关文章