/* BT search v1 (2026-11-18): Search row in the mobile menu + "Tools" shortcuts inside Ghost's search window */ (function () { if (window.btSearchV1) return; window.btSearchV1 = 1; var B = 'https://baseballthings.com'; var T = [ ['Hot Stove GM', '/hot-stove-gm/', 'Build the Mariners offseason yourself', 'gm general manager offseason simulator sim mock'], ['Hot Stove Tracker', '/hot-stove-tracker/', 'Every MLB move this offseason', 'moves signings trades deals offseason hot stove'], ['Free Agent Tracker', '/free-agent-tracker/', 'Every MLB and MiLB free agent', 'fa free agents agency signings available'], ['Arbitration Tracker', '/arbitration-tracker/', 'Arbitration-eligible players and salaries', 'arb arbitration salary salaries eligible'], ['Contention Index', '/contention-index/', 'All 30 clubs ranked on contention', 'contention playoff rankings teams index power'], ['Trade Tree', '/mariners-dipoto-trade-tree/', 'Every Dipoto trade and what it became', 'trades trade tree dipoto'], ['Contract Value Board', '/mariners-dipoto-contract-board/', 'Mariners contracts graded by value', 'contracts contract value extensions'], ['Rule 5 Tracker', '/rule-5-tracker/', 'Rule 5 eligibility for all 30 teams', 'rule 5 five draft protected 40-man forty eligible'], ['Draft Scorecard', '/mariners-draft-dipoto-hunter/', 'Mariners drafts under Dipoto and Hunter', 'draft drafts scorecard hunter picks'], ['Player Comparison', '/mlb-player-compare/', 'Compare MLB players side by side', 'compare comparison stats versus vs'], ['Prospect Rankings Live', '/prospect-rankings-live/', 'Mariners prospect rankings, kept current', 'prospects prospect rankings top farm'], ['Prospect Leaderboards', '/prospects-stats-leaderboards-2026/', 'Minor league stat leaderboards', 'leaderboards leaders stats minors milb minor league prospects'], ['Fall & Winter Ball', '/prospects-afl-winter-stats/', 'Arizona Fall League and winter ball stats', 'afl arizona fall winter ball league stats'], ['Mariners Roster', '/mariners-roster/', 'The current 40-man roster', 'roster 40-man forty mariners'], ['Depth Chart', '/mariners-depth-chart/', 'Mariners depth chart by position', 'depth chart lineup rotation bullpen'], ['Transactions', '/transactions/', 'Every roster move, as it happens', 'transactions moves news'], ['Players A–Z', '/players/', 'Player pages for every 40-man roster', 'players player pages a-z'], ['MLB Teams', '/teams/', 'All 30 clubs', 'teams clubs mlb'], ['Series Preview', '/series-preview/', 'The next Mariners series, previewed', 'series preview schedule matchup'], ['Subscribe', '/subscribe/', 'Plans and prices', 'subscribe plans membership price prices join sign up'], ['Patreon', '/patreon/', 'Support Baseball Things on Patreon', 'patreon support'] ]; function norm(s) { return (s || '').toLowerCase().replace(/[–—]/g, '-').replace(/[^a-z0-9\- ]+/g, ' ').replace(/\s+/g, ' ').trim(); } function match(q) { q = norm(q); if (q.length < 2) return []; var qw = q.split(' '), out = []; T.forEach(function (t) { var name = norm(t[0]), words = (name + ' ' + norm(t[3])).split(' '), score = 0; if (name === q) score = 100; else if (q.length <= 3 && words.indexOf(q) > -1) score = 90; else if (name.indexOf(q) === 0) score = 80; else if (name.indexOf(q) > -1) score = 60; else if (words.indexOf(q) > -1) score = 50; else if (qw.every(function (w) { return words.some(function (x) { return x.indexOf(w) === 0; }); })) score = 40; if (score) out.push([score, t]); }); out.sort(function (a, b) { return b[0] - a[0]; }); return out.slice(0, 4).map(function (x) { return x[1]; }); } function esc(s) { return s.replace(/[&<>"]/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"' }[c]; }); } /* Tools group inside the search window (Ghost's search runs in a same-origin iframe) */ function render(d) { var dlg = d.querySelector('[role=dialog]'), inp = d.querySelector('input'); if (!dlg || !inp) return; var box = d.getElementById('bt-tools'); var hits = match(inp.value); if (!hits.length) { if (box) box.remove(); return; } if (!box) { box = d.createElement('div'); box.id = 'bt-tools'; box.setAttribute('style', 'border-top:1px solid #e5e5e5;padding:12px 0 6px;background:#fff;position:relative;z-index:5'); } var anchor = dlg.firstElementChild; if (box.parentNode !== dlg || box.previousElementSibling !== anchor) dlg.insertBefore(box, anchor ? anchor.nextSibling : dlg.firstChild); var key = hits.map(function (t) { return t[1]; }).join(); if (box.getAttribute('data-k') === key) return; box.setAttribute('data-k', key); var pad = d.defaultView.innerWidth >= 640 ? '28px' : '16px'; box.innerHTML = '
Tools
' + hits.map(function (t) { return '' + '⚾' + '' + esc(t[0]) + '' + '' + esc(t[2]) + ''; }).join(''); } function hook(f) { if (f.__bt) return; var d; try { d = f.contentDocument; } catch (e) { return; } if (!d || !d.body) return; f.__bt = 1; if (!d.getElementById('bt-tools-css')) { var s = d.createElement('style'); s.id = 'bt-tools-css'; s.textContent = '#bt-tools a.bt-tool:hover,#bt-tools a.bt-tool:focus{background:#f5f5f5;outline:none}'; d.head.appendChild(s); } var busy = 0; new MutationObserver(function () { if (busy) return; busy = 1; try { render(d); } finally { busy = 0; } }) .observe(d.body, { childList: true, subtree: true, characterData: true }); d.addEventListener('input', function () { render(d); }, true); render(d); } function scan() { var r = document.getElementById('sodo-search-root'); if (!r) return; r.querySelectorAll('iframe').forEach(function (f) { if (!f.__btl) { f.__btl = 1; f.addEventListener('load', function () { f.__bt = 0; hook(f); }); } if (f.__bt && f.__btd !== f.contentDocument) f.__bt = 0; if (!f.__bt) { hook(f); f.__btd = f.contentDocument; } }); } /* Mobile menu: a Search row at the top of the open menu */ function openSearch() { var nav = document.getElementById('gh-navigation'), burger = document.querySelector('.gh-burger'); if (nav && nav.classList.contains('is-open') && burger) burger.click(); var b = document.querySelector('.gh-search[data-ghost-search]'); if (b) b.click(); else location.hash = '#/search'; } function addMenuRow() { var menu = document.querySelector('.gh-navigation-menu ul.nav'); if (!menu || menu.querySelector('.bt-msearch')) return; var st = document.createElement('style'); st.textContent = '.bt-msearch-li{display:none}' + '@media (max-width:767px){.gh-navigation.is-open .bt-msearch-li{display:block;list-style:none;margin:0 0 14px}.bt-msearch{display:flex;align-items:center;gap:10px;width:min(320px,86vw);margin:0 auto;padding:12px 16px;border-radius:999px;border:1px solid rgba(255,255,255,.18);background:rgba(255,255,255,.07);color:#d6e2f1;font:inherit;font-size:16px;font-weight:600;cursor:pointer;text-align:left}' + '.bt-msearch svg{flex:none;color:#6cb4ff}}'; document.head.appendChild(st); var b = document.createElement('button'); b.type = 'button'; b.className = 'bt-msearch'; b.setAttribute('aria-label', 'Search this site'); b.innerHTML = 'Search players, posts & tools'; b.addEventListener('click', function (e) { e.preventDefault(); e.stopPropagation(); openSearch(); }); var li = document.createElement('li'); li.className = 'bt-msearch-li'; li.appendChild(b); menu.insertBefore(li, menu.firstChild); } function init() { addMenuRow(); var n = 0, t = setInterval(function () { var r = document.getElementById('sodo-search-root'); if (r) { clearInterval(t); new MutationObserver(scan).observe(r, { childList: true, subtree: true }); scan(); } else if (++n > 60) clearInterval(t); }, 500); } if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else init(); window.btSearchTest = match; })();