_name)
var given = w.modelName && !/^Objects_\d+_name$/.test(w.modelName);
var name = given ? ' as ' + esc(w.modelName) + '' : '';
return 'On ' + fmt.link('/properties/' + w.propertyId, w.propertyName || 'Property ' + w.propertyId) + name +
'
(' + fmt.character(w.ownerId, w.ownerName) + ', ' + esc(w.zoneId) + ')' +
'
3D ';
}
if (w.type === 'mail') return 'In the mail to ' + fmt.character(w.characterId, w.characterName) + '
';
return 'In ' + fmt.character(w.characterId, item.characterName) + '\'s ' + esc(inventoryName(w.inventory)) + '
';
}).join('');
}
function render(items) {
rows.innerHTML = items.length ? items.map(function (item) {
var lot = item.kind === 'modular' ? 6416 : 6662;
var label = item.kind === 'modular' ? 'Car or rocket' : 'Model';
var title = item.link ? '' + label + ' ' + esc(item.ugcId) + '' : label + ' ' + esc(item.ugcId);
var detail = item.detail ? '' + (item.kind === 'modular' ? 'Modules ' + esc(item.detail) + '' : esc(item.detail)) + '
' : '';
var account = item.accountName ? '' + (document.getElementById('ugcSearchPage').dataset.canAccounts ? fmt.link('/accounts/' + item.accountId, item.accountName) : esc(item.accountName)) + '
' : '';
return '| ' + UgcLinks.icon(item, lot, 48) + ' | ' + title + detail + ' | ' +
'' + fmt.character(item.characterId, item.characterName) + account + ' | ' +
'' + where(item) + ' | ' + UgcLinks.state(item) + ' |
';
}).join('') : '| Nothing matches. |
';
}
function search() {
var q = input.value.trim();
var request = ++latest;
var url = new URL(window.location.href);
if (q) url.searchParams.set('q', q); else url.searchParams.delete('q');
history.replaceState(null, '', url);
if (!q) { rows.innerHTML = '| Type something to search. |
'; status.textContent = ''; return; }
status.textContent = 'Searching…';
api.get('/api/ugc_links/search?q=' + encodeURIComponent(q)).then(function (d) {
if (request !== latest) return;
var items = (d && d.items) || [];
status.textContent = items.length + ' found' + (items.length >= 50 ? ' (the newest 50 of each kind; narrow the search for more)' : '');
render(items);
}).catch(function () { if (request === latest) status.textContent = 'The search failed.'; });
}
input.addEventListener('input', function () { clearTimeout(timer); timer = setTimeout(search, 300); });
document.getElementById('ugcSearchForm').addEventListener('submit', function (e) { e.preventDefault(); clearTimeout(timer); search(); });
input.value = document.getElementById('ugcSearchPage').dataset.query || '';
if (input.value) search();
input.focus();
})();