// ==UserScript== // @name Search Engine Quick Switcher // @namespace https://github.com/quantavil // @version 3.8 // @description floating Search Engine Quick Switcher // @author quantavil // @license MIT // @match *://search.brave.com/search?* // @match *://yandex.com/search?* // @match *://yandex.ru/search?* // @match *://www.bing.com/search?* // @match *://duckduckgo.com/?* // @match *://www.google.com/search?* // @match *://www.youtube.com/results?* // @match *://m.youtube.com/results?* // @grant none // @run-at document-idle // @downloadURL none // ==/UserScript== (function () { 'use strict'; const PREF_KEY = 'seqs_prefs_v1'; const ENGINES = [ { key: 'brave', host: 'search.brave.com', param: 'q', url: 'https://search.brave.com/search?q=', label: 'Brave', icon: '' }, { key: 'yandex', host: 'yandex.', param: 'text', url: 'https://yandex.com/search?text=', label: 'Yandex', icon: '' }, { key: 'bing', host: 'bing.com', param: 'q', url: 'https://www.bing.com/search?q=', label: 'Bing', icon: '' }, { key: 'ddg', host: 'duckduckgo.com', param: 'q', url: 'https://duckduckgo.com/?q=', label: 'DuckDuckGo', icon: '' }, { key: 'youtube', host: 'youtube.com', param: 'search_query', url: 'https://www.youtube.com/results?search_query=', label: 'YouTube', icon: '' }, { key: 'google', host: 'google.com', param: 'q', url: 'https://www.google.com/search?q=', label: 'Google', // Official multi-color "G" icon: '' } ]; const ENGINE_MAP = new Map(ENGINES.map(e => [e.key, e])); const getDefaultPrefs = () => ({ order: ENGINES.map(e => e.key), disabled: [] }); const loadPrefs = () => { try { const raw = localStorage.getItem(PREF_KEY); if (!raw) return getDefaultPrefs(); const parsed = JSON.parse(raw) || {}; const known = new Set(ENGINES.map(e => e.key)); let order = Array.isArray(parsed.order) ? parsed.order.filter(k => known.has(k)) : []; for (const k of ENGINES.map(e => e.key)) if (!order.includes(k)) order.push(k); const disabled = Array.isArray(parsed.disabled) ? parsed.disabled.filter(k => known.has(k)) : []; return { order, disabled }; } catch { return getDefaultPrefs(); } }; const savePrefs = (prefs) => { localStorage.setItem(PREF_KEY, JSON.stringify(prefs)); }; const getOrderedEngines = (prefs) => prefs.order.map(k => ENGINE_MAP.get(k)).filter(Boolean); const getEnabledEngines = (prefs) => getOrderedEngines(prefs).filter(e => !prefs.disabled.includes(e.key)); const getCurrentEngine = () => { const { hostname, searchParams } = new URL(location.href); for (const engine of ENGINES) { if (hostname.includes(engine.host)) { const query = searchParams.get(engine.param)?.trim(); return query ? { engine, query } : null; } } return null; }; const current = getCurrentEngine(); if (!current) return; const switchTo = (engine) => { if (engine.key !== current.engine.key) { location.href = engine.url + encodeURIComponent(current.query); } }; const style = document.createElement('style'); style.textContent = ` :root { --seqs-width: 60px; --seqs-bg-start: #1a1a1a; --seqs-bg-end: #0d0d0d; --seqs-border: rgba(255,255,255,.08); --seqs-border-hover: rgba(255,255,255,.2); --seqs-btn-bg: rgba(255,255,255,.04); --seqs-btn-hover: rgba(255,255,255,.08); --seqs-shadow: rgba(0,0,0,.6); --seqs-accent: #4285f4; --seqs-ease: cubic-bezier(.4,0,.2,1); } .seqs-wrap { position: fixed; top: 50%; left: 0; transform: translate(calc(-1 * var(--seqs-width)), -50%); z-index: 999999; transition: transform .3s var(--seqs-ease); } .seqs-wrap:hover { transform: translate(0, -50%); } .seqs-panel { width: var(--seqs-width); background: linear-gradient(135deg, var(--seqs-bg-start), var(--seqs-bg-end)); border-radius: 0 12px 12px 0; box-shadow: 4px 0 24px var(--seqs-shadow); padding: 8px 0; border: 1px solid var(--seqs-border); border-left: none; } .seqs-btn { display: grid; place-items: center; width: 44px; height: 44px; margin: 6px auto; background: var(--seqs-btn-bg); border: 1px solid var(--seqs-border); border-radius: 10px; cursor: pointer; transition: all .2s var(--seqs-ease); padding: 0; } .seqs-btn:hover { background: var(--seqs-btn-hover); border-color: var(--seqs-border-hover); transform: scale(1.08); } .seqs-btn.current { background: rgba(66,133,244,.15); border-color: var(--seqs-accent); box-shadow: 0 0 12px rgba(66,133,244,.3); } .seqs-btn.settings { background: rgba(255,255,255,.02); } .seqs-btn.settings:hover { background: rgba(255,255,255,.08); } .seqs-icon-host { width: 24px; height: 24px; display: block; pointer-events: none; } .seqs-handle { position: absolute; top: 50%; right: -28px; transform: translateY(-50%); width: 28px; height: 56px; background: linear-gradient(135deg, #2a2a2a, #1a1a1a); border-radius: 0 8px 8px 0; box-shadow: 2px 0 16px var(--seqs-shadow); display: grid; place-items: center; cursor: pointer; transition: all .2s var(--seqs-ease); border: 1px solid var(--seqs-border); border-left: none; } .seqs-handle:hover { width: 32px; background: linear-gradient(135deg, #333, #222); border-color: var(--seqs-border-hover); } .seqs-handle svg { width: 16px; height: 16px; fill: rgba(255,255,255,.7); transition: fill .2s var(--seqs-ease); } .seqs-handle:hover svg { fill: rgba(255,255,255,.9); } /* Settings modal */ .seqs-settings-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 9999999; display: grid; place-items: center; } .seqs-settings { width: min(520px, calc(100vw - 32px)); background: #121212; color: #fff; border: 1px solid var(--seqs-border); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.6); overflow: hidden; font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; } .seqs-settings-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: linear-gradient(135deg, #1b1b1b, #151515); border-bottom: 1px solid var(--seqs-border); } .seqs-settings-header h3 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: .2px; } .seqs-settings-close { background: transparent; border: 1px solid var(--seqs-border); color: #ddd; width: 28px; height: 28px; border-radius: 8px; cursor: pointer; } .seqs-settings-body { padding: 12px 16px; max-height: min(70vh, 560px); overflow: auto; } .seqs-hint { font-size: 12px; color: #bbb; margin: 0 0 10px 0; } .seqs-engine-list { margin: 0; padding: 0; list-style: none; } .seqs-engine-row { position: relative; display: grid; grid-template-columns: 1fr auto auto; /* info | toggle | drag */ gap: 10px; align-items: center; padding: 10px; border: 1px solid var(--seqs-border); border-radius: 10px; background: rgba(255,255,255,.02); margin-bottom: 8px; } .seqs-engine-row.drop-before::before, .seqs-engine-row.drop-after::after { content: ''; position: absolute; left: 8px; right: 8px; height: 2px; background: var(--seqs-accent); } .seqs-engine-row.drop-before::before { top: -1px; } .seqs-engine-row.drop-after::after { bottom: -1px; } .seqs-engine-info { display: flex; align-items: center; gap: 10px; min-width: 0; } .seqs-engine-name { font-size: 14px; font-weight: 600; } .seqs-engine-badge { font-size: 12px; color: #bbb; padding: 2px 6px; border: 1px solid var(--seqs-border); border-radius: 999px; margin-left: 6px; } .seqs-toggle { display: inline-flex; align-items: center; gap: 6px; color: #ddd; font-size: 13px; } .seqs-toggle input { accent-color: var(--seqs-accent); } .seqs-drag { display: inline-grid; place-items: center; width: 28px; height: 28px; border: 1px solid var(--seqs-border); border-radius: 6px; background: var(--seqs-btn-bg); cursor: grab; user-select: none; } .seqs-drag:hover { border-color: var(--seqs-border-hover); background: var(--seqs-btn-hover); } .seqs-drag:active { cursor: grabbing; } .seqs-settings-actions { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--seqs-border); background: #101010; } .seqs-settings-actions .spacer { flex: 1; } .seqs-settings-actions button { background: var(--seqs-btn-bg); color: #eee; border: 1px solid var(--seqs-border); border-radius: 8px; padding: 8px 12px; cursor: pointer; transition: all .2s var(--seqs-ease); } .seqs-settings-actions button:hover { background: var(--seqs-btn-hover); border-color: var(--seqs-border-hover); } .seqs-primary { border-color: var(--seqs-accent); } `; document.head.appendChild(style); const createIcon = (svgMarkup) => { const host = document.createElement('span'); host.className = 'seqs-icon-host'; const shadow = host.attachShadow({ mode: 'open' }); const css = document.createElement('style'); css.textContent = `svg{width:100%;height:100%;display:block;overflow:hidden;}`; shadow.appendChild(css); const tpl = document.createElement('template'); tpl.innerHTML = svgMarkup.trim(); const svg = tpl.content.firstElementChild; if (svg?.tagName.toLowerCase() === 'svg') { const w = parseFloat(svg.getAttribute('width')) || 64; const h = parseFloat(svg.getAttribute('height')) || 64; svg.removeAttribute('width'); svg.removeAttribute('height'); if (!svg.hasAttribute('viewBox')) { svg.setAttribute('viewBox', `0 0 ${w} ${h}`); } svg.setAttribute('preserveAspectRatio', 'xMidYMid meet'); shadow.appendChild(svg); } else { shadow.appendChild(document.createTextNode('⚠️')); } return host; }; const wrap = document.createElement('div'); wrap.className = 'seqs-wrap'; wrap.setAttribute('role', 'navigation'); wrap.setAttribute('aria-label', 'Search engine switcher'); const panel = document.createElement('div'); panel.className = 'seqs-panel'; const handle = document.createElement('div'); handle.className = 'seqs-handle'; handle.title = 'Cycle to next engine'; handle.innerHTML = ``; const buildPanel = () => { const prefs = loadPrefs(); const enabled = getEnabledEngines(prefs); panel.innerHTML = ''; // Ensure current engine is visible even if disabled in settings const display = enabled.slice(); if (!display.some(e => e.key === current.engine.key)) { display.unshift(current.engine); } for (const engine of display) { const btn = document.createElement('button'); btn.className = 'seqs-btn' + (engine.key === current.engine.key ? ' current' : ''); btn.type = 'button'; btn.title = engine.label; btn.appendChild(createIcon(engine.icon)); btn.onclick = () => switchTo(engine); panel.appendChild(btn); } // Settings button with fixed gear icon const settingsBtn = document.createElement('button'); settingsBtn.className = 'seqs-btn settings'; settingsBtn.type = 'button'; settingsBtn.title = 'Settings'; settingsBtn.innerHTML = ``; const sIconHost = settingsBtn.querySelector('.seqs-icon-host'); const sShadow = sIconHost.attachShadow({ mode: 'open' }); sShadow.innerHTML = ` `; settingsBtn.onclick = openSettings; panel.appendChild(settingsBtn); }; const cycleNext = () => { const prefs = loadPrefs(); const enabled = getEnabledEngines(prefs); if (enabled.length === 0) return; const idx = enabled.findIndex(e => e.key === current.engine.key); const next = idx === -1 ? enabled[0] : enabled[(idx + 1) % enabled.length]; switchTo(next); }; handle.onclick = cycleNext; wrap.appendChild(panel); wrap.appendChild(handle); document.body.appendChild(wrap); buildPanel(); function openSettings() { const prefs = loadPrefs(); let order = [...prefs.order]; const disabled = new Set(prefs.disabled); const overlay = document.createElement('div'); overlay.className = 'seqs-settings-overlay'; overlay.innerHTML = `
Drag the grip on the right to reorder. Uncheck to hide an engine from the panel. The current engine is always visible.