Làm Bài Trên EduNext Dễ Hơn Bao Giờ Hết!
当前为
// ==UserScript==
// @name Easy Edunext
// @namespace fsc-Easy-edunext
// @version 1.6
// @description Làm Bài Trên EduNext Dễ Hơn Bao Giờ Hết!
// @author KienDev1234
// @match https://fsc-edunext.fpt.edu.vn/*
// @grant GM.xmlHttpRequest
// @connect generativelanguage.googleapis.com
// ==/UserScript==
(function () {
"use strict";
console.log("Tampermonkey script đã được inject thành công!");
async function autoClickFiveStars() {
while (1) {
const labels = document.querySelectorAll("label");
let foundLabels = 0;
labels.forEach((label) => {
const span = label.querySelector("span.MuiRating-visuallyHidden");
if (span && span.textContent.trim() === "5 Stars") {
console.log(`Tìm thấy label:`, label);
label.click();
foundLabels++;
}
});
console.log(`Đã click vào ${foundLabels} label(s) có chứa "5 Stars".`);
await new Promise((resolve) => setTimeout(resolve, 1000));
addAiButton();
}
}
function addAiButton() {
const buttonContainer = document.querySelector(".button-send-comment");
if (buttonContainer) {
const existingButton = buttonContainer.querySelector(
'button[data-ai-button="true"]'
);
if (!existingButton) {
const aiButton = document.createElement("button");
aiButton.className =
"MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeSmall MuiButton-containedSizeSmall edu-button css-1n61s5c";
aiButton.setAttribute("data-ai-button", "true");
aiButton.textContent = "Làm Bằng AI";
aiButton.style.marginLeft = "10px";
aiButton.addEventListener("click", handleAiButtonClick);
buttonContainer.appendChild(aiButton);
console.log('Đã thêm nút "Làm Bằng AI" vào div .button-send-comment');
}
}
}
async function handleAiButtonClick() {
const aiButton = document.querySelector('button[data-ai-button="true"]');
if (aiButton) {
aiButton.textContent = "Đang tạo...";
const contentDiv = document.querySelector(".wrap-entry-lesson-content");
if (contentDiv) {
const styledDiv = contentDiv.querySelector(".styled");
const pText = styledDiv?.querySelector("p")?.textContent || "";
if (pText) {
console.log("Đã lấy nội dung:", pText);
await sendCurlRequest(pText, aiButton);
}
}
}
}
async function sendCurlRequest(content, aiButton) {
const url =
"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-001:generateContent?key=AIzaSyA1hn2RpP0rzLJuqUYTMDzsr_IFL8H41d8";
const payload = {
contents: [
{
parts: [
{
text: content,
},
],
},
],
};
try {
const response = await new Promise((resolve, reject) => {
GM.xmlHttpRequest({
method: "POST",
url: url,
headers: { "Content-Type": "application/json" },
data: JSON.stringify(payload),
responseType: "json",
onload: resolve,
onerror: reject,
});
});
console.log("Full response:", response);
console.log("Response Text:", response.responseText);
const data = response.response;
if (data && data.candidates && data.candidates.length > 0) {
const generatedContent =
data.candidates[0].content.parts[0].text || "Không có nội dung từ AI";
const formattedContent = generatedContent;
const contentDiv = document.querySelector(".wrap-entry-lesson-content");
const styledDiv = contentDiv.querySelector(".styled");
let textarea = styledDiv.querySelector("textarea");
if (!textarea) {
const h4 = document.createElement("h4");
const label = document.createElement("label");
label.setAttribute("for", "w3review");
label.textContent = "Bạn Bôi Đen Đáp Án Rồi Thả Vào Editor";
h4.appendChild(label);
textarea = document.createElement("textarea");
textarea.id = "w3review";
textarea.name = "w3review";
textarea.rows = 10;
textarea.cols = 50;
textarea.setAttribute("readonly", "true");
const pTag = document.createElement("p");
pTag.textContent = "Làm theo hướng dẫn để sao chép và dán vào Editor.";
const selectButton = document.createElement("button");
selectButton.textContent = "Bôi Đen Đáp Án";
selectButton.className =
"MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeSmall MuiButton-containedSizeSmall edu-button css-1n61s5c";
selectButton.style.marginTop = "10px";
selectButton.addEventListener("click", () => {
textarea.select();
});
styledDiv.appendChild(h4);
styledDiv.appendChild(textarea);
styledDiv.appendChild(pTag);
styledDiv.appendChild(selectButton);
}
textarea.textContent = formattedContent;
} else {
console.error("Không có dữ liệu từ API!");
}
aiButton.textContent = "Làm Bằng AI";
} catch (error) {
console.error("Lỗi khi gửi yêu cầu:", error);
aiButton.textContent = "Làm Bằng AI";
}
}
autoClickFiveStars();
})();