code cosmetics
This commit is contained in:
parent
1d9ec09d62
commit
866f54c307
|
@ -39,7 +39,6 @@ window.addEventListener('showStyles:done', function _() {
|
||||||
const BLANK_PIXEL_DATA = 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAA' +
|
const BLANK_PIXEL_DATA = 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAA' +
|
||||||
'C1HAwCAAAAC0lEQVR42mOcXQ8AAbsBHLLDr5MAAAAASUVORK5CYII=';
|
'C1HAwCAAAAC0lEQVR42mOcXQ8AAbsBHLLDr5MAAAAASUVORK5CYII=';
|
||||||
|
|
||||||
// TODO: add -
|
|
||||||
const CACHE_SIZE = 1e6;
|
const CACHE_SIZE = 1e6;
|
||||||
const CACHE_PREFIX = 'usoSearchCache/';
|
const CACHE_PREFIX = 'usoSearchCache/';
|
||||||
const CACHE_DURATION = 24 * 3600e3;
|
const CACHE_DURATION = 24 * 3600e3;
|
||||||
|
@ -87,7 +86,6 @@ window.addEventListener('showStyles:done', function _() {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
document.body.style.setProperty('transition', 'background-color 1s', 'important');
|
|
||||||
setTimeout(() => document.body.classList.add(BODY_CLASS));
|
setTimeout(() => document.body.classList.add(BODY_CLASS));
|
||||||
|
|
||||||
$('#find-styles-inline-group').classList.add('hidden');
|
$('#find-styles-inline-group').classList.add('hidden');
|
||||||
|
@ -573,27 +571,20 @@ window.addEventListener('showStyles:done', function _() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the JSON style object from userstyles.org (containing code, sections, updateUrl, etc).
|
* Fetches the JSON style object from userstyles.org (containing code, sections, updateUrl, etc).
|
||||||
* Stores (caches) the JSON within the given usoSearchResult, to avoid unnecessary network usage.
|
* Stores (caches) the JSON within the given result, to avoid unnecessary network usage.
|
||||||
* Style JSON is fetched from the /styles/chrome/{id}.json endpoint.
|
* Style JSON is fetched from the /styles/chrome/{id}.json endpoint.
|
||||||
* @param {Object} usoSearchResult A search result object from userstyles.org
|
* @param {Object} result A search result object from userstyles.org
|
||||||
* @returns {Promise<Object>} Promises the response as a JSON object.
|
* @returns {Promise<Object>} Promises the response as a JSON object.
|
||||||
*/
|
*/
|
||||||
function fetchStyleJson(usoSearchResult) {
|
function fetchStyleJson(result) {
|
||||||
return new Promise((resolve, reject) => {
|
return Promise.resolve(
|
||||||
if (usoSearchResult.json) {
|
result.json ||
|
||||||
// JSON already downloaded & stored.
|
download(BASE_URL + '/styles/chrome/' + result.id + '.json', {
|
||||||
resolve(usoSearchResult.json);
|
responseType: 'json',
|
||||||
}
|
}).then(json => {
|
||||||
|
result.json = json;
|
||||||
const jsonUrl = BASE_URL + '/styles/chrome/' + usoSearchResult.id + '.json';
|
return json;
|
||||||
download(jsonUrl)
|
}));
|
||||||
.then(responseText => {
|
|
||||||
// Store JSON within the search result, so we don't have to download again.
|
|
||||||
usoSearchResult.json = tryJSONparse(responseText);
|
|
||||||
resolve(usoSearchResult.json);
|
|
||||||
})
|
|
||||||
.catch(reject);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user