吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1820|回复: 10
收起左侧

[学习记录] 粉笔网答案

[复制链接]
yk156511 发表于 2026-4-20 15:21
本帖最后由 yk156511 于 2026-4-20 15:23 编辑

[Asm] 纯文本查看 复制代码
// ==UserScript==
// @name         粉笔行测答案(修复可运行)
// @namespace    [url]https://fenbi.com/[/url]
// @version      2.0
// @description  修复不运行、不弹窗问题
// @match        *://*.fenbi.com/*
// @grant        GM_addStyle
// @run-at       document-end
// ==/UserScript==

(async function () {
    console.log("✅ 脚本已运行");

    // 样式
    GM_addStyle(`
        #fenbiAnswerPopup {
            position: fixed;
            top: 20px;
            right: 20px;
            width: 380px;
            background: #fff;
            border: 1px solid #ccc;
            z-index: 99999999;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.2);
        }
        .refreshBtn {
            padding: 6px 10px;
            background: #165DFF;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
    `);

    // 创建弹窗
    function createPopup() {
        let pop = document.getElementById('fenbiAnswerPopup');
        if (pop) return pop;

        pop = document.createElement('div');
        pop.id = 'fenbiAnswerPopup';
        pop.innerHTML = `
            <h4>粉笔行测答案</h4>
            <button class="refreshBtn" id="refreshAns">刷新答案</button>
            <div id="ansContent" style="margin-top:10px;">等待获取...</div>
        `;
        document.body.appendChild(pop);

        document.getElementById('refreshAns').onclick = getAnswers;
        return pop;
    }

    // 核心获取答案
    async function getAnswers() {
        const content = document.getElementById('ansContent');
        content.innerText = "加载中...";

        try {
            // 1. 找接口
            const ress = performance.getEntriesByType('resource');
            let apiUrl = null;
            for (let r of ress) {
                if (r.name.includes('tiku.fenbi.com/combine/static/exercise') && r.name.includes('key=')) {
                    apiUrl = r.name;
                    break;
                }
            }

            if (!apiUrl) {
                content.innerText = "&#10060; 请刷新题本页面";
                return;
            }

            // 2. 拿题目ID
            const res = await fetch(apiUrl, { credentials: 'include' });
            const data = await res.json();
            const questions = data.questions || [];
            const ids = questions.map(q => q.id).filter(Boolean);

            if (!ids.length) {
                content.innerText = "&#10060; 未获取到题目ID";
                return;
            }

            // 3. 拿答案
            const ansRes = await fetch(`[url]https://tiku.fenbi.com/api/xingce/questions?ids=[/url]${ids.join(',')}`, {
                credentials: 'include'
            });
            const ansData = await ansRes.json();

            // 4. 解析
            let result = [];
            ansData.forEach((item, i) => {
                const c = item.correctAnswer?.choice;
                const ans = ["A", "B", "C", "D"][c] || "?";
                result.push(`${i + 1}.${ans}`);
            });

            content.innerText = result.join('  ');

        } catch (e) {
            content.innerText = "&#10060; 错误:" + e.message;
            console.error(e);
        }
    }

    // 页面加载完立即显示弹窗
    setTimeout(() => {
        createPopup();
        getAnswers();
    }, 1000);

})();

免费评分

参与人数 2吾爱币 +1 热心值 +2 收起 理由
ttxccjx123 + 1 我很赞同!
lsb2pojie + 1 + 1 热心回复!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

rcg1997 发表于 2026-4-20 15:26
分区错了吧
ITHM 发表于 2026-4-20 16:01
zzqiang97 发表于 2026-4-20 17:37
Crysis-逆神 发表于 2026-4-21 00:42
啥意思,解释一下
lbdcyy 发表于 2026-4-21 08:39
这是个什么东东?很是奇怪.....
zxinyun 发表于 2026-4-21 08:55
本帖最后由 zxinyun 于 2026-4-21 12:37 编辑

[HTML] 纯文本查看 复制代码
&#10060; 错误:Unexpected token '<', "<!doctype "... is not valid JSON


改良一下:
[JavaScript] 纯文本查看 复制代码
// ==UserScript==
// [url=home.php?mod=space&uid=170990]@name[/url]         粉笔行测助手 v7.5
// [url=home.php?mod=space&uid=467642]@namespace[/url]    https://fenbi.com/
// [url=home.php?mod=space&uid=1248337]@version[/url]      7.5
// @description  强制物理顺序 1:1 对齐,解决材料题导致的答案移位问题
// [url=home.php?mod=space&uid=195849]@match[/url]        *://*.fenbi.com/*
// [url=home.php?mod=space&uid=609072]@grant[/url]        GM_addStyle
// @run-at       document-end
// ==/UserScript==
 
