Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Reset Button
- // @match https://console.x.ai/playground/imagine*
- // @grant none
- // @run-at document-end
- // ==/UserScript==
- (function () {
- 'use strict';
- const BTN_ID = 'xai-reset-btn';
- const GAP_PX = 8;
- function resetLimit() {
- try { localStorage.clear(); sessionStorage.clear(); } catch {}
- document.cookie.split(';').forEach(c => {
- const name = c.split('=')[0]?.trim();
- if (!name) return;
- ['.x.ai','console.x.ai','.console.x.ai',''].forEach(d => {
- ['/','/playground','/playground/imagine',''].forEach(p => {
- document.cookie = `${name}=;expires=Thu,01 Jan 1970 00:00:00 GMT;path=${p}${d?';domain='+d:''}`;
- });
- });
- });
- const u = new URL(location.href);
- u.searchParams.set('_r', Date.now());
- location.replace(u.toString());
- }
- function createButton() {
- if (document.getElementById(BTN_ID)) return;
- const btn = document.createElement('button');
- btn.id = BTN_ID;
- btn.type = 'button';
- btn.className =
- 'inline-flex items-center justify-center gap-x-2 rounded-full ' +
- 'text-sm font-medium transition-colors focus-visible:outline-none ' +
- 'focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none ' +
- 'disabled:opacity-50 border border-input text-primary ' +
- 'hover:border-primary/15 shadow-sm hover:bg-overlay-hover ' +
- 'h-9 px-4 py-2 bg-surface-l1 z-[9999] pointer-events-auto';
- btn.innerHTML = `
- <svg class="size-4 shrink-0" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
- <path d="M3 12a9 9 0 1 0 9-9 9 9 0 0 0-9 9Z"/>
- <path d="m15 3-3 3 3 3"/>
- </svg>
- <span class="min-w-[90px]">Сбросить лимит</span>
- `;
- btn.onclick = resetLimit;
- btn.style.opacity = '0';
- btn.style.transition = 'opacity 0.15s ease, transform 0.12s ease';
- btn.style.position = 'fixed';
- btn.style.pointerEvents = 'auto';
- document.body.appendChild(btn);
- positionButton();
- }
- function positionButton() {
- const btn = document.getElementById(BTN_ID);
- if (!btn) return;
- const target = Array.from(document.querySelectorAll('button[aria-haspopup="menu"]')).find(el => {
- const span = el.querySelector('span');
- const chevron = el.querySelector('svg.lucide-chevrons-up-down');
- return span?.textContent?.trim() === 'Image' && chevron;
- });
- if (!target) {
- requestAnimationFrame(positionButton);
- return;
- }
- const rect = target.getBoundingClientRect();
- const btnRect = btn.getBoundingClientRect();
- let left = rect.left + window.scrollX - btnRect.width - GAP_PX;
- let top = rect.top + window.scrollY + ((rect.height - btnRect.height) / 2);
- if (left < 16) left = 16;
- btn.style.left = `${left}px`;
- btn.style.top = `${top}px`;
- btn.style.margin = '0';
- btn.style.transform = 'none';
- if (btn.style.opacity !== '1') {
- setTimeout(() => { btn.style.opacity = '1'; }, 50);
- }
- }
- function init() {
- createButton();
- const mo = new MutationObserver(positionButton);
- mo.observe(document.body, {
- childList: true,
- subtree: true,
- attributes: true,
- attributeFilter: ['class', 'style', 'hidden', 'data-state']
- });
- const throttled = (() => {
- let raf;
- return () => {
- cancelAnimationFrame(raf);
- raf = requestAnimationFrame(positionButton);
- };
- })();
- window.addEventListener('resize', throttled);
- window.addEventListener('scroll', throttled, { passive: true });
- setTimeout(positionButton, 200);
- }
- if (document.readyState !== 'loading') init();
- else document.addEventListener('DOMContentLoaded', init);
- })();
Advertisement
Add Comment
Please, Sign In to add comment