// ==UserScript== // @name Cookie Manager Pro // @namespace http://tampermonkey.net/ // @version 3.0 // @description Advanced cookie management with import/export // @author Your Name // @match *://*/* // @grant none // @downloadURL https://update.greasyfork.icu/scripts/537110/Cookie%20Manager%20Pro.user.js // @updateURL https://update.greasyfork.icu/scripts/537110/Cookie%20Manager%20Pro.meta.js // ==/UserScript== (function() { 'use strict'; // 创建界面元素 const floatBtn = createFloatButton(); const manager = createManagerPanel(); let isDragging = false; // 初始化事件 initDragEvents(); function createFloatButton() { const btn = document.createElement('div'); btn.innerHTML = '🍪'; btn.style.cssText = ` position: fixed; bottom: 20px; right: 20px; width: 40px; height: 40px; background: #2196F3; color: white; border-radius: 50%; text-align: center; line-height: 40px; cursor: move; z-index: 9999; box-shadow: 0 2px 5px rgba(0,0,0,0.3); user-select: none; `; document.body.appendChild(btn); return btn; } function createManagerPanel() { const panel = document.createElement('div'); panel.style.cssText = ` display: none; position: fixed; background: #f5f5f5; border: 1px solid #ddd; border-radius: 8px; width: 85%; max-width: 450px; max-height: 80vh; overflow: hidden; z-index: 9998; padding: 15px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); `; panel.innerHTML = `
Cookie管理 - ${location.hostname}
`; document.body.appendChild(panel); return panel; } // 初始化拖动事件 function initDragEvents() { let startX, startY, initialX, initialY; floatBtn.addEventListener('mousedown', (e) => { isDragging = true; startX = e.clientX; startY = e.clientY; initialX = floatBtn.offsetLeft; initialY = floatBtn.offsetTop; floatBtn.style.transition = 'none'; }); document.addEventListener('mousemove', (e) => { if (!isDragging) return; const dx = e.clientX - startX; const dy = e.clientY - startY; floatBtn.style.left = `${initialX + dx}px`; floatBtn.style.top = `${initialY + dy}px`; adjustPanelPosition(); }); document.addEventListener('mouseup', () => { isDragging = false; floatBtn.style.transition = 'all 0.3s ease'; }); floatBtn.addEventListener('click', () => { if (isDragging) return; manager.style.display = manager.style.display === 'none' ? 'block' : 'none'; adjustPanelPosition(); refreshCookies(); }); } function adjustPanelPosition() { const btnRect = floatBtn.getBoundingClientRect(); const panelWidth = manager.offsetWidth; const viewportWidth = window.innerWidth; let leftPos = btnRect.left - panelWidth/2 + 20; if (leftPos < 10) leftPos = 10; if (leftPos + panelWidth > viewportWidth - 10) { leftPos = viewportWidth - panelWidth - 10; } manager.style.left = `${leftPos}px`; manager.style.top = `${btnRect.top - manager.offsetHeight - 20}px`; } // 刷新Cookie显示 function refreshCookies() { const content = manager.querySelector('#cookieContent'); content.innerHTML = document.cookie.split(';').map(cookie => { const [name, value] = cookie.trim().split('='); return `
${name}
${decodeURIComponent(value)}
`; }).join(''); } // 导出功能 window.exportCookies = function() { const cookies = document.cookie.split(';').map(cookie => { const [name, value] = cookie.trim().split('='); return `${name}=${decodeURIComponent(value)}`; }).join('\n'); const ta = document.createElement('textarea'); ta.value = cookies; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); document.body.removeChild(ta); alert('Cookie已复制到剪贴板'); } // 导入功能 window.importCookies = function() { const input = prompt('粘贴要导入的Cookie(每行一个Cookie):'); if (!input) return; input.split('\n').forEach(line => { const [name, value] = line.split('=').map(s => s.trim()); if (name && value) { setCookie(name, value); } }); refreshCookies(); alert(`成功导入${input.split('\n').length}个Cookie`); } // 公共方法 window.addCookie = function() { const name = document.getElementById('newName').value; const value = document.getElementById('newValue').value; if (name && value) { setCookie(name, value); document.getElementById('newName').value = ''; document.getElementById('newValue').value = ''; } } window.editCookie = function(name) { const currentValue = getCookie(name); const newName = prompt('新名称:', name); const newValue = prompt('新值:', currentValue); if (newName && newValue !== null) { deleteCookie(name); setCookie(newName, newValue); } } window.deleteCookie = function(name) { if (confirm(`确定删除 ${name} 吗?`)) { document.cookie = `${encodeURIComponent(name)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/`; refreshCookies(); } } // Cookie操作函数 function setCookie(name, value, days = 365) { const date = new Date(); date.setTime(date.getTime() + (days * 86400000)); document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; expires=${date.toUTCString()}; path=/`; refreshCookies(); } function getCookie(name) { const cookie = document.cookie .split('; ') .find(row => row.startsWith(`${name}=`)); return cookie ? decodeURIComponent(cookie.split('=')[1]) : null; } })()