Greasy Fork is available in English.
测试
当前为
// ==UserScript==
// @name 保存测试
// @namespace http://tampermonkey.net/
// @version 8.3
// @license MIT
// @description 测试
// @author 从前跟你一样
// @grant unsafeWindow
// @match *://*/*
// @require https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js
// @connect vagrantup.com
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @connect 192.168.10.2
// @connect novelai.net
// @match *://*/*
// @description Save user settings
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
// ==/UserScript==
(function() {
'use strict';
let isDragging = null;
const ICON_URL = 'https://internal-api-drive-stream-sg.larksuite.com/space/api/box/stream/download/v2/cover/QHspbh93roP3BtxYKSelqvZvgGf/?fallback_source=1&height=1280&mount_node_token=A76Yd1rjgo4Bavxu183lE7j7gIh&mount_point=docx_image&policy=equal&width=1280';
// let iconData = GM_getValue('iconData', null);
let iconData = "data:image/gif;base64,R0lGODlhPAA9AOYAACkW5/z7/9fT+ioX5ysY5ywZ5ywa5y4b6C0b5y8c6DAd6DEe6DEf6DIg6DMh6DQi6DUj6DYk6DYl6Tcm6Tgm6Tkn6Too6Tsp6Tsq6Twr6T0s6T4t6T8u6UAv6kAw6kEw6kIx6kMy6kQz6kU06kY16kY26kc36kg46kk560o660s760w86009604+608/61BA61BB61FC7FJD7FNE7FRF7FVG7FZH7FdI7FhJ7FlK7FpL7FtM7VtN7V1P7V5Q7V9Q7WBR7WBS7WFT7WJU7WNV7WRW7mVX7mVY7mZZ7mda7mhb7mlb7mpc7mpd7mxf72te7m1g725h729i73Fl73Jl73Rn73Vp8Hpu8Hpv8Hxw8H5y8YJ38YV78Yd88oh98o+F8pSK85SL85iP85qR9J6V9KKa9aGZ9Kig9ayl9q6n9ry298jD+c7K+uHe/MjE+cnF+eTi/Pf3/v7+/////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AByDDH/BUEC2SqLsAoC6KAygwQAq/LMldAQQURKGBzyTibbEgCOy9ASLEQeDr01AGl0wxZSStdSAJMOz3ItsU27A6w77AzyQEH7Myxuz1rgorYGROCwAFcc6yy15S87XbOcxRgANp2qwx33JsSLogoBiBAiAKMM82vkFnTUgks0BCCNr8JZIp15EU6gsklXqToNzScH3Sy4YP80EmWLSrNyHhd/CCC3hrzPYccrwMAT+uFA8AinQCMMcnG4mECG++EYDEhKgGcrnUhPBA55ykS3JQKf7WvmPfqcgKlQlmsH3JKh4zOA0B+62/AATAa5w8i7POYAYhKZ7Nj+/ruyBfSxhiutA88AJ1BT9LwB6AuvA8Vv4sfJmLwBjMAQAJXKF8n4CEHvUWPHeHrXuc8BwAR1E93c2DN8miBv+KVDhP4U44G6+SIA3JuexM83iPUcELbsSoObshhDsfwqwv+hVVA1IQPQRjEIq4iEAA7" // 下载并保存图标
function downloadAndSaveIcon() {
GM_xmlhttpRequest({
method: 'GET',
url: ICON_URL,
responseType: 'blob',
onload: function(response) {
let reader = new FileReader();
reader.onloadend = function() {
iconData = reader.result;
GM_setValue('iconData', iconData);
createSettingsIcon(iconData);
};
reader.readAsDataURL(response.response);
}
});
}
function createSettingsIcon(iconSrc) {
const icon = document.createElement('img');
icon.src = iconSrc;
icon.style.position = 'fixed';
icon.style.top = '50%';
icon.style.right = '0';
icon.style.transform = 'translateY(-50%)';
icon.style.width = '30px';
icon.style.height = '30px';
icon.style.cursor = 'pointer';
icon.style.zIndex = '9999';
icon.style.transition = 'right 0.3s';
let hideTimeout;
let isDragging = false;
let startX, startY;
function snapToRight() {
icon.style.right = '0';
icon.style.left = 'auto';
clearTimeout(hideTimeout);
hideTimeout = setTimeout(() => {
icon.style.right = '-20px';
}, 2000);
}
function showIcon() {
icon.style.right = '0';
clearTimeout(hideTimeout);
}
function hideIcon() {
hideTimeout = setTimeout(() => {
icon.style.right = '-20px';
}, 1000);
}
// 触摸事件处理
icon.addEventListener('touchstart', handleTouchStart);
icon.addEventListener('touchmove', handleTouchMove);
icon.addEventListener('touchend', handleTouchEnd);
function handleTouchStart(e) {
e.preventDefault();
isDragging = false;
startX = e.touches[0].clientX;
startY = e.touches[0].clientY;
}
function handleTouchMove(e) {
e.preventDefault();
const touchX = e.touches[0].clientX;
const touchY = e.touches[0].clientY;
const deltaX = touchX - startX;
const deltaY = touchY - startY;
if (Math.abs(deltaX) > 5 || Math.abs(deltaY) > 5) {
isDragging = true;
icon.style.right = 'auto';
icon.style.left = `${icon.offsetLeft + deltaX}px`;
icon.style.top = `${icon.offsetTop + deltaY}px`;
}
startX = touchX;
startY = touchY;
}
function handleTouchEnd(e) {
if (!isDragging) {
openSettingsPanel();
} else {
snapToRight();
}
}
// 保留原有的鼠标事件处理
icon.addEventListener('mouseenter', showIcon);
icon.addEventListener('mouseleave', hideIcon);
icon.addEventListener('mousedown', (e) => {
isDragging = false;
startX = e.clientX;
startY = e.clientY;
});
icon.addEventListener('mouseup', (e) => {
if (!isDragging) {
openSettingsPanel();
}
});
makeDraggable(icon, snapToRight);
document.body.appendChild(icon);
hideIcon(); // 初始状态为隐藏
}
function makeDraggable(element, callback) {
let pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
pos3 = e.clientX;
pos4 = e.clientY;
document.addEventListener('mouseup', closeDragElement);
document.addEventListener('mousemove', 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";
element.style.right = 'auto';
}
function closeDragElement() {
document.removeEventListener('mouseup', closeDragElement);
document.removeEventListener('mousemove', elementDrag);
if (callback) callback();
}
element.addEventListener('mousedown', dragMouseDown);
}
// 创建设置面板
function createSettingsPanel() {
const panel = document.createElement('div');
panel.style.position = 'fixed';
panel.style.top = '50%';
panel.style.left = '50%';
panel.style.transform = 'translate(-50%, -50%)';
panel.style.backgroundColor = 'white';
panel.style.padding = '20px';
panel.style.border = '1px solid black';
panel.style.zIndex = '10000';
panel.style.display = 'none';
const input = document.createElement('input');
input.type = 'text';
input.value = GM_getValue('userSetting', '');
const saveButton = document.createElement('button');
saveButton.textContent = '保存设置';
saveButton.onclick = saveSetting;
panel.appendChild(input);
panel.appendChild(saveButton);
document.body.appendChild(panel);
return panel;
}
// 打开设置面板
function openSettingsPanel() {
settingsPanel.style.display = 'block';
}
// 保存设置
function saveSetting() {
const input = settingsPanel.querySelector('input');
GM_setValue('userSetting', input.value);
settingsPanel.style.display = 'none';
}
// 初始化
if (iconData) {
createSettingsIcon(iconData);
} else {
downloadAndSaveIcon();
}
const settingsPanel = createSettingsPanel();
// Your code here...
})();