Guest User

Cookie Reset

a guest
Mar 21st, 2026
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Reset Button
  3. // @match https://console.x.ai/playground/imagine*
  4. // @grant none
  5. // @run-at document-end
  6. // ==/UserScript==
  7.  
  8. (function () {
  9. 'use strict';
  10.  
  11. const BTN_ID = 'xai-reset-btn';
  12. const GAP_PX = 8;
  13.  
  14. function resetLimit() {
  15. try { localStorage.clear(); sessionStorage.clear(); } catch {}
  16.  
  17. document.cookie.split(';').forEach(c => {
  18. const name = c.split('=')[0]?.trim();
  19. if (!name) return;
  20. ['.x.ai','console.x.ai','.console.x.ai',''].forEach(d => {
  21. ['/','/playground','/playground/imagine',''].forEach(p => {
  22. document.cookie = `${name}=;expires=Thu,01 Jan 1970 00:00:00 GMT;path=${p}${d?';domain='+d:''}`;
  23. });
  24. });
  25. });
  26.  
  27. const u = new URL(location.href);
  28. u.searchParams.set('_r', Date.now());
  29. location.replace(u.toString());
  30. }
  31.  
  32. function createButton() {
  33. if (document.getElementById(BTN_ID)) return;
  34.  
  35. const btn = document.createElement('button');
  36. btn.id = BTN_ID;
  37. btn.type = 'button';
  38.  
  39. btn.className =
  40. 'inline-flex items-center justify-center gap-x-2 rounded-full ' +
  41. 'text-sm font-medium transition-colors focus-visible:outline-none ' +
  42. 'focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none ' +
  43. 'disabled:opacity-50 border border-input text-primary ' +
  44. 'hover:border-primary/15 shadow-sm hover:bg-overlay-hover ' +
  45. 'h-9 px-4 py-2 bg-surface-l1 z-[9999] pointer-events-auto';
  46.  
  47. btn.innerHTML = `
  48. <svg class="size-4 shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  49. <path d="M3 12a9 9 0 1 0 9-9 9 9 0 0 0-9 9Z"/>
  50. <path d="m15 3-3 3 3 3"/>
  51. </svg>
  52. <span class="min-w-[90px]">Сбросить лимит</span>
  53. `;
  54.  
  55. btn.onclick = resetLimit;
  56. btn.style.opacity = '0';
  57. btn.style.transition = 'opacity 0.15s ease, transform 0.12s ease';
  58. btn.style.position = 'fixed';
  59. btn.style.pointerEvents = 'auto';
  60.  
  61. document.body.appendChild(btn);
  62. positionButton();
  63. }
  64.  
  65. function positionButton() {
  66. const btn = document.getElementById(BTN_ID);
  67. if (!btn) return;
  68.  
  69. const target = Array.from(document.querySelectorAll('button[aria-haspopup="menu"]')).find(el => {
  70. const span = el.querySelector('span');
  71. const chevron = el.querySelector('svg.lucide-chevrons-up-down');
  72. return span?.textContent?.trim() === 'Image' && chevron;
  73. });
  74.  
  75. if (!target) {
  76. requestAnimationFrame(positionButton);
  77. return;
  78. }
  79.  
  80. const rect = target.getBoundingClientRect();
  81. const btnRect = btn.getBoundingClientRect();
  82.  
  83. let left = rect.left + window.scrollX - btnRect.width - GAP_PX;
  84. let top = rect.top + window.scrollY + ((rect.height - btnRect.height) / 2);
  85.  
  86. if (left < 16) left = 16;
  87.  
  88. btn.style.left = `${left}px`;
  89. btn.style.top = `${top}px`;
  90. btn.style.margin = '0';
  91. btn.style.transform = 'none';
  92.  
  93. if (btn.style.opacity !== '1') {
  94. setTimeout(() => { btn.style.opacity = '1'; }, 50);
  95. }
  96. }
  97.  
  98. function init() {
  99. createButton();
  100.  
  101. const mo = new MutationObserver(positionButton);
  102. mo.observe(document.body, {
  103. childList: true,
  104. subtree: true,
  105. attributes: true,
  106. attributeFilter: ['class', 'style', 'hidden', 'data-state']
  107. });
  108.  
  109. const throttled = (() => {
  110. let raf;
  111. return () => {
  112. cancelAnimationFrame(raf);
  113. raf = requestAnimationFrame(positionButton);
  114. };
  115. })();
  116.  
  117. window.addEventListener('resize', throttled);
  118. window.addEventListener('scroll', throttled, { passive: true });
  119.  
  120. setTimeout(positionButton, 200);
  121. }
  122.  
  123. if (document.readyState !== 'loading') init();
  124. else document.addEventListener('DOMContentLoaded', init);
  125. })();
Advertisement
Add Comment
Please, Sign In to add comment