自动获取答案

自用真香,别看我主页

目前為 2024-09-24 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         自动获取答案
// @namespace    http://tampermonkey.net/
// @version      2.8
// @description  自用真香,别看我主页
// @author       郭郭郭
// @match        https://www.lnonl.com/post/*
// @match        https://gbwlxy.dtdjzx.gov.cn/*
// @match        https://dywlxy.dtdjzx.gov.cn/*
// @grant        GM_setValue
// @grant        GM_getValue
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const currentURL = window.location.href;

    function createFloatingWindow(content) {
        let floatingWindow = document.querySelector('#floatingWindow');
        if (!floatingWindow) {
            floatingWindow = document.createElement('div');
            floatingWindow.id = 'floatingWindow';
            floatingWindow.style.position = 'fixed';
            floatingWindow.style.top = '20px';
            floatingWindow.style.right = '20px';
            floatingWindow.style.width = '300px';
            floatingWindow.style.maxHeight = '400px';
            floatingWindow.style.overflowY = 'auto';
            floatingWindow.style.backgroundColor = 'white';
            floatingWindow.style.border = '1px solid black';
            floatingWindow.style.padding = '10px';
            floatingWindow.style.zIndex = '9999';
            floatingWindow.style.fontSize = '16px';
            document.body.appendChild(floatingWindow);
        }
        floatingWindow.innerHTML = content;
    }

    function updateFloatingWindow() {
        let storedContent = GM_getValue('storedContent', '没有找到存储的内容。');
        createFloatingWindow(storedContent);
    }

    if (currentURL.includes('lnonl.com')) {
        let title = document.querySelector('title').textContent.trim();

        let resultGroups = [];
        let currentGroup = [];

        let questionElements = document.querySelectorAll('p, span, div');

        questionElements.forEach(function(element) {
            let text = element.textContent.trim();

            let choiceMatch = text.match(/^(\d+)\.\s*([A-Z]+)\s+/);
            if (choiceMatch) {
                let number = choiceMatch[1];
                let answer = choiceMatch[2];

                if (number === '1' && currentGroup.length > 0) {
                    resultGroups.push(currentGroup);
                    currentGroup = [];
                }

                currentGroup.push(`${number}:${answer}`);
            }

            let judgeMatch = text.match(/^(\d+)\.\s*(正确|错误|A正确|B错误)\s+/);
            if (judgeMatch) {
                let number = judgeMatch[1];
                let answer = judgeMatch[2];

                if (number === '1' && currentGroup.length > 0) {
                    resultGroups.push(currentGroup);
                    currentGroup = [];
                }

                currentGroup.push(`${number}:${answer}`);
            }
        });

        if (currentGroup.length > 0) {
            resultGroups.push(currentGroup);
        }

        let content = `<h3>${title}</h3>`;
        let labels = [];

        if (title.includes('上') && title.includes('中') && title.includes('下')) {
            labels = ['上', '中', '下'];
        } else if (title.includes('上') && title.includes('下')) {
            labels = ['上', '下'];
        } else {
            labels = resultGroups.map(() => '答案组');
        }

        const colors = ['#FF6347', '#4682B4', '#32CD32'];
        resultGroups.forEach(function(group, index) {
            const label = labels[index] || '答案组';
            const color = colors[index] || '#000000';
            content += `<p><strong style="color:${color}; font-size:18px;">${label}:</strong> `;
            content += `<span style="color:${color};">${group.join(' ')}</span>`;
            content += `</p>`;
        });

        if (resultGroups.length === 0) {
            content += "<p>未找到题号和答案,请检查选择器或手动查找。</p>";
        }

        GM_setValue('storedContent', content);

        createFloatingWindow(content);

    } else if (currentURL.includes('dtdjzx.gov.cn')) {
        updateFloatingWindow();
        setInterval(updateFloatingWindow, 1000);
    }
})();