// ==UserScript==
// @name 芯位蜜线/教育 自动播放,自动答题
// @namespace https://github.com/poi-yee/51xinweiauto
// @version 0.4.9
// @description 芯位蜜线/教育 自动播放,自动刷作业(题库模式)
// @author PoiYee,Code-dogcreatior
// @match *://*.51xinwei.com/*
// @include *://*.beeline-ai.com/*
// @icon *://*.51xinwei.com/*
// @grant none
// @run-at document-end
// @downloadURL https://update.greasyfork.icu/scripts/490485/%E8%8A%AF%E4%BD%8D%E8%9C%9C%E7%BA%BF%E6%95%99%E8%82%B2%20%E8%87%AA%E5%8A%A8%E6%92%AD%E6%94%BE%EF%BC%8C%E8%87%AA%E5%8A%A8%E7%AD%94%E9%A2%98.user.js
// @updateURL https://update.greasyfork.icu/scripts/490485/%E8%8A%AF%E4%BD%8D%E8%9C%9C%E7%BA%BF%E6%95%99%E8%82%B2%20%E8%87%AA%E5%8A%A8%E6%92%AD%E6%94%BE%EF%BC%8C%E8%87%AA%E5%8A%A8%E7%AD%94%E9%A2%98.meta.js
// ==/UserScript==
(function() {
'use strict';
const state = {
autoClickAndMoveEnabled: false,
autoMuteEnabled: false,
autoAnswerEnabled: false,
agreedTerms: false,
currentQuestionIndex: 0,
allQuestions: [],
remainingQueries: 0
};
let mutationTimeout = null;
let isAllQuestionsAnswered = false;
let currentUrl = window.location.href;
function observeDomChanges() {
const observer = new MutationObserver(mutations => {
// 立即执行自动静音和自动点击下一集,不等待3秒
autoClickAndMove();
autoMuteVideo();
if (mutationTimeout) {
clearTimeout(mutationTimeout);
}
mutationTimeout = setTimeout(() => {
console.log('DOM 3秒内无变化,开始执行操作...');
if (!isAllQuestionsAnswered) {
if (state.autoAnswerEnabled && state.agreedTerms) {
checkForHomework();
}
}
}, 3000);
// Check if URL has changed
if (window.location.href !== currentUrl) {
currentUrl = window.location.href;
clearAnswerRecord();
}
});
observer.observe(document.body, { childList: true, subtree: true });
}
function createControlPanel() {
const controlPanelHTML = `
`;
const controlPanel = document.createElement('div');
controlPanel.innerHTML = controlPanelHTML;
document.body.appendChild(controlPanel);
const windowHeight = window.innerHeight;
const windowWidth = window.innerWidth;
const controlPanelElement = document.getElementById('controlPanel');
controlPanelElement.style.left = `${windowWidth - controlPanelElement.offsetWidth - 20}px`;
controlPanelElement.style.top = `${windowHeight - controlPanelElement.offsetHeight - 20}px`;
makeDraggable(controlPanelElement);
bindControlPanelEvents();
}
function makeDraggable(element) {
let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
element.onmousedown = dragMouseDown;
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
element.style.top = (element.offsetTop - pos2) + "px";
element.style.left = (element.offsetLeft - pos1) + "px";
}
function closeDragElement() {
document.onmouseup = null;
document.onmousemove = null;
}
}
function bindControlPanelEvents() {
document.getElementById('autoClickAndMoveSwitch').addEventListener('change', function() {
state.autoClickAndMoveEnabled = this.checked;
localStorage.setItem('autoClickAndMoveEnabled', state.autoClickAndMoveEnabled);
});
document.getElementById('autoMuteSwitch').addEventListener('change', function() {
state.autoMuteEnabled = this.checked;
localStorage.setItem('autoMuteEnabled', state.autoMuteEnabled);
});
document.getElementById('autoAnswerSwitch').addEventListener('change', function() {
state.autoAnswerEnabled = this.checked;
localStorage.setItem('autoAnswerEnabled', state.autoAnswerEnabled);
updateAnswerPanel();
});
document.getElementById('aboutButton').addEventListener('click', function() {
document.getElementById('aboutPage').style.display = 'block';
startCountdown();
document.getElementById('tokenInput').value = localStorage.getItem('userToken') || '';
});
}
function initializeState() {
state.autoClickAndMoveEnabled = localStorage.getItem('autoClickAndMoveEnabled') === 'true';
state.autoMuteEnabled = localStorage.getItem('autoMuteEnabled') === 'true';
state.autoAnswerEnabled = localStorage.getItem('autoAnswerEnabled') === 'true';
state.agreedTerms = localStorage.getItem('agreedTerms') === 'true';
document.getElementById('autoClickAndMoveSwitch').checked = state.autoClickAndMoveEnabled;
document.getElementById('autoMuteSwitch').checked = state.autoMuteEnabled;
document.getElementById('autoAnswerSwitch').checked = state.autoAnswerEnabled;
if (state.agreedTerms) {
document.getElementById('autoAnswerSwitch').disabled = false;
}
}
function autoClickAndMove() {
if (!state.autoClickAndMoveEnabled) return;
const nextChapterButton = document.querySelector('.button-box > .left');
if (nextChapterButton) {
console.log('等待10秒后点击下一集按钮...');
setTimeout(() => {
nextChapterButton.click();
console.log('已点击下一集按钮。');
}, 10000); // 延迟10秒 (10000 毫秒)
}
}
function autoMuteVideo() {
if (!state.autoMuteEnabled) return;
const videoElement = document.querySelector('video');
const muteButton = document.querySelector('.vjs-mute-control');
if (videoElement && muteButton && muteButton.getAttribute('title') === '静音') {
muteButton.click();
console.log('Video muted.');
}
}
async function fetchAnswerFromAPI(question, options, callback) {
const token = localStorage.getItem('userToken');
if (!token) {
alert('请先在关于页面中填写 token');
return;
}
const queryUrl = `https://tk.enncy.cn/query?token=${token}&title=${encodeURIComponent(question)}`;
setTimeout(() => {
fetch(queryUrl)
.then(res => res.json())
.then(data => {
if (data.code === 1) {
const answer = data.data.answer;
console.log("获取到的答案: ", answer);
state.allQuestions.push({ question, answer });
state.remainingQueries = data.data.times;
updateAnswerPanel();
callback(null, answer);
} else {
console.log("未找到答案,跳转至下一题...");
state.allQuestions.push({ question, answer: "未查询到题目" });
updateAnswerPanel();
callback('no-answer');
}
})
.catch(error => {
console.error("查询接口调用失败: ", error);
alert("查询接口调用失败,停止操作。");
state.allQuestions.push({ question, answer: "接口故障或未查询到题目" });
updateAnswerPanel();
callback('error');
});
}, 2000);
}
function fuzzyMatch(answer, options) {
return options.find(option =>
option && answer.toLowerCase().includes(option.toLowerCase())
);
}
function handleSingleChoice(question, options) {
fetchAnswerFromAPI(question, options, (err, correctAnswer) => {
if (err === 'error') return;
if (err === 'no-answer') {
goToNextQuestion();
return;
}
const matchedOption = fuzzyMatch(correctAnswer, options);
if (matchedOption) {
const index = options.indexOf(matchedOption) + 1;
setTimeout(() => {
document.querySelector(`label:nth-child(${index}) > span.el-radio__label > span.label`).click();
console.log(`已选择匹配的选项: ${matchedOption}`);
goToNextQuestion();
}, 1000);
} else {
console.log('无法匹配答案,跳转至下一题...');
goToNextQuestion();
}
});
}
function handleMultipleChoice(question, options) {
fetchAnswerFromAPI(question, options, (err, correctAnswer) => {
if (err === 'error') return;
if (err === 'no-answer') {
goToNextQuestion();
return;
}
let matchedAny = false;
const answers = correctAnswer.split('\n').map(answer => answer.trim());
answers.forEach(answer => {
const matchedOption = fuzzyMatch(answer, options);
if (matchedOption) {
matchedAny = true;
const index = options.indexOf(matchedOption) + 1;
setTimeout(() => {
document.querySelector(`label:nth-child(${index}) > span.el-checkbox__label > span.label`).click();
console.log(`已选择匹配的选项: ${matchedOption}`);
}, 1000);
}
});
if (matchedAny) {
setTimeout(() => goToNextQuestion(), 1500);
} else {
console.log('无法匹配答案,跳转至下一题...');
goToNextQuestion();
}
});
}
function handleTrueOrFalse(question, options) {
fetchAnswerFromAPI(question, options, (err, correctAnswer) => {
if (err === 'error') return;
if (err === 'no-answer') {
goToNextQuestion();
return;
}
const trueKeywords = ["正确", "对", "t", "true", "yes", "是", "√"];
const falseKeywords = ["错误", "错", "f", "false", "no", "否", "×"];
let isTrue = trueKeywords.some(keyword => correctAnswer.toLowerCase().includes(keyword));
let isFalse = falseKeywords.some(keyword => correctAnswer.toLowerCase().includes(keyword));
if (isTrue && !isFalse) {
selectOption(options, "正确");
} else if (isFalse && !isTrue) {
selectOption(options, "错误");
} else {
console.log('无法判断答案,跳转至下一题...');
goToNextQuestion();
}
});
}
function selectOption(options, targetOption) {
const index = options.findIndex(option =>
option.toLowerCase().includes(targetOption.toLowerCase())
) + 1;
if (index > 0) {
setTimeout(() => {
document.querySelector(`label:nth-child(${index}) > span.el-radio__label > span.label`).click();
console.log(`已选择选项: ${targetOption}`);
goToNextQuestion();
}, 1000);
} else {
console.log(`未找到匹配的${targetOption}选项,跳转至下一题...`);
goToNextQuestion();
}
}
function goToNextQuestion() {
setTimeout(() => {
const nextQuestionButton = document.querySelector("button:nth-child(2)");
if (nextQuestionButton && !nextQuestionButton.disabled) {
nextQuestionButton.click();
console.log('Next question button clicked.');
state.currentQuestionIndex++;
} else {
console.log('未找到下一题按钮或按钮已禁用,可能已到达最后一题。');
isAllQuestionsAnswered = true;
alert('答题完成!请务必核对左侧答案记录与实际选择一致');
}
}, 1000);
}
function checkForHomework() {
if (!state.autoAnswerEnabled || !state.agreedTerms) return;
let question, options;
if (document.querySelector("div.homework-single-selected > div > div > div.content > span")) {
console.log("检测到单选题");
question = document.querySelector("div.homework-single-selected > div > div > div.content > span").textContent;
options = Array.from(document.querySelectorAll("label span.el-radio__label > span.label")).map(opt => opt.textContent);
handleSingleChoice(question, options);
} else if (document.querySelector("div.homework-multiple-selected > div > div > div.content > span")) {
console.log("检测到多选题");
question = document.querySelector("div.homework-multiple-selected > div > div > div.content > span").textContent;
options = Array.from(document.querySelectorAll("label span.el-checkbox__label > span.label")).map(opt => opt.textContent);
handleMultipleChoice(question, options);
} else if (document.querySelector("div.homework-true-or-false > div > div > div.content > span")) {
console.log("检测到判断题");
question = document.querySelector("div.homework-true-or-false > div > div > div.content > span").textContent;
options = Array.from(document.querySelectorAll("label span.el-radio__label > span.label")).map(opt => opt.textContent);
handleTrueOrFalse(question, options);
} else {
console.error("未检测到题目或不支持的题目类型!");
}
}
function createAboutPage() {
const aboutPage = document.createElement('div');
aboutPage.id = 'aboutPage';
aboutPage.style.cssText = 'display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 2000;';
aboutPage.innerHTML = `
Pay ————— ¥5
无人看守的诚信小卖铺
新版芯位已完全无法倍速,故删除
自动下一集,自动静音,视频倍速是免费的
自动答题¥5/人永久使用,谢谢支持😋
自动答题开关开启后建议刷新一次网页再使用,在答题界面稍作等待将自动开始
❗更换为题库方式后答案的正确度严重下降,请一定要再三确认后再提交作业❗
采取诚信授权模式,灵感来源Salt Player ☆*:.o.O(≥▽≤)O.o.:*☆
本人不对题目的正确性做担保,题库也并非本人维护开发收费,请自行判断!
在此处获取token-📖言溪题库
有BUG?GreasyFork反馈罢
GreasyFork
`;
document.body.appendChild(aboutPage);
document.getElementById('closeAboutPageButton').addEventListener('click', function() {
aboutPage.style.display = 'none';
clearInterval(countdownInterval);
const tokenInput = document.getElementById('tokenInput');
localStorage.setItem('userToken', tokenInput.value);
state.agreedTerms = document.getElementById('agreeCheckbox').checked;
localStorage.setItem('agreedTerms', state.agreedTerms);
document.getElementById('autoAnswerSwitch').disabled = !state.agreedTerms;
});
}
let countdownInterval;
function startCountdown() {
clearInterval(countdownInterval);
let timeLeft = 3;
const countdownElement = document.getElementById('countdown');
const agreeCheckbox = document.getElementById('agreeCheckbox');
countdownInterval = setInterval(function() {
if (timeLeft <= 0) {
clearInterval(countdownInterval);
countdownElement.innerHTML = '';
agreeCheckbox.disabled = false;
document.getElementById('closeAboutPageButton').disabled = false;
} else {
countdownElement.innerHTML = '倒计时: ' + timeLeft + ' 秒';
timeLeft--;
}
}, 1000);
}
function createAnswerPanel() {
const answerPanel = document.createElement('div');
answerPanel.id = 'answerPanel';
answerPanel.style.cssText = 'position: fixed; left: 20px; bottom: 20px; width: 300px; height: auto; max-height: 600px; background: white; border: 1px solid black; padding: 10px; overflow-y: auto; z-index: 1000; display: none;';
answerPanel.innerHTML = '答案记录
';
document.body.appendChild(answerPanel);
makeDraggable(answerPanel);
}
function updateAnswerPanel() {
const answerPanel = document.getElementById('answerPanel');
const answerList = document.getElementById('answerList');
const autoAnswerStatus = document.getElementById('autoAnswerStatus');
const remainingQueries = document.getElementById('remainingQueries');
if (!answerPanel || !answerList || !autoAnswerStatus || !remainingQueries) return;
answerPanel.style.display = state.autoAnswerEnabled && isOnHomeworkPage() ? 'block' : 'none';
answerList.innerHTML = '';
state.allQuestions.forEach((item, index) => {
const answerItem = document.createElement('div');
answerItem.innerHTML = `问题 ${index + 1}: ${item.question}
答案: ${item.answer}
`;
answerList.appendChild(answerItem);
});
autoAnswerStatus.innerHTML = `自动答题状态: ${getAutoAnswerStatus()}`;
remainingQueries.innerHTML = `剩余查询次数: ${state.remainingQueries}`;
}
function getAutoAnswerStatus() {
if (mutationTimeout) {
return '请在题目页面静止,在答题完成前请勿点击。记得关闭倍速!!!';
} else if (isAllQuestionsAnswered) {
return '答题完成';
} else {
return '准备中';
}
}
function isOnHomeworkPage() {
return /^https:\/\/www\.beeline-ai\.com\/student\/#\/courseInfo\//.test(window.location.href);
}
function clearAnswerRecord() {
state.allQuestions = [];
state.currentQuestionIndex = 0;
isAllQuestionsAnswered = false;
updateAnswerPanel();
}
window.addEventListener('load', () => {
createControlPanel();
createAboutPage();
createAnswerPanel();
initializeState();
observeDomChanges();
if (!isOnHomeworkPage()) {
console.log('脚本已停止,当前网页不匹配指定的URL。');
return;
}
});
})();