// ==UserScript== // @name Photar — Steam & SteamDB at0-m Bridge // @namespace https://github.com/niwia/Uran // @version 1.5.0 // @description 1-click game injection into SLSsteam via at0-m for Steam Store & SteamDB // @author niwia, ASSella Team // @match *://store.steampowered.com/app/* // @match *://steamdb.info/app/* // @grant GM_xmlhttpRequest // @connect 127.0.0.1 // @updateURL https://raw.githubusercontent.com/niwia/Uran/main/photar/photar.user.js // @downloadURL https://raw.githubusercontent.com/niwia/Uran/main/photar/photar.user.js // @run-at document-end // ==/UserScript== (function () { 'use strict'; var EPSILON_URL = 'http://127.0.0.1:1952'; var POLL_INTERVAL_MS = 1500; var MAX_POLLS = 40; var DEFAULT_GUIDE_URL = 'https://assella.pages.dev/epsilon'; var TOOLTIP_TEXT = 'Add game to at0-m plugin and download from your library!'; var CARET_SVG = ''; var activeCleanup = null; function injectStyles() { if (document.getElementById('photar-styles')) return; var style = document.createElement('style'); style.id = 'photar-styles'; style.textContent = /* Shared wrapper */ '#at0m-store-wrap, #at0m-steamdb-wrap {' + ' position: relative;' + ' display: inline-flex;' + ' align-items: center;' + ' gap: 1px;' + ' vertical-align: top;' + '}' + '#at0m-store-wrap.queue_btn_at0m { margin-right: 4px; }' + '#at0m-store-wrap.at0m_purchase_action_wrap { margin-right: 6px; vertical-align: middle; }' + '#at0m-steamdb-wrap { margin-right: 4px; }' + /* Steam Store split buttons */ '#at0m-store-btn, #at0m-menu-toggle {' + ' display: inline-flex;' + ' align-items: center;' + ' justify-content: center;' + ' height: 32px;' + ' box-sizing: border-box;' + ' border: none;' + ' padding: 0;' + ' cursor: pointer;' + ' text-decoration: none;' + ' transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;' + '}' + '#at0m-store-btn {' + ' background: rgba(103, 193, 245, 0.2);' + ' border-radius: 2px 0 0 2px;' + '}' + '#at0m-store-btn span {' + ' display: block;' + ' background: transparent !important;' + ' color: #67c1f5;' + ' font-family: "Motiva Sans", Arial, Helvetica, sans-serif;' + ' font-size: 15px;' + ' line-height: 30px;' + ' padding: 0 15px;' + ' text-align: center;' + ' white-space: nowrap;' + ' transition: color 0.2s ease;' + '}' + '#at0m-store-btn:hover {' + ' background: linear-gradient(-60deg, #417a9b 5%, #67c1f5 95%);' + '}' + '#at0m-store-btn:hover span { color: #ffffff; }' + /* Steam Store states */ '#at0m-store-btn[data-state="IN_LIBRARY"] { background: rgba(74, 222, 128, 0.2); }' + '#at0m-store-btn[data-state="IN_LIBRARY"] span { color: #86efac; }' + '#at0m-store-btn[data-state="IN_LIBRARY"]:hover { background: linear-gradient(-60deg, #15803d 5%, #4ade80 95%); }' + '#at0m-store-btn[data-state="IN_LIBRARY"]:hover span { color: #ffffff; }' + '#at0m-store-btn[data-state="ERROR"] { background: rgba(239, 68, 68, 0.2); }' + '#at0m-store-btn[data-state="ERROR"] span { color: #ef4444; }' + '#at0m-store-btn[data-state="ERROR"]:hover { background: linear-gradient(-60deg, #991b1b 5%, #ef4444 95%); }' + '#at0m-store-btn[data-state="ERROR"]:hover span { color: #ffffff; }' + '#at0m-store-btn[data-state="ADDING"] {' + ' opacity: 0.7;' + ' cursor: wait;' + ' pointer-events: none;' + '}' + /* Steam Store dropdown caret cap */ '#at0m-menu-toggle {' + ' width: 24px;' + ' background: rgba(103, 193, 245, 0.2);' + ' color: #67c1f5;' + ' border-radius: 0 2px 2px 0;' + '}' + '#at0m-menu-toggle:hover, #at0m-menu-toggle[aria-expanded="true"] {' + ' background: linear-gradient(-60deg, #417a9b 5%, #67c1f5 95%);' + ' color: #ffffff;' + '}' + /* Dropdown menu */ '.at0m-dropdown {' + ' display: none;' + ' position: absolute;' + ' top: calc(100% + 3px);' + ' left: 0;' + ' min-width: 175px;' + ' background: #1b2838;' + ' border: 1px solid #3d4f63;' + ' border-radius: 2px;' + ' box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);' + ' padding: 4px 0;' + ' z-index: 9999;' + ' font-family: "Motiva Sans", Arial, Helvetica, sans-serif;' + '}' + '.at0m-dropdown.open { display: block; }' + '.at0m-dropdown-item {' + ' display: flex;' + ' align-items: center;' + ' justify-content: space-between;' + ' width: 100%;' + ' box-sizing: border-box;' + ' background: transparent;' + ' border: none;' + ' color: #c7d5e0;' + ' font-size: 13px;' + ' line-height: 1.3;' + ' padding: 7px 12px;' + ' text-align: left;' + ' text-decoration: none;' + ' cursor: pointer;' + ' white-space: nowrap;' + '}' + '.at0m-dropdown-item:hover {' + ' background: rgba(103, 193, 245, 0.2);' + ' color: #ffffff;' + '}' + '.at0m-dropdown-item[disabled] {' + ' opacity: 0.45;' + ' cursor: not-allowed;' + ' pointer-events: none;' + '}' + '.at0m-dropdown-sep {' + ' height: 1px;' + ' background: rgba(255, 255, 255, 0.1);' + ' margin: 4px 0;' + '}' + /* SteamDB buttons */ '#at0m-steamdb-btn { cursor: pointer; border-top-right-radius: 0; border-bottom-right-radius: 0; }' + '#at0m-steamdb-btn[data-state="IN_LIBRARY"] { border-color: #4ade80; }' + '#at0m-steamdb-btn[data-state="IN_LIBRARY"] span { color: #86efac; }' + '#at0m-steamdb-btn[data-state="IN_LIBRARY"]:hover { background-color: #4ade80; }' + '#at0m-steamdb-btn[data-state="IN_LIBRARY"]:hover span { color: #000000; }' + '#at0m-steamdb-btn[data-state="ERROR"] { border-color: #ef4444; }' + '#at0m-steamdb-btn[data-state="ERROR"] span { color: #ef4444; }' + '#at0m-steamdb-btn[data-state="ERROR"]:hover { background-color: #ef4444; }' + '#at0m-steamdb-btn[data-state="ERROR"]:hover span { color: #ffffff; }' + '#at0m-steamdb-btn[data-state="ADDING"] { opacity: 0.7; cursor: wait; pointer-events: none; }' + '#at0m-steamdb-toggle {' + ' cursor: pointer;' + ' padding-left: 6px;' + ' padding-right: 6px;' + ' border-top-left-radius: 0;' + ' border-bottom-left-radius: 0;' + ' display: inline-flex;' + ' align-items: center;' + '}'; (document.head || document.documentElement).appendChild(style); } function isDlcPage() { if (document.querySelector('.game_area_dlc_bubble, div.game_area_bubble.game_area_dlc_bubble')) { return true; } var rows = document.querySelectorAll('.table-bordered tr'); for (var i = 0; i < rows.length; i++) { var cells = rows[i].children; if (cells.length >= 2 && cells[0].textContent.trim() === 'App Type') { if (cells[1].textContent.trim().toUpperCase() === 'DLC') { return true; } } } return false; } function getAppId() { var match = window.location.pathname.match(/\/app\/(\d+)/); if (match) return match[1]; var firstEntry = document.querySelector('.span3'); if (firstEntry && firstEntry.nextElementSibling) { var candidate = firstEntry.nextElementSibling.textContent.trim(); if (/^\d+$/.test(candidate)) return candidate; } return null; } function triggerSteamInstall(appId) { window.location.href = 'steam://install/' + appId; } function req(method, path, body) { return new Promise(function (resolve, reject) { GM_xmlhttpRequest({ method: method, url: EPSILON_URL + path, headers: { 'Content-Type': 'application/json', 'X-Photar-Client': '1' }, data: body ? JSON.stringify(body) : null, timeout: 8000, onload: function (res) { try { var data = JSON.parse(res.responseText); resolve({ ok: true, status: res.status, data: data }); } catch (e) { resolve({ ok: false, status: res.status, text: res.responseText }); } }, ontimeout: function () { reject(new Error('Timeout connecting to local bridge')); }, onerror: function (err) { reject(err); } }); }); } function initBridge(appId) { var state = 'INITIALIZING'; var isSteamDB = window.location.hostname.indexOf('steamdb.info') !== -1; var btn = null; var span = null; var dropdown = null; var toggleBtn = null; var addOnlyItem = null; var addInstallItem = null; var pollTimer = null; var pollCount = 0; var destroyed = false; var guideUrl = DEFAULT_GUIDE_URL; var currentErrorCode = null; var currentErrorMsg = null; function closeDropdown() { if (!dropdown || !toggleBtn) return; dropdown.classList.remove('open'); toggleBtn.setAttribute('aria-expanded', 'false'); } function updateDropdownItems() { if (!addOnlyItem || !addInstallItem) return; var busy = state === 'ADDING'; var inLib = state === 'IN_LIBRARY'; var isErr = state === 'ERROR'; addOnlyItem.disabled = busy || isErr; addInstallItem.disabled = busy || isErr; addOnlyItem.textContent = inLib ? 'Refetch Keys Only' : 'Add Only (Default)'; addInstallItem.textContent = inLib ? 'Start Install' : 'Add & Start Install'; } function applyState(newState, labelOverride, titleOverride) { if (destroyed || !btn || !span) return; state = newState; var lbl = labelOverride; var tip = titleOverride || TOOLTIP_TEXT; if (!lbl) { if (state === 'READY') lbl = 'Add to at0-m'; else if (state === 'IN_LIBRARY') lbl = 'In Library'; else if (state === 'ADDING') lbl = 'Adding...'; else if (state === 'ERROR') lbl = currentErrorCode || '707'; else lbl = 'Add to at0-m'; } if (state === 'ERROR') { tip = currentErrorMsg ? '[Error ' + (currentErrorCode || '707') + '] ' + currentErrorMsg + ' — Click to view guide' : '[Error ' + (currentErrorCode || '707') + '] Click for troubleshooting guide'; } span.textContent = lbl; btn.setAttribute('data-state', state); btn.title = tip; btn.setAttribute('aria-label', tip); if (!isSteamDB) { btn.setAttribute('data-tooltip-text', tip); } updateDropdownItems(); } function checkStatus() { if (destroyed) return; currentErrorCode = null; currentErrorMsg = null; req('GET', '/ping') .then(function (pingRes) { if (destroyed) return; if (!pingRes.ok || !pingRes.data || pingRes.data.service !== 'epsilon') { currentErrorCode = '505'; currentErrorMsg = 'Bridge offline. Start Epsilon or Uran to enable.'; guideUrl = 'https://assella.pages.dev/epsilon#err-505'; applyState('ERROR'); return; } if (pingRes.data.guide_url) { guideUrl = pingRes.data.guide_url; } if (pingRes.data.ready === false || pingRes.data.error_code) { currentErrorCode = pingRes.data.error_code || '504'; currentErrorMsg = pingRes.data.error || 'System prerequisite missing'; guideUrl = pingRes.data.guide_url || ('https://assella.pages.dev/epsilon#err-' + currentErrorCode); } return req('GET', '/status?appid=' + appId); }) .then(function (statusRes) { if (destroyed || !statusRes) return; if (statusRes.ok && statusRes.data) { if (statusRes.data.guide_url) { guideUrl = statusRes.data.guide_url; } if (statusRes.data.added) { applyState('IN_LIBRARY', 'In Library', 'Game is registered in your at0-m library. Click to refetch keys.'); } else if (currentErrorCode) { applyState('ERROR'); } else if (!statusRes.data.ready || statusRes.data.error_code) { currentErrorCode = statusRes.data.error_code || '707'; currentErrorMsg = statusRes.data.error || 'Error occurred'; guideUrl = statusRes.data.guide_url || ('https://assella.pages.dev/epsilon#err-' + currentErrorCode); applyState('ERROR'); } else { applyState('READY'); } } else { applyState(currentErrorCode ? 'ERROR' : 'READY'); } }) .catch(function () { if (destroyed) return; currentErrorCode = '505'; currentErrorMsg = 'Bridge offline. Start Epsilon or Uran to enable.'; guideUrl = 'https://assella.pages.dev/epsilon#err-505'; applyState('ERROR'); }); } function startPolling(launchInstall) { if (pollTimer) clearInterval(pollTimer); pollCount = 0; pollTimer = setInterval(function () { if (destroyed) { clearInterval(pollTimer); return; } pollCount++; if (pollCount > MAX_POLLS) { clearInterval(pollTimer); applyState('IN_LIBRARY', 'In Library'); if (launchInstall) triggerSteamInstall(appId); return; } req('GET', '/status?appid=' + appId) .then(function (res) { if (destroyed) return; if (res.ok && res.data) { var injectStatus = res.data.inject_status; if (injectStatus && injectStatus.done) { clearInterval(pollTimer); if (injectStatus.error) { currentErrorCode = res.data.error_code || '701'; currentErrorMsg = injectStatus.error; guideUrl = res.data.guide_url || ('https://assella.pages.dev/epsilon#err-' + currentErrorCode); applyState('ERROR'); } else { applyState('IN_LIBRARY', 'In Library'); if (launchInstall) triggerSteamInstall(appId); } } else if (res.data.added && !injectStatus) { clearInterval(pollTimer); applyState('IN_LIBRARY', 'In Library'); if (launchInstall) triggerSteamInstall(appId); } } }) .catch(function () {}); }, POLL_INTERVAL_MS); } function runAction(launchInstall) { if (state === 'ADDING') return; if (state === 'ERROR') { var errTarget = guideUrl || ('https://assella.pages.dev/epsilon#err-' + (currentErrorCode || '707')); window.open(errTarget, '_blank', 'noopener,noreferrer'); return; } if (state === 'IN_LIBRARY') { if (launchInstall) { triggerSteamInstall(appId); return; } var confirmed = confirm( 'App ' + appId + ' is already registered in your library.\n\nDo you want to re-project configuration and fetch fresh decryption keys?' ); if (!confirmed) return; applyState('ADDING', 'Refetching...'); req('POST', '/refetch', { appid: appId }) .then(function (res) { if (destroyed) return; if (res.ok && res.data && res.data.ok === false) { currentErrorCode = res.data.error_code || '707'; currentErrorMsg = res.data.error || 'Refetch failed'; guideUrl = res.data.guide_url || ('https://assella.pages.dev/epsilon#err-' + currentErrorCode); applyState('ERROR'); } else { applyState('IN_LIBRARY', 'In Library'); } }) .catch(function () { if (destroyed) return; currentErrorCode = '505'; currentErrorMsg = 'Bridge connection failed during refetch'; guideUrl = 'https://assella.pages.dev/epsilon#err-505'; applyState('ERROR'); }); return; } applyState('ADDING', launchInstall ? 'Adding & Installing...' : 'Adding...'); req('POST', '/inject', { appid: appId }) .then(function (res) { if (destroyed) return; if (!res.ok || !res.data) { currentErrorCode = '505'; currentErrorMsg = 'Bridge offline or connection refused'; guideUrl = 'https://assella.pages.dev/epsilon#err-505'; applyState('ERROR'); return; } if (res.data.already_added) { applyState('IN_LIBRARY', 'In Library'); if (launchInstall) triggerSteamInstall(appId); return; } if (res.data.ok === false || res.data.error_code) { currentErrorCode = res.data.error_code || '707'; currentErrorMsg = res.data.error || 'Injection failed'; guideUrl = res.data.guide_url || ('https://assella.pages.dev/epsilon#err-' + currentErrorCode); applyState('ERROR'); return; } startPolling(launchInstall); }) .catch(function (err) { if (destroyed) return; currentErrorCode = '505'; currentErrorMsg = err.message || 'Bridge offline'; guideUrl = 'https://assella.pages.dev/epsilon#err-505'; applyState('ERROR'); }); } function handleMainClick(e) { e.preventDefault(); e.stopPropagation(); closeDropdown(); runAction(false); } function buildDropdown(consoleUrl) { var menu = document.createElement('div'); menu.className = 'at0m-dropdown'; menu.setAttribute('role', 'menu'); addOnlyItem = document.createElement('button'); addOnlyItem.type = 'button'; addOnlyItem.className = 'at0m-dropdown-item'; addOnlyItem.textContent = 'Add Only (Default)'; addOnlyItem.addEventListener('click', function (e) { e.preventDefault(); e.stopPropagation(); closeDropdown(); runAction(false); }); addInstallItem = document.createElement('button'); addInstallItem.type = 'button'; addInstallItem.className = 'at0m-dropdown-item'; addInstallItem.textContent = 'Add & Start Install'; addInstallItem.addEventListener('click', function (e) { e.preventDefault(); e.stopPropagation(); closeDropdown(); runAction(true); }); var sep = document.createElement('div'); sep.className = 'at0m-dropdown-sep'; var consoleItem = document.createElement('a'); consoleItem.className = 'at0m-dropdown-item'; consoleItem.href = consoleUrl; consoleItem.target = '_blank'; consoleItem.rel = 'noopener noreferrer'; consoleItem.textContent = 'Open Web Console ↗'; consoleItem.addEventListener('click', function () { closeDropdown(); }); menu.appendChild(addOnlyItem); menu.appendChild(addInstallItem); menu.appendChild(sep); menu.appendChild(consoleItem); return menu; } function onWindowFocus() { if (state === 'ERROR') { checkStatus(); } } function onDocumentClick(e) { if (dropdown && dropdown.classList.contains('open')) { var wrapEl = dropdown.parentElement; if (wrapEl && !wrapEl.contains(e.target)) { closeDropdown(); } } } function onKeyDown(e) { if (e.key === 'Escape') closeDropdown(); } window.addEventListener('focus', onWindowFocus); document.addEventListener('click', onDocumentClick); document.addEventListener('keydown', onKeyDown); activeCleanup = function () { destroyed = true; if (pollTimer) clearInterval(pollTimer); window.removeEventListener('focus', onWindowFocus); document.removeEventListener('click', onDocumentClick); document.removeEventListener('keydown', onKeyDown); }; injectStyles(); var consoleUrl = 'https://assella.pages.dev/at0m?q=' + encodeURIComponent(appId); dropdown = buildDropdown(consoleUrl); // 1. SteamDB if (isSteamDB) { var dbWrap = document.createElement('div'); dbWrap.id = 'at0m-steamdb-wrap'; btn = document.createElement('a'); btn.id = 'at0m-steamdb-btn'; btn.className = 'btn tooltipped tooltipped-n'; btn.href = 'javascript:void(0);'; btn.setAttribute('data-state', 'READY'); span = document.createElement('span'); span.textContent = 'Add to at0-m'; btn.appendChild(span); btn.addEventListener('click', handleMainClick); toggleBtn = document.createElement('a'); toggleBtn.id = 'at0m-steamdb-toggle'; toggleBtn.className = 'btn'; toggleBtn.href = 'javascript:void(0);'; toggleBtn.title = 'More at0-m options'; toggleBtn.setAttribute('aria-label', 'More at0-m options'); toggleBtn.setAttribute('aria-expanded', 'false'); toggleBtn.innerHTML = CARET_SVG; toggleBtn.addEventListener('click', function (e) { e.preventDefault(); e.stopPropagation(); var isOpen = dropdown.classList.toggle('open'); toggleBtn.setAttribute('aria-expanded', isOpen ? 'true' : 'false'); }); dbWrap.appendChild(btn); dbWrap.appendChild(toggleBtn); dbWrap.appendChild(dropdown); var target = null; var appLinks = document.querySelectorAll('.app-links'); if (appLinks.length > 1 && appLinks[1].firstElementChild) { target = appLinks[1].firstElementChild; } else if (appLinks.length > 0 && appLinks[0].firstElementChild) { target = appLinks[0].firstElementChild; } else { var pagehead = document.querySelector('.pagehead-actions'); if (pagehead && pagehead.firstElementChild) { target = pagehead.firstElementChild; } } if (target) { target.insertAdjacentElement('beforebegin', dbWrap); checkStatus(); } return; } // 2. Steam Store (split-button matching Steam's Ignore dropdown) btn = document.createElement('a'); btn.id = 'at0m-store-btn'; btn.className = 'btnv6_blue_hoverfade btn_medium queue_btn_inactive'; btn.href = 'javascript:void(0);'; btn.setAttribute('data-state', 'READY'); span = document.createElement('span'); span.textContent = 'Add to at0-m'; btn.appendChild(span); btn.addEventListener('click', handleMainClick); toggleBtn = document.createElement('a'); toggleBtn.id = 'at0m-menu-toggle'; toggleBtn.className = 'btnv6_blue_hoverfade btn_medium'; toggleBtn.href = 'javascript:void(0);'; toggleBtn.title = 'More at0-m options'; toggleBtn.setAttribute('data-tooltip-text', 'More at0-m options'); toggleBtn.setAttribute('aria-label', 'More at0-m options'); toggleBtn.setAttribute('aria-expanded', 'false'); toggleBtn.innerHTML = CARET_SVG; toggleBtn.addEventListener('click', function (e) { e.preventDefault(); e.stopPropagation(); var isOpen = dropdown.classList.toggle('open'); toggleBtn.setAttribute('aria-expanded', isOpen ? 'true' : 'false'); }); var wrap = document.createElement('div'); wrap.id = 'at0m-store-wrap'; wrap.appendChild(btn); wrap.appendChild(toggleBtn); wrap.appendChild(dropdown); var injected = false; // Strategy A: Next to Wishlist button inside .queue_actions_ctn var wishArea = document.querySelector('#add_to_wishlist_area'); var queueCtn = document.querySelector('.queue_actions_ctn'); if (wishArea) { var wishCol = wishArea.closest('.queue_control_button') || wishArea; if (wishCol.parentElement) { wrap.className = 'queue_control_button queue_btn_at0m'; wishCol.parentElement.insertBefore(wrap, wishCol.nextSibling || wishCol); injected = true; } } else if (queueCtn) { wrap.className = 'queue_control_button queue_btn_at0m'; queueCtn.appendChild(wrap); injected = true; } // Strategy B: Fallback to the purchase area (e.g. Free-to-play / no wishlist) if (!injected) { var purchaseAction = document.querySelector('.game_area_purchase_game .game_purchase_action') || document.querySelector('.game_purchase_action'); if (purchaseAction) { wrap.className = 'at0m_purchase_action_wrap'; var cartBtn = purchaseAction.querySelector('.btn_addtocart') || purchaseAction.firstElementChild; if (cartBtn) { purchaseAction.insertBefore(wrap, cartBtn); } else { purchaseAction.appendChild(wrap); } injected = true; } } if (injected) { checkStatus(); } } function unmount() { if (activeCleanup) { activeCleanup(); activeCleanup = null; } var ids = ['at0m-store-wrap', 'at0m-steamdb-wrap']; for (var i = 0; i < ids.length; i++) { var el = document.getElementById(ids[i]); if (el) el.remove(); } } function mount() { if (isDlcPage()) return; var appId = getAppId(); if (!appId) return; if (document.getElementById('at0m-store-btn') || document.getElementById('at0m-steamdb-btn')) { return; } initBridge(appId); } mount(); var lastUrl = window.location.href; var debounceTimer = null; var observer = new MutationObserver(function () { if (window.location.href !== lastUrl) { lastUrl = window.location.href; unmount(); clearTimeout(debounceTimer); debounceTimer = setTimeout(mount, 400); return; } if (document.getElementById('at0m-store-btn') || document.getElementById('at0m-steamdb-btn')) { return; } clearTimeout(debounceTimer); debounceTimer = setTimeout(mount, 250); }); observer.observe(document.body, { childList: true, subtree: true }); })();