学习记录 - js
type: channel
link: https://blog.moxiaoying.top/tag/js/
items: 法制考试常用脚本
items: 前端jsonp转换json格式

法制考试常用脚本
type: item
date: 2025-11-04T08:40:00+08:00
description: 1. 过无限debuggerFunction.prototype.__constructor_back = Function.prototype.constructor; Function.prototype.constructor = function() { if(arguments && typeof arguments[0]==='string'){ if("debugger" === arguments[0]){ return } } return Function.prototype.__constructor_back.apply(this,arguments); }2.自动答题{hide}q_list = decryptArray const span = createMessage() const sleep = async (time_delay) => { return new Promise(resolve => { setTimeout(() => { resolve() }, time_delay * 1000) }) } function createMessage() { const span = document.createElement('span') let style = `position: fixed; right: 10px; top: 80px; width: 500px; text-align: left; background-color: rgba(255, 255, 255, 0.9); z-index: 99; padding: 10px 20px; border-radius: 5px; color: #222; box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2); font-weight: bold;` span.setAttribute('style', style) span.innerText = '脚本启动成功' document.body.appendChild(span) return span } function message(text = '') { span.innerHTML = text } // 添加按钮到指定父元素 const addBtn = (content, click_func = null, parent_element = '.panel-title') => { let heasers = document.querySelector(parent_element); let button = document.createElement('button'); button.innerHTML = content; button.className = 'layui-btn layui-btn-warm'; button.onclick = click_func; heasers.append(button); } async function completeCurrentQuestion(num = 1) { const question = q_list[num - 1] for (const answer of question['answer_list']) { if (answer['op'] == 1) { let op = document.querySelector(`#questions input[value="${answer['id']}"]`) if (!op) { gen(num) await sleep(0.3) op = document.querySelector(`#questions input[value="${answer['id']}"]`) } op.click() } } } async function generateQuestion(num = 1) { document.querySelector(`#btn-${num}`).click(); } const start = async () => { const func = async () => { for (let i = 1; i <= 100; i++) { generateQuestion(i) await sleep(0.3) await completeCurrentQuestion(i); await sleep(2.6) } // 等待30分钟后点击交卷 message('等待5分钟后点击交卷') await sleep(60*5) document.que…

前端jsonp转换json格式
type: item
date: 2023-07-21T21:56:30+08:00
description: 以百度搜索建议为例后端返回数据样式({ q: "没有的", p: false, s: ["没有的英语单词", "没有的读音", "没有的近义词", "没有的事总是能胡思乱想出一些事"] });使用js处理const response = await axios.get( `https://www.baidu.com/su?wd=${encodeURIComponent(query)}&cb=hello`, ); // 提取JSON部分 const apiResponse = response.data.match(/hello\(([^)]+)\)/)[1]; const data = JSON.parse(apiResponse.replace(/(\w+)(?=:)/g, '"$1"'));