All Cookie Viewer

Displays cookies for the current page in an overlay

  1. // ==UserScript==
  2. // @name All Cookie Viewer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Displays cookies for the current page in an overlay
  6. // @author
  7. // @match *://*/*
  8. // @grant none
  9. // @license free
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Create overlay element
  16. const overlay = document.createElement('div');
  17. overlay.id = 'cookieOverlay';
  18. overlay.innerHTML = `
  19. <div class="header">
  20. <h3>Cookies for <span class="domain">${location.hostname}</span></h3>
  21. <button class="close">×</button>
  22. </div>
  23. <div class="content"></div>
  24. `;
  25.  
  26. // Create and append styles
  27. const style = document.createElement('style');
  28. style.textContent = `
  29. #cookieOverlay {
  30. position: fixed;
  31. bottom: 10px;
  32. right: 10px;
  33. background: rgba(0, 0, 0, 0.9);
  34. color: white;
  35. padding: 15px;
  36. border-radius: 8px;
  37. max-width: 400px;
  38. max-height: 50vh;
  39. overflow-y: auto;
  40. z-index: 9999;
  41. font-family: Arial, sans-serif;
  42. box-shadow: 0 2px 10px rgba(0,0,0,0.5);
  43. }
  44. #cookieOverlay .header {
  45. display: flex;
  46. justify-content: space-between;
  47. align-items: center;
  48. margin-bottom: 12px;
  49. position: sticky;
  50. top: 0;
  51. background: inherit;
  52. }
  53. #cookieOverlay .close {
  54. background: none;
  55. border: none;
  56. color: white;
  57. font-size: 24px;
  58. cursor: pointer;
  59. padding: 0 8px;
  60. margin-left: 10px;
  61. }
  62. #cookieOverlay .close:hover {
  63. color: #ff4444;
  64. }
  65. #cookieOverlay .content {
  66. font-size: 14px;
  67. line-height: 1.4;
  68. }
  69. #cookieOverlay .cookie-item {
  70. margin: 8px 0;
  71. padding: 6px;
  72. background: rgba(255,255,255,0.1);
  73. border-radius: 4px;
  74. word-break: break-word;
  75. }
  76. #cookieOverlay .domain {
  77. color: #00ff9d;
  78. font-weight: bold;
  79. }
  80. `;
  81. document.body.appendChild(style);
  82. document.body.appendChild(overlay);
  83.  
  84. // Update cookie display function
  85. function updateCookieDisplay() {
  86. const domainSpan = overlay.querySelector('.domain');
  87. const contentDiv = overlay.querySelector('.content');
  88. domainSpan.textContent = location.hostname;
  89. contentDiv.innerHTML = '';
  90.  
  91. const cookies = document.cookie.split('; ').filter(Boolean);
  92. if (cookies.length === 0) {
  93. contentDiv.innerHTML = '<div class="cookie-item">No cookies found</div>';
  94. return;
  95. }
  96.  
  97. cookies.forEach(cookie => {
  98. const [key, ...valueParts] = cookie.split('=');
  99. const value = valueParts.join('=');
  100. const cookieDiv = document.createElement('div');
  101. cookieDiv.className = 'cookie-item';
  102. cookieDiv.innerHTML = `
  103. <strong>${key.trim()}</strong>: <span class="cookie-value">${decodeURIComponent(value)}</span>
  104. `;
  105. contentDiv.appendChild(cookieDiv);
  106. });
  107. }
  108.  
  109. // Event listeners for page changes
  110. const updateEvents = ['load', 'DOMContentLoaded', 'popstate', 'pushState', 'replaceState'];
  111. updateEvents.forEach(event => window.addEventListener(event, updateCookieDisplay));
  112.  
  113. // Monitor history changes for SPAs
  114. const originalPushState = history.pushState;
  115. const originalReplaceState = history.replaceState;
  116.  
  117. history.pushState = function(...args) {
  118. originalPushState.apply(this, args);
  119. window.dispatchEvent(new Event('pushState'));
  120. };
  121.  
  122. history.replaceState = function(...args) {
  123. originalReplaceState.apply(this, args);
  124. window.dispatchEvent(new Event('replaceState'));
  125. };
  126.  
  127. // Close button functionality
  128. overlay.querySelector('.close').addEventListener('click', () => {
  129. overlay.style.display = 'none';
  130. localStorage.setItem('cookieOverlayHidden', 'true');
  131. });
  132.  
  133. // Persist visibility state across page loads
  134. if (localStorage.getItem('cookieOverlayHidden') === 'true') {
  135. overlay.style.display = 'none';
  136. } else {
  137. overlay.style.display = 'block';
  138. }
  139.  
  140. // Initial update
  141. updateCookieDisplay();
  142. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址