Add USw to the inline search and proper installing
This commit is contained in:
parent
33e7f920a3
commit
63ebd1e0aa
|
@ -1275,6 +1275,10 @@
|
||||||
"message": "Also search global styles",
|
"message": "Also search global styles",
|
||||||
"description": "Checkbox label in the popup's inline style search, shown when the text to search is entered"
|
"description": "Checkbox label in the popup's inline style search, shown when the text to search is entered"
|
||||||
},
|
},
|
||||||
|
"searchUserStylesWorld": {
|
||||||
|
"message": "Search in Userstyles world",
|
||||||
|
"description": "Checkbox label in the popup's inline style search, shown when the text to search is entered"
|
||||||
|
},
|
||||||
"searchNumberOfResults": {
|
"searchNumberOfResults": {
|
||||||
"message": "Number of matches",
|
"message": "Number of matches",
|
||||||
"description": "Tooltip for the number of found search results in the editor shown on Ctrl-F"
|
"description": "Tooltip for the number of found search results in the editor shown on Ctrl-F"
|
||||||
|
|
|
@ -226,6 +226,10 @@ const styleMan = (() => {
|
||||||
URLS.extractGreasyForkInstallUrl(style.updateUrl)
|
URLS.extractGreasyForkInstallUrl(style.updateUrl)
|
||||||
);
|
);
|
||||||
if (url) style.url = style.installationUrl = url;
|
if (url) style.url = style.installationUrl = url;
|
||||||
|
if (style.initialUrl) {
|
||||||
|
style.installationUrl = URLS.extractUSwInstallUrl(style.initialUrl);
|
||||||
|
delete style.initialUrl;
|
||||||
|
}
|
||||||
style.originalDigest = await calcStyleDigest(style);
|
style.originalDigest = await calcStyleDigest(style);
|
||||||
// FIXME: update updateDate? what about usercss config?
|
// FIXME: update updateDate? what about usercss config?
|
||||||
return handleSave(await saveStyle(style), reason);
|
return handleSave(await saveStyle(style), reason);
|
||||||
|
|
|
@ -38,6 +38,7 @@ bgReady.all.then(() => {
|
||||||
URLS.usoArchiveRaw + 'usercss/*.user.css',
|
URLS.usoArchiveRaw + 'usercss/*.user.css',
|
||||||
'*://greasyfork.org/scripts/*/code/*.user.css',
|
'*://greasyfork.org/scripts/*/code/*.user.css',
|
||||||
'*://sleazyfork.org/scripts/*/code/*.user.css',
|
'*://sleazyfork.org/scripts/*/code/*.user.css',
|
||||||
|
URLS.usw + 'api/style/*.user.css',
|
||||||
...[].concat(
|
...[].concat(
|
||||||
...Object.entries(maybeDistro)
|
...Object.entries(maybeDistro)
|
||||||
.map(([host, {glob}]) => makeUsercssGlobs(host, glob))),
|
.map(([host, {glob}]) => makeUsercssGlobs(host, glob))),
|
||||||
|
|
|
@ -81,6 +81,7 @@ const preinit = (() => {
|
||||||
value: API.usercss.buildCode(data.style).then(style => style.sections),
|
value: API.usercss.buildCode(data.style).then(style => style.sections),
|
||||||
configurable: true,
|
configurable: true,
|
||||||
});
|
});
|
||||||
|
data.style.initialUrl = initialUrl;
|
||||||
return data;
|
return data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {error, sourceCode};
|
return {error, sourceCode};
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
'popup.autoResort': false, // auto resort styles after toggling
|
'popup.autoResort': false, // auto resort styles after toggling
|
||||||
'popup.borders': false, // add white borders on the sides
|
'popup.borders': false, // add white borders on the sides
|
||||||
'popup.findStylesInline': true, // use the inline style search
|
'popup.findStylesInline': true, // use the inline style search
|
||||||
|
'popup.searchUserStylesWorld': false, // use userstyles world instead of uso-archive for inline searching.
|
||||||
|
|
||||||
'manage.onlyEnabled': false, // display only enabled styles
|
'manage.onlyEnabled': false, // display only enabled styles
|
||||||
'manage.onlyLocal': false, // display only styles created locally
|
'manage.onlyLocal': false, // display only styles created locally
|
||||||
|
|
|
@ -78,6 +78,10 @@ const URLS = {
|
||||||
|
|
||||||
usoArchive: 'https://33kk.github.io/uso-archive/',
|
usoArchive: 'https://33kk.github.io/uso-archive/',
|
||||||
usoArchiveRaw: 'https://raw.githubusercontent.com/33kk/uso-archive/flomaster/data/',
|
usoArchiveRaw: 'https://raw.githubusercontent.com/33kk/uso-archive/flomaster/data/',
|
||||||
|
|
||||||
|
usw: 'https://userstyles.world/',
|
||||||
|
uswSearch: 'https://userstyles.world/api/search/',
|
||||||
|
|
||||||
extractUsoArchiveId: url =>
|
extractUsoArchiveId: url =>
|
||||||
url &&
|
url &&
|
||||||
url.startsWith(URLS.usoArchiveRaw) &&
|
url.startsWith(URLS.usoArchiveRaw) &&
|
||||||
|
@ -91,6 +95,16 @@ const URLS = {
|
||||||
extractGreasyForkInstallUrl: url =>
|
extractGreasyForkInstallUrl: url =>
|
||||||
/^(https:\/\/(?:greasy|sleazy)fork\.org\/scripts\/\d+)[^/]*\/code\/[^/]*\.user\.css$|$/.exec(url)[1],
|
/^(https:\/\/(?:greasy|sleazy)fork\.org\/scripts\/\d+)[^/]*\/code\/[^/]*\.user\.css$|$/.exec(url)[1],
|
||||||
|
|
||||||
|
extractUSwId: url =>
|
||||||
|
url &&
|
||||||
|
url.startsWith(URLS.usw) &&
|
||||||
|
Number(url.match(/\/(\d+)\.user\.css|$/)[1]),
|
||||||
|
extractUSwInstallUrl: url => {
|
||||||
|
const id = URLS.extractUSwId(url);
|
||||||
|
return id ? `${URLS.usw}style/${id}` : '';
|
||||||
|
},
|
||||||
|
makeUSwArchiveCodeUrl: id => `${URLS.usw}api/style/${id}.user.css`,
|
||||||
|
|
||||||
supported: url => (
|
supported: url => (
|
||||||
url.startsWith('http') ||
|
url.startsWith('http') ||
|
||||||
url.startsWith('ftp') ||
|
url.startsWith('ftp') ||
|
||||||
|
@ -411,13 +425,14 @@ function download(url, {
|
||||||
};
|
};
|
||||||
xhr.onload = () => {
|
xhr.onload = () => {
|
||||||
if (xhr.status === requiredStatusCode || !requiredStatusCode || u.protocol === 'file:') {
|
if (xhr.status === requiredStatusCode || !requiredStatusCode || u.protocol === 'file:') {
|
||||||
|
const isUSWSearch = url.startsWith(URLS.uswSearch);
|
||||||
const response = expandUsoVars(xhr.response);
|
const response = expandUsoVars(xhr.response);
|
||||||
if (responseHeaders) {
|
if (responseHeaders) {
|
||||||
const headers = {};
|
const headers = {};
|
||||||
for (const h of responseHeaders) headers[h] = xhr.getResponseHeader(h);
|
for (const h of responseHeaders) headers[h] = xhr.getResponseHeader(h);
|
||||||
resolve({headers, response});
|
resolve({headers, response});
|
||||||
} else {
|
} else {
|
||||||
resolve(response);
|
resolve(isUSWSearch ? response.data : response);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reject(xhr.status);
|
reject(xhr.status);
|
||||||
|
|
|
@ -252,6 +252,13 @@
|
||||||
</span>
|
</span>
|
||||||
<span i18n-text="searchGlobalStyles"></span>
|
<span i18n-text="searchGlobalStyles"></span>
|
||||||
</label>
|
</label>
|
||||||
|
<label>
|
||||||
|
<span class="checkbox-container">
|
||||||
|
<input id="search-usw" type="checkbox" checked>
|
||||||
|
<svg class="svg-icon checked"><use xlink:href="#svg-icon-checked"/></svg>
|
||||||
|
</span>
|
||||||
|
<span i18n-text="searchUserStylesWorld"></span>
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div id="search-results-list"></div>
|
<div id="search-results-list"></div>
|
||||||
<div class="search-results-nav" data-type="bottom"></div>
|
<div class="search-results-nav" data-type="bottom"></div>
|
||||||
|
|
171
popup/search.js
171
popup/search.js
|
@ -39,8 +39,23 @@
|
||||||
let results;
|
let results;
|
||||||
/** @type IndexEntry[] */
|
/** @type IndexEntry[] */
|
||||||
let index;
|
let index;
|
||||||
|
/**
|
||||||
|
* @typedef USWIndexEntry
|
||||||
|
* @prop {Number} id - id
|
||||||
|
* @prop {string} name - name
|
||||||
|
* @prop {string} username - authorName
|
||||||
|
* @prop {string} description - description
|
||||||
|
* @prop {string} preview - screenshot
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @type {Object.<string, USWIndexEntry[]>}
|
||||||
|
*/
|
||||||
|
const USWIndex = {};
|
||||||
|
/** @type USWIndexEntry[] */
|
||||||
|
let USWResults = [];
|
||||||
let category = '';
|
let category = '';
|
||||||
let searchGlobals = $('#search-globals').checked;
|
let searchGlobals = $('#search-globals').checked;
|
||||||
|
let searchUserStylesWorld = $('#search-usw').checked;
|
||||||
/** @type string[] */
|
/** @type string[] */
|
||||||
let query = [];
|
let query = [];
|
||||||
/** @type 'n' | 'u' | 't' | 'w' | 'r' */
|
/** @type 'n' | 'u' | 't' | 'w' | 'r' */
|
||||||
|
@ -82,9 +97,16 @@
|
||||||
searchGlobals = this.checked;
|
searchGlobals = this.checked;
|
||||||
ready = ready.then(start);
|
ready = ready.then(start);
|
||||||
};
|
};
|
||||||
|
$('#search-usw').checked = prefs.get('popup.searchUserStylesWorld');
|
||||||
|
$('#search-usw').onchange = function () {
|
||||||
|
searchUserStylesWorld = this.checked;
|
||||||
|
prefs.set('popup.searchUserStylesWorld', searchUserStylesWorld);
|
||||||
|
ready = ready.then(start);
|
||||||
|
};
|
||||||
$('#search-query').oninput = function () {
|
$('#search-query').oninput = function () {
|
||||||
|
debounce(ev => {
|
||||||
query = [];
|
query = [];
|
||||||
const text = this.value.trim().toLocaleLowerCase();
|
const text = ev.value.trim().toLocaleLowerCase();
|
||||||
const thisYear = new Date().getFullYear();
|
const thisYear = new Date().getFullYear();
|
||||||
for (let re = /"(.+?)"|(\S+)/g, m; (m = re.exec(text));) {
|
for (let re = /"(.+?)"|(\S+)/g, m; (m = re.exec(text));) {
|
||||||
const n = Number(m[2]);
|
const n = Number(m[2]);
|
||||||
|
@ -94,11 +116,17 @@
|
||||||
query.push('stylus');
|
query.push('stylus');
|
||||||
}
|
}
|
||||||
ready = ready.then(start);
|
ready = ready.then(start);
|
||||||
|
}, 750, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
$('#search-order').value = order;
|
$('#search-order').value = order;
|
||||||
$('#search-order').onchange = function () {
|
$('#search-order').onchange = function () {
|
||||||
order = this.value;
|
order = this.value;
|
||||||
|
if (searchUserStylesWorld) {
|
||||||
|
USWResults.sort(comparator);
|
||||||
|
} else {
|
||||||
results.sort(comparator);
|
results.sort(comparator);
|
||||||
|
}
|
||||||
render();
|
render();
|
||||||
};
|
};
|
||||||
dom.list = $('#search-results-list');
|
dom.list = $('#search-results-list');
|
||||||
|
@ -132,20 +160,36 @@
|
||||||
|
|
||||||
window.on('styleDeleted', ({detail: {style: {id}}}) => {
|
window.on('styleDeleted', ({detail: {style: {id}}}) => {
|
||||||
restoreScrollPosition();
|
restoreScrollPosition();
|
||||||
|
if (searchUserStylesWorld) {
|
||||||
|
const result = USWResults.find(r => r.id === id);
|
||||||
|
if (result) {
|
||||||
|
clearTimeout(result.pingbackTimer);
|
||||||
|
renderActionButtons(result.id, -1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
const result = results.find(r => r.installedStyleId === id);
|
const result = results.find(r => r.installedStyleId === id);
|
||||||
if (result) {
|
if (result) {
|
||||||
clearTimeout(result.pingbackTimer);
|
clearTimeout(result.pingbackTimer);
|
||||||
renderActionButtons(result.i, -1);
|
renderActionButtons(result.i, -1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.on('styleAdded', async ({detail: {style}}) => {
|
window.on('styleAdded', async ({detail: {style}}) => {
|
||||||
restoreScrollPosition();
|
restoreScrollPosition();
|
||||||
|
if (searchUserStylesWorld) {
|
||||||
|
const uswId = calcUSwId(style) ||
|
||||||
|
calcUSwId(await API.styles.get(style.id));
|
||||||
|
if (uswId && USWResults.find(r => r.id === uswId)) {
|
||||||
|
renderActionButtons(uswId, style.id);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
const usoId = calcUsoId(style) ||
|
const usoId = calcUsoId(style) ||
|
||||||
calcUsoId(await API.styles.get(style.id));
|
calcUsoId(await API.styles.get(style.id));
|
||||||
if (usoId && results.find(r => r.i === usoId)) {
|
if (usoId && results.find(r => r.i === usoId)) {
|
||||||
renderActionButtons(usoId, style.id);
|
renderActionButtons(usoId, style.id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,19 +225,27 @@
|
||||||
show(dom.container);
|
show(dom.container);
|
||||||
show(dom.list);
|
show(dom.list);
|
||||||
hide(dom.error);
|
hide(dom.error);
|
||||||
results = [];
|
|
||||||
try {
|
try {
|
||||||
for (let retry = 0; !results.length && retry <= 2; retry++) {
|
let resultsMap = [];
|
||||||
results = await search({retry});
|
for (let retry = 0; !resultsMap.length && retry <= 2; retry++) {
|
||||||
|
resultsMap = await search({retry, searchUserStylesWorld});
|
||||||
}
|
}
|
||||||
if (results.length) {
|
if (resultsMap.length) {
|
||||||
const installedStyles = await API.styles.getAll();
|
const installedStyles = await API.styles.getAll();
|
||||||
|
if (searchUserStylesWorld) {
|
||||||
|
const allUSwIds = new Set(installedStyles.map(calcUSwId));
|
||||||
|
USWResults = resultsMap.filter(r => !allUSwIds.has(r.id));
|
||||||
|
} else {
|
||||||
const allUsoIds = new Set(installedStyles.map(calcUsoId));
|
const allUsoIds = new Set(installedStyles.map(calcUsoId));
|
||||||
results = results.filter(r => !allUsoIds.has(r.i));
|
results = resultsMap.filter(r => !allUsoIds.has(r.i));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
USWResults = [];
|
||||||
|
results = [];
|
||||||
}
|
}
|
||||||
render();
|
render();
|
||||||
(results.length ? show : hide)(dom.list);
|
((searchUserStylesWorld ? USWResults : results).length ? show : hide)(dom.list);
|
||||||
if (!results.length && !$('#search-query').value) {
|
if (!(searchUserStylesWorld ? USWResults : results).length) {
|
||||||
error(t('searchResultNoneFound'));
|
error(t('searchResultNoneFound'));
|
||||||
}
|
}
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
|
@ -202,7 +254,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
totalPages = Math.ceil(results.length / PAGE_LENGTH);
|
const correctResults = searchUserStylesWorld ? USWResults : results;
|
||||||
|
totalPages = Math.ceil(correctResults.length / PAGE_LENGTH);
|
||||||
displayedPage = Math.min(displayedPage, totalPages) || 1;
|
displayedPage = Math.min(displayedPage, totalPages) || 1;
|
||||||
let start = (displayedPage - 1) * PAGE_LENGTH;
|
let start = (displayedPage - 1) * PAGE_LENGTH;
|
||||||
const end = displayedPage * PAGE_LENGTH;
|
const end = displayedPage * PAGE_LENGTH;
|
||||||
|
@ -211,15 +264,17 @@
|
||||||
// keep rendered elements with ids in the range of interest
|
// keep rendered elements with ids in the range of interest
|
||||||
while (
|
while (
|
||||||
plantAt < PAGE_LENGTH &&
|
plantAt < PAGE_LENGTH &&
|
||||||
slot && slot.id === 'search-result-' + (results[start] || {}).i
|
slot && slot.id === 'search-result-' + (correctResults[start] || {}).i
|
||||||
) {
|
) {
|
||||||
slot = slot.nextElementSibling;
|
slot = slot.nextElementSibling;
|
||||||
plantAt++;
|
plantAt++;
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
// add new elements
|
// add new elements
|
||||||
while (start < Math.min(end, results.length)) {
|
while (start < Math.min(end, correctResults.length)) {
|
||||||
const entry = createSearchResultNode(results[start++]);
|
const entry = searchUserStylesWorld
|
||||||
|
? createSearchUSWResultNode(correctResults[start++])
|
||||||
|
: createSearchResultNode(correctResults[start++]);
|
||||||
if (slot) {
|
if (slot) {
|
||||||
dom.list.replaceChild(entry, slot);
|
dom.list.replaceChild(entry, slot);
|
||||||
slot = entry.nextElementSibling;
|
slot = entry.nextElementSibling;
|
||||||
|
@ -229,13 +284,13 @@
|
||||||
plantAt++;
|
plantAt++;
|
||||||
}
|
}
|
||||||
// remove extraneous elements
|
// remove extraneous elements
|
||||||
const pageLen = end > results.length &&
|
const pageLen = end > correctResults.length &&
|
||||||
results.length % PAGE_LENGTH ||
|
correctResults.length % PAGE_LENGTH ||
|
||||||
Math.min(results.length, PAGE_LENGTH);
|
Math.min(correctResults.length, PAGE_LENGTH);
|
||||||
while (dom.list.children.length > pageLen) {
|
while (dom.list.children.length > pageLen) {
|
||||||
dom.list.lastElementChild.remove();
|
dom.list.lastElementChild.remove();
|
||||||
}
|
}
|
||||||
if (results.length && 'empty' in dom.container.dataset) {
|
if (correctResults.length && 'empty' in dom.container.dataset) {
|
||||||
delete dom.container.dataset.empty;
|
delete dom.container.dataset.empty;
|
||||||
}
|
}
|
||||||
if (scrollToFirstResult && (!FIREFOX || FIREFOX >= 55)) {
|
if (scrollToFirstResult && (!FIREFOX || FIREFOX >= 55)) {
|
||||||
|
@ -318,6 +373,42 @@
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {USWIndexEntry} result
|
||||||
|
* @returns {Node}
|
||||||
|
*/
|
||||||
|
function createSearchUSWResultNode(result) {
|
||||||
|
const entry = t.template.searchResult.cloneNode(true);
|
||||||
|
const {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
preview,
|
||||||
|
username,
|
||||||
|
} = entry._result = result;
|
||||||
|
entry.id = RESULT_ID_PREFIX + id;
|
||||||
|
// title
|
||||||
|
Object.assign($('.search-result-title', entry), {
|
||||||
|
onclick: Events.openURLandHide,
|
||||||
|
href: `${URLS.usw}style/${id}`,
|
||||||
|
});
|
||||||
|
$('.search-result-title span', entry).textContent =
|
||||||
|
t.breakWord(name.length < 300 ? name : name.slice(0, 300) + '...');
|
||||||
|
// screenshot
|
||||||
|
Object.assign($('.search-result-screenshot', entry), {
|
||||||
|
src: preview,
|
||||||
|
onerror: fixScreenshot,
|
||||||
|
});
|
||||||
|
// author
|
||||||
|
Object.assign($('[data-type="author"] a', entry), {
|
||||||
|
textContent: username,
|
||||||
|
title: username,
|
||||||
|
href: `${URLS.usw}user/${encodeURIComponent(username).replace(/%20/g, '+')}`,
|
||||||
|
onclick: Events.openURLandHide,
|
||||||
|
});
|
||||||
|
renderActionButtons(entry);
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
function formatNumber(num) {
|
function formatNumber(num) {
|
||||||
return (
|
return (
|
||||||
num > 1e9 ? (num / 1e9).toFixed(1) + 'B' :
|
num > 1e9 ? (num / 1e9).toFixed(1) + 'B' :
|
||||||
|
@ -369,11 +460,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object.assign($('.search-result-screenshot', entry), {
|
Object.assign($('.search-result-screenshot', entry), {
|
||||||
onclick: isInstalled ? uninstall : install,
|
onclick: isInstalled ? uninstall : searchUserStylesWorld ? uswInstall : install,
|
||||||
title: isInstalled ? '' : t('installButton'),
|
title: isInstalled ? '' : t('installButton'),
|
||||||
});
|
});
|
||||||
$('.search-result-uninstall', entry).onclick = uninstall;
|
$('.search-result-uninstall', entry).onclick = uninstall;
|
||||||
$('.search-result-install', entry).onclick = install;
|
$('.search-result-install', entry).onclick = searchUserStylesWorld ? uswInstall : install;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderFullInfo(entry, style) {
|
function renderFullInfo(entry, style) {
|
||||||
|
@ -422,6 +513,30 @@
|
||||||
entry.style.pointerEvents = '';
|
entry.style.pointerEvents = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function uswInstall() {
|
||||||
|
const entry = this.closest('.search-result');
|
||||||
|
const result = /** @type IndexEntry */ entry._result;
|
||||||
|
const {id} = result;
|
||||||
|
const installButton = $('.search-result-install', entry);
|
||||||
|
|
||||||
|
showSpinner(entry);
|
||||||
|
saveScrollPosition(entry);
|
||||||
|
installButton.disabled = true;
|
||||||
|
entry.style.setProperty('pointer-events', 'none', 'important');
|
||||||
|
|
||||||
|
const updateUrl = URLS.makeUSwArchiveCodeUrl(id);
|
||||||
|
try {
|
||||||
|
const sourceCode = await download(updateUrl);
|
||||||
|
const style = await API.usercss.install({sourceCode, updateUrl, initialUrl: updateUrl});
|
||||||
|
renderFullInfo(entry, style);
|
||||||
|
} catch (reason) {
|
||||||
|
error(`Error while downloading uswID:${id}\nReason: ${reason}`);
|
||||||
|
}
|
||||||
|
$remove('.lds-spinner', entry);
|
||||||
|
installButton.disabled = false;
|
||||||
|
entry.style.pointerEvents = '';
|
||||||
|
}
|
||||||
|
|
||||||
function uninstall() {
|
function uninstall() {
|
||||||
const entry = this.closest('.search-result');
|
const entry = this.closest('.search-result');
|
||||||
saveScrollPosition(entry);
|
saveScrollPosition(entry);
|
||||||
|
@ -476,9 +591,23 @@
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function search({retry} = {}) {
|
async function searchUSW() {
|
||||||
|
const timer = setTimeout(showSpinner, BUSY_DELAY, dom.list);
|
||||||
|
const USWQuery = query.join(' ');
|
||||||
|
if (!USWQuery) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
USWIndex[USWQuery] = (await download(URLS.uswSearch + USWQuery, {responseType: 'json'}));
|
||||||
|
clearTimeout(timer);
|
||||||
|
$remove(':scope > .lds-spinner', dom.list);
|
||||||
|
return USWIndex[USWQuery];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function search({retry, searchUserStylesWorld} = {}) {
|
||||||
return retry && !calcCategory({retry})
|
return retry && !calcCategory({retry})
|
||||||
? []
|
? []
|
||||||
|
: searchUserStylesWorld
|
||||||
|
? (USWIndex[query.join(' ')] || await searchUSW() || []).sort(comparator)
|
||||||
: (index || await fetchIndex()).filter(isResultMatching).sort(comparator);
|
: (index || await fetchIndex()).filter(isResultMatching).sort(comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,6 +650,10 @@
|
||||||
URLS.extractUsoArchiveId(updateUrl);
|
URLS.extractUsoArchiveId(updateUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function calcUSwId({installationUrl}) {
|
||||||
|
return installationUrl ? installationUrl.match(/\d+|$/)[0] : 0;
|
||||||
|
}
|
||||||
|
|
||||||
function calcHaystack(res) {
|
function calcHaystack(res) {
|
||||||
if (!res._nLC) res._nLC = res.n.toLocaleLowerCase();
|
if (!res._nLC) res._nLC = res.n.toLocaleLowerCase();
|
||||||
if (!res._year) res._year = new Date(res.u * 1000).getFullYear();
|
if (!res._year) res._year = new Date(res.u * 1000).getFullYear();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user