(async function () {
    console.log("&#9989; 粉笔助手 v7.5 启动 - 纯净对齐模式");
 
    GM_addStyle(`
        #fbHelper {
            position: fixed; top: 120px; left: 10px; width: 180px;
            background: #fff; border: 2px solid #165DFF; z-index: 2147483647;
            padding: 10px; border-radius: 10px; box-shadow: 0 8px 20px rgba(0,0,0,0.15);
        }
        .fb-btn {
            width: 100%; padding: 8px; background: #165DFF; color: #fff;
            border: none; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: bold;
        }
        #fbAnsList {
            max-height: 250px; overflow-y: auto; margin-top: 10px;
            font-size: 13px; background: #fdfdfd; padding: 5px; border-radius: 5px; border: 1px solid #eee;
        }
        .ans-item { display: inline-block; width: 45%; margin: 2px; color: #333; border-bottom: 1px solid #f0f0f0; }
        .ans-item b { color: #165DFF; }
        .fb-stat { display: block; text-align: center; font-size: 11px; color: #165DFF; margin-top: 5px; }
    `);
 
    function createUI() {
        if (document.getElementById('fbHelper')) return;
        const div = document.createElement('div');
        div.id = 'fbHelper';
        div.innerHTML = `
            <div style="font-size:12px;font-weight:bold;color:#165DFF;margin-bottom:6px;text-align:center;">粉笔助手 v7.5</div>
            <button class="fb-btn" id="fbRun">同步并 1:1 填充</button>
            <span id="fbStat" class="fb-stat">就绪</span>
            <div id="fbAnsList">等待同步...</div>
        `;
        document.body.appendChild(div);
        document.getElementById('fbRun').onclick = startWork;
    }
 
    // 强制 1:1 顺序填充
    async function forceSequenceFill(ansChoices) {
        // 1. 寻找所有包含选项列表的 <ul> 容器,这才是真正的题目交互区
        const questionLists = Array.from(document.querySelectorAll('ul.choice-radios, .choice-radios'));
        
        let filledCount = 0;
        questionLists.forEach((ul, index) => {
            // index 0 对应第一个 <ul> (即第1题),index 1 对应第2题...
            const correctIdx = ansChoices[index];
            if (correctIdx !== undefined && correctIdx !== null) {
                // 寻找该 <ul> 下的第几个 <li>
                const options = ul.querySelectorAll('li.choice-radio, .choice-radio');
                if (options.length > correctIdx) {
                    const targetLi = options[correctIdx];
                    // 模拟点击 label 或内部的 input-radio
                    const clicker = targetLi.querySelector('.input-radio') || targetLi.querySelector('label') || targetLi;
                    clicker.click();
                    
                    // 触发 Angular 状态变更
                    const input = targetLi.querySelector('input');
                    if (input) {
                        input.dispatchEvent(new Event('change', { bubbles: true }));
                    }
                    filledCount++;
                }
            }
        });
        return filledCount;
    }
 
    async function startWork() {
        const list = document.getElementById('fbAnsList');
        const stat = document.getElementById('fbStat');
        list.innerText = "数据同步中...";
 
        try {
            const ress = performance.getEntriesByType('resource');
            const apiEntry = ress.find(r => r.name.includes('tiku.fenbi.com/combine/static/exercise') || r.name.includes('tiku.fenbi.com/api/xingce/exercises'));
 
            if (!apiEntry) {
                list.innerText = "&#10060; 未发现数据,请刷新。";
                return;
            }
 
            const res = await fetch(apiEntry.name, { credentials: 'include' });
            const data = await res.json();
            const ids = (data.questions || []).map(q => q.id).filter(id => id);
 
            const idsStr = ids.join(',');
            const ansRes = await fetch('https://tiku.fenbi.com/api/xingce/questions?ids=' + idsStr, { credentials: 'include' });
            const ansData = await ansRes.json();
 
            let ansChoices = [];
            let html = "";
            ids.forEach((id) => {
                const item = ansData.find(a => String(a.id) === String(id));
                const choice = item ? item.correctAnswer?.choice : null;
                ansChoices.push(choice);
                const char = (choice !== null && choice !== undefined) ? ["A", "B", "C", "D"][choice] : "?";
                html += `<div class="ans-item">${ansChoices.length}: <b>${char}</b></div>`;
            });
 
            list.innerHTML = html;
            stat.innerText = "正在 1:1 填充...";
 
            // 执行 3 轮滚动扫描,确保懒加载题目被触发
            for (let i = 0; i < 3; i++) {
                const num = await forceSequenceFill(ansChoices);
                if (num >= ids.length) break;
                window.scrollBy(0, 800);
                await new Promise(r => setTimeout(r, 600));
            }
            window.scrollTo(0, 0);
            stat.innerText = "&#10024; 填充完成";
 
        } catch (e) {
            list.innerText = "&#10060; 错误:" + e.message;
        }
    }
 
    setTimeout(createUI, 1500);
})();

点评

好的,谢谢  发表于 2026-4-22 09:47
Manson9527 发表于 2026-4-21 10:08
感谢分享
bubble1 发表于 2026-4-21 11:39
感谢分享
紫夜阑珊 发表于 2026-4-21 11:43
这个好像是油猴脚本。。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-6-6 05:12

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表