获取当前网页的Cookies,并提供一键导出和复制到剪贴板的功能,按钮更小更隐蔽
目前為
// ==UserScript==
// @name 一键导出Cookies
// @namespace http://tampermonkey.net/
// @version 1.0.1
// @description 获取当前网页的Cookies,并提供一键导出和复制到剪贴板的功能,按钮更小更隐蔽
// @author zskfree
// @match http://*/*
// @match https://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_setClipboard
// @license MIT
// ==/UserScript==
(function() {
'use strict';
function getCookies() {
return document.cookie;
}
function copyToClipboard(text) {
if (typeof GM_setClipboard === 'function') {
GM_setClipboard(text);
alert('Cookies已复制到剪贴板!');
} else {
// Fallback for browsers/environments where GM_setClipboard is not available
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.position = 'fixed';
textarea.style.top = '0';
textarea.style.left = '0';
textarea.style.width = '1px';
textarea.style.height = '1px';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
const successful = document.execCommand('copy');
if (successful) {
alert('Cookies已复制到剪贴板!');
} else {
alert('复制失败,请手动复制:\n' + text);
}
} catch (err) {
alert('复制失败,请手动复制:\n' + text);
}
document.body.removeChild(textarea);
}
}
// 创建一个更小、更隐蔽的圆形按钮
const exportButton = document.createElement('button');
exportButton.textContent = '🍪'; // 使用一个饼干图标,更不易察觉
exportButton.title = '导出并复制Cookies'; // 鼠标悬停时显示提示
exportButton.style.position = 'fixed';
exportButton.style.bottom = '15px'; // 离底部稍近
exportButton.style.right = '15px'; // 离右侧稍近
exportButton.style.zIndex = '10000';
exportButton.style.width = '35px'; // 宽度
exportButton.style.height = '35px'; // 高度
exportButton.style.borderRadius = '50%'; // 圆形
exportButton.style.backgroundColor = 'rgba(0, 0, 0, 0.4)'; // 半透明黑色
exportButton.style.color = 'white';
exportButton.style.border = 'none';
exportButton.style.fontSize = '20px'; // 字体大小
exportButton.style.display = 'flex'; // 启用flexbox
exportButton.style.justifyContent = 'center'; // 水平居中
exportButton.style.alignItems = 'center'; // 垂直居中
exportButton.style.cursor = 'pointer';
exportButton.style.boxShadow = '0 2px 5px rgba(0,0,0,0.2)';
exportButton.style.transition = 'background-color 0.3s ease'; // 添加过渡效果
// 鼠标悬停效果
exportButton.addEventListener('mouseenter', () => {
exportButton.style.backgroundColor = 'rgba(0, 0, 0, 0.6)'; // 悬停时颜色变深
});
exportButton.addEventListener('mouseleave', () => {
exportButton.style.backgroundColor = 'rgba(0, 0, 0, 0.4)'; // 鼠标移开时恢复
});
exportButton.addEventListener('click', () => {
const cookies = getCookies();
if (cookies) {
copyToClipboard(cookies);
} else {
alert('当前页面没有Cookies。');
}
});
document.body.appendChild(exportButton);
})();