ChatGpt
当前为
// ==UserScript==
// @name 王攀的ChatGpt
// @namespace http://tampermonkey.net/
// @version 1.3
// @description ChatGpt
// @author wangpan
// @match *://*/*
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
let popupOpen = false;
let popupElement = null;
// 创建Chat按钮
function createChatButton() {
const chatButton = document.createElement('button');
chatButton.textContent = 'Chat';
chatButton.style.position = 'fixed';
chatButton.style.bottom = '20px';
chatButton.style.right = '27px';
chatButton.style.width = '40px'; // 设置按钮宽度为 40px
chatButton.style.height = '22px'; // 设置按钮高度为 20px
chatButton.style.zIndex = '9999';
chatButton.style.padding = '10px';
chatButton.style.backgroundColor = '#007bff';
chatButton.style.color = 'white';
chatButton.style.border = 'none';
chatButton.style.borderRadius = '5px';
chatButton.style.cursor = 'pointer';
chatButton.style.display = 'flex';
chatButton.style.justifyContent = 'center'; // 让按钮文字水平居中
chatButton.style.alignItems = 'center'; // 让按钮文字垂直居中
chatButton.addEventListener('click', function() {
if (popupOpen) {
document.body.removeChild(popupElement);
popupOpen = false;
popupElement = null;
} else {
createPopup();
popupOpen = true;
}
});
document.body.appendChild(chatButton);
}
// 创建弹出框
function createPopup() {
const popup = document.createElement('div');
popup.id = 'chatPopup';
popup.style.position = 'fixed';
popup.style.bottom = '20px';
popup.style.right = '20px';
popup.style.width = '360px';
popup.style.height = '650px';
popup.style.backgroundColor = '#f9f9f9';
popup.style.border = '1px solid #ccc';
popup.style.borderRadius = '8px';
popup.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.1)';
popup.style.overflow = 'hidden';
popup.style.zIndex = '999';
const iframe = document.createElement('iframe');
iframe.src = 'https://zhangrui.chat/#/chat';
iframe.style.width = '100%';
iframe.style.height = '100%';
iframe.style.border = 'none';
popup.appendChild(iframe);
document.body.appendChild(popup);
popupElement = popup;
}
// 添加右键菜单
document.addEventListener('contextmenu', function(e) {
e.preventDefault();
// 移除之前存在的右键菜单
const existingContextMenu = document.getElementById('contextMenu');
if (existingContextMenu) {
document.body.removeChild(existingContextMenu);
}
const contextMenu = document.createElement('div');
contextMenu.id = 'contextMenu';
contextMenu.style.position = 'fixed';
contextMenu.style.top = e.clientY + 'px';
contextMenu.style.left = e.clientX + 'px';
contextMenu.style.backgroundColor = '#fff';
contextMenu.style.border = '1px solid #ccc';
contextMenu.style.padding = '5px';
contextMenu.style.zIndex = '9999';
if (popupOpen) {
const closeChatOption = document.createElement('div');
closeChatOption.textContent = '关闭 Chat';
closeChatOption.style.cursor = 'pointer';
closeChatOption.addEventListener('click', function() {
if (popupOpen) {
document.body.removeChild(popupElement);
popupOpen = false;
popupElement = null;
}
document.body.removeChild(contextMenu);
});
contextMenu.appendChild(closeChatOption);
} else {
const openChatOption = document.createElement('div');
openChatOption.textContent = '打开 Chat';
openChatOption.style.cursor = 'pointer';
openChatOption.addEventListener('click', function() {
if (!popupOpen) {
createPopup();
popupOpen = true;
}
document.body.removeChild(contextMenu);
});
contextMenu.appendChild(openChatOption);
}
document.body.appendChild(contextMenu);
});
// 检查当前页面是否是 https://zhangrui.chat/#/chat,如果是则不创建Chat按钮
if (!window.location.href.includes('https://zhangrui.chat/#/chat')) {
createChatButton();
}
})();