智能问答学习助手
// ==UserScript==
// @name 智能问答学习助手
// @namespace http://tampermonkey.net/
// @version 1.2
// @description 考试学习必备,在任意网页嵌入一个聊天交互界面,用户可以通过问问题然后得到回复,支持拖拽和悬浮小球展开,支持Tab切换和API Key加密显示
// @match *://*/*
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @connect open.bigmodel.cn
// @author 不会使用使用过程遇到问题请联系q:2430486030 如果获取apikey:https://sa6z03i7sec.feishu.cn/docx/FemzdZ1mnosEgVxRVNocwKEnneY?from=from_copylink
// ==/UserScript==
(function() {
'use strict';
const API_URL = 'https://open.bigmodel.cn/api/paas/v4/chat/completions';
let apiKey = GM_getValue('apiKey', ''); // 从油猴存储获取 API Key
// 创建悬浮小球
function createFloatingBall() {
const ball = document.createElement('div');
ball.id = 'floating-ball';
ball.style.position = 'fixed';
ball.style.bottom = '20px';
ball.style.right = '20px';
ball.style.width = '50px';
ball.style.height = '50px';
ball.style.backgroundColor = '#007bff';
ball.style.borderRadius = '50%';
ball.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
ball.style.zIndex = '2147483647';
ball.style.cursor = 'pointer';
ball.style.display = 'flex';
ball.style.alignItems = 'center';
ball.style.justifyContent = 'center';
ball.style.color = 'white';
ball.style.fontSize = '24px';
ball.textContent = '+';
document.body.appendChild(ball);
makeDraggable(ball);
ball.onclick = toggleChatContainer;
return ball;
}
// 创建聊天界面容器
function createChatContainer() {
const container = document.createElement('div');
container.id = 'chat-container';
container.style.position = 'fixed';
container.style.bottom = '80px';
container.style.right = '20px';
container.style.width = '300px';
container.style.height = '400px';
container.style.backgroundColor = 'white';
container.style.border = '1px solid #ccc';
container.style.borderRadius = '5px';
container.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
container.style.zIndex = '2147483647';
container.style.display = 'none';
container.style.flexDirection = 'column';
container.style.overflow = 'hidden';
document.body.appendChild(container);
return container;
}
// 切换聊天界面显示状态
function toggleChatContainer() {
const container = document.getElementById('chat-container');
if (container.style.display === 'none') {
container.style.display = 'flex';
} else {
container.style.display = 'none';
}
}
// 创建聊天界面
function createChatInterface(container) {
const tabHeader = document.createElement('div');
tabHeader.style.display = 'flex';
tabHeader.style.borderBottom = '1px solid #ccc';
const chatTab = document.createElement('div');
chatTab.textContent = '聊天';
chatTab.style.flex = '1';
chatTab.style.padding = '10px';
chatTab.style.cursor = 'pointer';
chatTab.style.textAlign = 'center';
chatTab.style.backgroundColor = '#007bff';
chatTab.style.color = 'white';
chatTab.onclick = () => switchTab('chat');
tabHeader.appendChild(chatTab);
const aboutTab = document.createElement('div');
aboutTab.textContent = '关于';
aboutTab.style.flex = '1';
aboutTab.style.padding = '10px';
aboutTab.style.cursor = 'pointer';
aboutTab.style.textAlign = 'center';
aboutTab.style.backgroundColor = '#f1f1f1';
aboutTab.style.color = 'black';
aboutTab.onclick = () => switchTab('about');
tabHeader.appendChild(aboutTab);
container.appendChild(tabHeader);
const chatContent = document.createElement('div');
chatContent.id = 'chat-content';
chatContent.style.flex = '1';
chatContent.style.padding = '10px';
chatContent.style.overflowY = 'auto';
chatContent.style.backgroundColor = '#f9f9f9';
container.appendChild(chatContent);
const aboutContent = document.createElement('div');
aboutContent.id = 'about-content';
aboutContent.style.flex = '1';
aboutContent.style.padding = '10px';
aboutContent.style.overflowY = 'auto';
aboutContent.style.backgroundColor = '#f9f9f9';
aboutContent.style.display = 'none';
container.appendChild(aboutContent);
createChatContent(chatContent);
createAboutContent(aboutContent);
}
// 切换Tab
function switchTab(tab) {
const chatTab = document.querySelector('#chat-container div:nth-child(1) div:nth-child(1)');
const aboutTab = document.querySelector('#chat-container div:nth-child(1) div:nth-child(2)');
const chatContent = document.getElementById('chat-content');
const aboutContent = document.getElementById('about-content');
if (tab === 'chat') {
chatTab.style.backgroundColor = '#007bff';
chatTab.style.color = 'white';
aboutTab.style.backgroundColor = '#f1f1f1';
aboutTab.style.color = 'black';
chatContent.style.display = 'block';
aboutContent.style.display = 'none';
} else {
chatTab.style.backgroundColor = '#f1f1f1';
chatTab.style.color = 'black';
aboutTab.style.backgroundColor = '#007bff';
aboutTab.style.color = 'white';
chatContent.style.display = 'none';
aboutContent.style.display = 'block';
}
}
// 创建聊天内容
function createChatContent(container) {
const chatBody = document.createElement('div');
chatBody.id = 'chat-body';
chatBody.style.flex = '1';
chatBody.style.padding = '10px';
chatBody.style.overflowY = 'auto';
chatBody.style.backgroundColor = '#f9f9f9';
container.appendChild(chatBody);
const chatFooter = document.createElement('div');
chatFooter.style.display = 'flex';
chatFooter.style.padding = '10px';
chatFooter.style.borderTop = '1px solid #ccc';
container.appendChild(chatFooter);
const input = document.createElement('input');
input.type = 'text';
input.id = 'chat-input';
input.style.flex = '1';
input.style.padding = '10px';
input.style.border = '1px solid #ccc';
input.style.borderRadius = '5px';
input.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
sendMessage();
}
});
chatFooter.appendChild(input);
const sendButton = document.createElement('button');
sendButton.textContent = '发送';
sendButton.style.marginLeft = '10px';
sendButton.style.padding = '10px';
sendButton.style.border = 'none';
sendButton.style.borderRadius = '5px';
sendButton.style.backgroundColor = '#007bff';
sendButton.style.color = 'white';
sendButton.style.cursor = 'pointer';
sendButton.onclick = sendMessage;
chatFooter.appendChild(sendButton);
}
// 创建关于内容
function createAboutContent(container) {
const helpText = document.createElement('div');
helpText.textContent = '帮助文档:在聊天界面中输入问题并点击发送按钮,您会看到回复显示在聊天界面中。';
helpText.style.marginBottom = '10px';
container.appendChild(helpText);
const apiKeyContainer = document.createElement('div');
apiKeyContainer.style.display = 'flex';
apiKeyContainer.style.alignItems = 'center';
const apiKeyInput = document.createElement('input');
apiKeyInput.type = 'text';
apiKeyInput.id = 'api-key-input';
apiKeyInput.placeholder = '输入API Key';
apiKeyInput.style.flex = '1';
apiKeyInput.style.padding = '10px';
apiKeyInput.style.border = '1px solid #ccc';
apiKeyInput.style.borderRadius = '5px';
apiKeyInput.value = apiKey;
apiKeyInput.onchange = function() {
apiKey = apiKeyInput.value;
GM_setValue('apiKey', apiKey); // 保存 API Key 到油猴存储
apiKeyInput.type = 'password'; // 将输入框类型改为密码
};
apiKeyContainer.appendChild(apiKeyInput);
const toggleButton = document.createElement('button');
toggleButton.textContent = '👁️';
toggleButton.style.marginLeft = '10px';
toggleButton.style.padding = '10px';
toggleButton.style.border = 'none';
toggleButton.style.borderRadius = '5px';
toggleButton.style.backgroundColor = '#007bff';
toggleButton.style.color = 'white';
toggleButton.style.cursor = 'pointer';
toggleButton.onclick = function() {
if (apiKeyInput.type === 'password') {
apiKeyInput.type = 'text';
} else {
apiKeyInput.type = 'password';
}
};
apiKeyContainer.appendChild(toggleButton);
container.appendChild(apiKeyContainer);
if (apiKey) {
apiKeyInput.type = 'password'; // 如果已有 API Key,将输入框类型改为密码
}
// const contactImage = document.createElement('img');
// contactImage.src = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCAFYAVgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAEC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cjNfysE5oA/qnxRilooAQj8K/lYJzX9U/ev5WKADJFf1TEYr+Vmv6p+uaAP5WscZzTTwetf1TkCv5WCc0Af1Tt0r+VojjOcV/VKRkYNAGKAP5WgOM5zX9Uq9KCM0AYGBQAEkDOM1/KyRgZpAcGgkmgBy5xxSEcnmkBxX9U4GBQAjdDxn6V/K3jv+lNBwaXJJoAd05Bpp4PWv6psZr+VgnNAAOv+Nf1Sjk45+tfytA4NBOaAP6piSDiv5WSMGgHFBOTQB/VRRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQB//2Q==';
// contactImage.alt = '联系方式';
// contactImage.style.width = '100%';
// contactImage.style.marginTop = '10px';
// container.appendChild(contactImage);
}
// 发送消息
function sendMessage() {
const input = document.getElementById('chat-input');
const message = input.value.trim();
if (message) {
appendMessage('user', message);
input.value = '';
getReply(message);
}
}
// 获取回复
function getReply(message) {
const chatBody = document.getElementById('chat-body');
const loadingMessage = appendMessage('bot', '正在思考...');
GM_xmlhttpRequest({
method: 'POST',
url: API_URL,
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
data: JSON.stringify({
model: 'glm-4',
messages: [
{
role: 'user',
content: message
}
]
}),
onload: function(response) {
console.log('API response:', response.responseText); // 调试信息
const data = JSON.parse(response.responseText);
if (data && data.choices && data.choices.length > 0) {
loadingMessage.textContent = data.choices[0].message.content;
} else {
loadingMessage.textContent = '抱歉,我无法理解您的问题。';
}
},
onerror: function() {
loadingMessage.textContent = '请求失败,请稍后再试。';
}
});
}
// 添加消息到聊天界面
function appendMessage(role, content) {
const chatBody = document.getElementById('chat-body');
const message = document.createElement('div');
message.style.marginBottom = '10px';
message.style.padding = '10px';
message.style.borderRadius = '5px';
message.style.backgroundColor = role === 'user' ? '#007bff' : '#f1f1f1';
message.style.color = role === 'user' ? 'white' : 'black';
message.style.alignSelf = role === 'user' ? 'flex-end' : 'flex-start';
message.textContent = content;
chatBody.appendChild(message);
chatBody.scrollTop = chatBody.scrollHeight;
return message;
}
// 添加拖动功能
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;
}
}
// 初始化悬浮小球和聊天界面
const floatingBall = createFloatingBall();
const chatContainer = createChatContainer();
createChatInterface(chatContainer);
// 监听鼠标选中事件
document.addEventListener('mouseup', function() {
const selectedText = window.getSelection().toString().trim();
if (selectedText) {
const input = document.getElementById('chat-input');
input.value = selectedText;
}
});
})();