// ==UserScript== // @name Cookies切换 // @namespace https://tampermonkey.net/ // @version 1.0 // @description 掌控你的cookie吧~~ // @author Cheney & Gemini // @match http://*/* // @match https://*/* // @require https://code.jquery.com/jquery-3.6.0.min.js // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAAXNSR0IArs4c6QAAArlJREFUSEullktoE0EYx//ftEKxD2uVFitW8AH25AssKIiCvVQQsaAeeiiKBzWZRMylXmwvnipkZ6OUoniwh6BexMdBPYiIggcVRS1YwQdUbKWRIhLbuJ+d3abNdjfJNlmYw+73+H0z859vllDgYSlbAMQAVJNSxwv5FrORnwNHo/VgvgDmkzn2PlKqt1jCfHYPiKPRLbCsAQBtniDL2kuJxONSYC4Qh0IHIcRVAA2+yZiryDT/lgXiUKgZQjwBsN43EdFLMoztpUB0zNyMWMpLAE5lE70Zz+Dy6z8YaK9zPjGPkGluLAvEUnYAuJebpFaN2a89bdU411btmIgOk2HcLAVmz4ilvALAJV/PjLLZS4QRR6OrYFnvAdQvotIkgM+kVE/QGGIpTwNIBA3I8RsmpVqDxmmQlvOxoAE5fmkIsY7i8e9BYokjkadg3hXE2ccncLfQoHEwrywRpMM8MI7FGqm/35Ht7OMBfZ38Z5ta6ipc7NHfFtpvpbC2tgL3Oz26+QTmb7NHYA+EOEPxeHwhyLV0+vy0NlTiRZe7C32YyGDH0IRdwLvuFcUWYBjMnWSaWs0OnyORa2Duzn7YnZxAzRLhVzVejWXQtFSguUYUA2l7Gun0Ghoc/OmApNSt/3yQyCA+qbSF5VWuQvocUCi0CUK8BVAZJFEhn0O3f+Hhlyl7aRfs8dlsC7oOoKtc0IkHk3g2Oo2hjmXY2jhX9w9MT7c6oHB4P4julgvKE99LSvXNXxORSBLMRwrBFikGneoOKXXA3qPcxCwl5wMtUt46zSgptXpO3i5QOLwZRI9mmqynU0xOMfbdSGFbU+X8ZZivKqLnZBg7XQfWz7csyRPFyDAuLszr+7uVI5CjAPQoJv0MAL3HSTJN103tu3S+s3POmYZtmB3Z/4aPM0dixB6WlaREYriQkP4DhYT2pc+2+CQAAAAASUVORK5CYII= // @grant GM_cookie // @grant GM_getValue // @grant GM_setValue // @grant GM_setClipboard // @license MIT // @downloadURL none // ==/UserScript== (function () { "use strict"; const hostname = location.hostname; const domain = hostname; let cookiesConfig = GM_getValue("cookiesConfig", {}); const mainClassName = `cookieSwitchWrapper_${randomStr()}`; const LIVE_COOKIES_OPTION_VALUE = "__LIVE_COOKIES__"; const LIVE_COOKIES_OPTION_TEXT = "当前Cookie"; function randomStr() { const letters = "abcdefghijklmnopqrstuvwxyz"; let str = ""; for (let i = 0; i < 6; i++) { str += letters[Math.floor(Math.random() * 26)]; } return str; } function closePannel() { $(`.${mainClassName}`).css("transform", "translateX(110%)"); } /** * Checks if the table width exceeds the panel width and applies word wrapping to the Name column if necessary. */ function checkAndAdjustNameColumnWrap() { setTimeout(() => { const $mainDiv = $(`.${mainClassName}`); if (!$mainDiv.length) return; const $table = $mainDiv.find('.cookieTable'); if (!$table.length || $table.find('tbody tr').length === 0) return; const $nameColumn = $table.find('th:first-child, td.cookie-name'); // Temporarily remove the class to measure the table's natural width $nameColumn.removeClass('force-wrap-name'); if ($table.outerWidth() > $mainDiv.width()) { $nameColumn.addClass('force-wrap-name'); } }, 100); // Use a short delay to ensure DOM is updated before measuring } function createStyle() { const css = ` .${mainClassName} { position: fixed; z-index: 999999; top: 0; right: 0; width: 1000px; height: 100%; padding: 10px; transition: transform 200ms; transform: translateX(110%); background-color: #fff !important; color: #000 !important; box-shadow: -10px 0 10px #ddd; overflow: auto; } .${mainClassName} .topWrapper { display: flex; justify-content: space-between; align-items: center; margin-bottom:10px; } .${mainClassName} .topWrapper span { color: #000 !important; } .${mainClassName} select, .${mainClassName} input, .${mainClassName} button { background-color: #fff !important; color: #000 !important; border: 1px solid #ccc !important; padding: 5px 8px !important; border-radius: 3px !important; margin-left: 5px !important; } .${mainClassName} select { min-width: 180px; } .${mainClassName} .titleInput { font-size: 14px; outline: none; flex-grow: 1; margin-left:10px !important; } .${mainClassName} .topWrapper button { margin-left: 10px !important; } .${mainClassName} .delete-setting-btn { background-color: #ffdddd !important; border-color: #ffaaaa !important;} .${mainClassName} .cookieTable { width: 100%; margin-top: 15px; border-collapse: collapse; } .${mainClassName} .cookieTable thead { background-color: #f0f0f0 !important; } .${mainClassName} .cookieTable th, .${mainClassName} .cookieTable td { font-size: 12px; padding: 6px; text-align: center; border: 1px solid #ddd !important; color: #000 !important; } .${mainClassName} .cookieTable th { font-size: 13px; white-space: nowrap; background-color: #e9e9e9 !important; } .${mainClassName} .cookieTable tbody tr:nth-child(odd) { background-color: #f9f9f9 !important; } .${mainClassName} .cookieTable tbody tr:hover { background-color: #f1f1f1 !important; } .${mainClassName} .cookieTable td.cookie-name { text-align: left; } .${mainClassName} .cookieTable td.cookie-value { text-align: left; word-break: break-all; } .${mainClassName} .cookieTable textarea { width: 100%; box-sizing: border-box; padding: 2px !important; border: 1px solid #eee !important; outline: none; color: #000 !important; background-color: #FFFFFF !important; font-family: inherit; font-size: inherit; line-height: inherit; resize: none; overflow-y: hidden; vertical-align: top; } .${mainClassName} .cookieTable button { word-break: keep-all; padding: 3px 6px !important; font-size:11px !important; } .${mainClassName} .btnWrapper { display: flex; justify-content: center; margin-top: 20px; } .${mainClassName} .btnWrapper button { margin-left: 15px !important; padding: 8px 20px !important; cursor: pointer; border: 1px solid #ddd;border-radius: 4px;background-color: #fff;&:hover {background-color: #f1f1f1; } #cookieBtn { background-color: #FF6E6E !important; } /* Style to force word wrapping on the name column when needed */ .${mainClassName} .force-wrap-name { white-space: normal !important; word-break: break-all !important; } `; return $("").text(css); } function createCookieBtn() { const cookieBtn = $( `
` ) .css({ width: "26px", height: "26px", position: "fixed", right: "10px", bottom: "40px", "z-index": 99999, cursor: "pointer", "user-select": "none", "box-shadow": "-4px 4px 8px #ddd", "border-radius": "50%", opacity: "0.9", }) .click(() => { $(`.${mainClassName}`).css("transform", "translateX(0)"); checkAndAdjustNameColumnWrap(); }); return cookieBtn; } function updateDeleteButtonVisibility() { const selectedValue = $(`.${mainClassName} .title-select`).val(); const deleteBtn = $(`.${mainClassName} .delete-setting-btn`); if (selectedValue && selectedValue !== LIVE_COOKIES_OPTION_VALUE && cookiesConfig[domain] && cookiesConfig[domain].some(s => s.title === selectedValue)) { deleteBtn.show(); } else { deleteBtn.hide(); } } function refreshSettingsUI(selectThisValue = null) { const titleSelect = $(`.${mainClassName} .title-select`); const titleInput = $(`.${mainClassName} .titleInput`); titleSelect.empty(); // Always add Live Cookies option first titleSelect.append($("