// ==UserScript== // @name Retry Helper // @namespace https://github.com/KanbanTrainer/tampermonkey // @version 2.0.0 // @description Prompts before retrying Retry or Try again buttons, with optional continuous retry for the current tab. // @match *://*/* // @grant none // @run-at document-idle // @updateURL https://raw.githubusercontent.com/KanbanTrainer/tampermonkey/main/auto-retry.user.js // @downloadURL https://raw.githubusercontent.com/KanbanTrainer/tampermonkey/main/auto-retry.user.js // ==/UserScript== (() => { 'use strict'; const RETRY_INTERVAL_SECONDS = 30; const CONTINUOUS_RETRY_KEY = 'tampermonkey-retry-helper-continuous'; const RETRY_LABELS = new Set(['retry', 'try again']); let retryWasPresent = false; let dismissedForCurrentAppearance = false; let secondsRemaining = RETRY_INTERVAL_SECONDS; function isContinuousRetryEnabled() { try { return sessionStorage.getItem(CONTINUOUS_RETRY_KEY) === 'true'; } catch { return false; } } function setContinuousRetryEnabled(enabled) { try { if (enabled) { sessionStorage.setItem(CONTINUOUS_RETRY_KEY, 'true'); } else { sessionStorage.removeItem(CONTINUOUS_RETRY_KEY); } } catch { // Keep working even when sessionStorage is unavailable. } } function normalizedButtonText(button) { return (button.innerText || button.textContent || '') .replace(/\s+/g, ' ') .trim() .toLowerCase(); } function findRetryButtons() { return [...document.querySelectorAll('button')].filter(button => !button.disabled && button.getAttribute('aria-disabled') !== 'true' && RETRY_LABELS.has(normalizedButtonText(button)) ); } function showToast(message) { const toast = document.createElement('div'); toast.textContent = message; Object.assign(toast.style, { position: 'fixed', right: '16px', bottom: '72px', zIndex: '2147483647', padding: '8px 11px', borderRadius: '9px', background: 'rgba(25, 25, 25, 0.94)', color: '#fff', fontFamily: 'system-ui, sans-serif', fontSize: '13px', fontWeight: '600', boxShadow: '0 4px 18px rgba(0, 0, 0, 0.25)', backdropFilter: 'blur(8px)', opacity: '0', transform: 'translateY(6px)', transition: 'opacity 150ms ease, transform 150ms ease', pointerEvents: 'none', }); document.documentElement.appendChild(toast); requestAnimationFrame(() => { toast.style.opacity = '1'; toast.style.transform = 'translateY(0)'; }); setTimeout(() => { toast.style.opacity = '0'; toast.style.transform = 'translateY(6px)'; setTimeout(() => toast.remove(), 200); }, 2200); } function clickRetryButtons(buttons, message = 'Retried') { for (const button of buttons) { button.click(); } if (buttons.length > 0) { showToast(buttons.length === 1 ? message : `${message} ${buttons.length} items`); } } function createControl() { const host = document.createElement('div'); host.id = 'tampermonkey-retry-helper'; Object.assign(host.style, { all: 'initial', position: 'fixed', right: '16px', bottom: '16px', zIndex: '2147483647', display: 'none', }); const shadow = host.attachShadow({ mode: 'open' }); shadow.innerHTML = `