Rename searchResults -> search-results, replaced double quotes with single-quotes
This commit is contained in:
parent
b3a6bddd48
commit
c9e894f670
|
@ -3,7 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
|
||||||
<link rel="stylesheet" href="popup/popup.css">
|
<link rel="stylesheet" href="popup/popup.css">
|
||||||
<link rel="stylesheet" href="popup/searchResults.css">
|
<link rel="stylesheet" href="popup/search-results.css">
|
||||||
|
|
||||||
<style id="firefox-transitions-bug-suppressor">
|
<style id="firefox-transitions-bug-suppressor">
|
||||||
/* restrict to FF */
|
/* restrict to FF */
|
||||||
|
@ -101,7 +101,7 @@
|
||||||
<script src="js/prefs.js"></script>
|
<script src="js/prefs.js"></script>
|
||||||
<script src="content/apply.js"></script>
|
<script src="content/apply.js"></script>
|
||||||
<script src="popup/popup.js"></script>
|
<script src="popup/popup.js"></script>
|
||||||
<script src="popup/searchResults.js"></script>
|
<script src="popup/search-results.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body id="stylus-popup">
|
<body id="stylus-popup">
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
* @returns {Object} Includes fetch() method which promises userstyles.org resources.
|
* @returns {Object} Includes fetch() method which promises userstyles.org resources.
|
||||||
*/
|
*/
|
||||||
const UserStylesAPI = (() => {
|
const UserStylesAPI = (() => {
|
||||||
return {fetch}
|
return {fetch};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches (and JSON-parses) the result from a userstyles.org API
|
* Fetches (and JSON-parses) the result from a userstyles.org API
|
||||||
* @param {string} path Path on userstyles.org (e.g. "/api/v1/styles/search")
|
* @param {string} path Path on userstyles.org (e.g. '/api/v1/styles/search')
|
||||||
* @param {string} queryParams Query parameters to send in search request (e.g. "key=value&name=that)".
|
* @param {string} queryParams Query parameters to send in search request (e.g. 'key=value&name=that)'.
|
||||||
* @return {Object} Response object from userstyles.org
|
* @return {Object} Response object from userstyles.org
|
||||||
*/
|
*/
|
||||||
function fetch(path, queryParams) {
|
function fetch(path, queryParams) {
|
||||||
|
@ -22,7 +22,7 @@ const UserStylesAPI = (() => {
|
||||||
};
|
};
|
||||||
let url = 'https://userstyles.org' + path;
|
let url = 'https://userstyles.org' + path;
|
||||||
if (queryParams) {
|
if (queryParams) {
|
||||||
url += "?" + queryParams;
|
url += '?' + queryParams;
|
||||||
}
|
}
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.timeout = TIMEOUT;
|
xhr.timeout = TIMEOUT;
|
||||||
|
@ -31,10 +31,10 @@ const UserStylesAPI = (() => {
|
||||||
try {
|
try {
|
||||||
resolve(JSON.parse(xhr.responseText));
|
resolve(JSON.parse(xhr.responseText));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject("Failed to parse JSON from " + url + "\nJSON Text: " + xhr.responseText);
|
reject('Failed to parse JSON from ' + url + '\nJSON Text: ' + xhr.responseText);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
reject("Error code " + xhr.status);
|
reject('Error code ' + xhr.status);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
xhr.onerror = reject;
|
xhr.onerror = reject;
|
||||||
|
@ -64,13 +64,13 @@ const SearchResults = (() => {
|
||||||
function load(event) {
|
function load(event) {
|
||||||
if (event) event.preventDefault();
|
if (event) event.preventDefault();
|
||||||
// Clear search results
|
// Clear search results
|
||||||
$('#searchResults-list').innerHTML = "";
|
$('#searchResults-list').innerHTML = '';
|
||||||
// Find styles for the current active tab
|
// Find styles for the current active tab
|
||||||
getActiveTab().then(tab => {
|
getActiveTab().then(tab => {
|
||||||
$('#load-search-results').classList.add("hidden");
|
$('#load-search-results').classList.add('hidden');
|
||||||
$('#searchResults').classList.remove("hidden");
|
$('#searchResults').classList.remove('hidden');
|
||||||
|
|
||||||
const hostname = new URL(tab.url).hostname.replace(/^(?:.*\.)?([^.]*\.(co\.)?[^.]*)$/i, "$1");
|
const hostname = new URL(tab.url).hostname.replace(/^(?:.*\.)?([^.]*\.(co\.)?[^.]*)$/i, '$1');
|
||||||
$('#searchResults-terms').textContent = hostname;
|
$('#searchResults-terms').textContent = hostname;
|
||||||
|
|
||||||
const queryParams = [
|
const queryParams = [
|
||||||
|
@ -78,7 +78,7 @@ const SearchResults = (() => {
|
||||||
'page=' + currentPage,
|
'page=' + currentPage,
|
||||||
'per_page=3'
|
'per_page=3'
|
||||||
].join('&');
|
].join('&');
|
||||||
UserStylesAPI.fetch("/api/v1/styles/search", queryParams)
|
UserStylesAPI.fetch('/api/v1/styles/search', queryParams)
|
||||||
.then(searchResults => {
|
.then(searchResults => {
|
||||||
/*
|
/*
|
||||||
searchResults: {
|
searchResults: {
|
||||||
|
@ -90,16 +90,16 @@ const SearchResults = (() => {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if (searchResults.data.length === 0) {
|
if (searchResults.data.length === 0) {
|
||||||
throw "No results found";
|
throw 'No results found';
|
||||||
}
|
}
|
||||||
currentPage = searchResults.current_page;
|
currentPage = searchResults.current_page;
|
||||||
updateSearchResultsNav(searchResults.current_page, searchResults.total_pages);
|
updateSearchResultsNav(searchResults.current_page, searchResults.total_pages);
|
||||||
searchResults.data.forEach(createSearchResult);
|
searchResults.data.forEach(createSearchResult);
|
||||||
})
|
})
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
$('#load-search-results').classList.remove("hidden");
|
$('#load-search-results').classList.remove('hidden');
|
||||||
$('#searchResults').classList.add("hidden");
|
$('#searchResults').classList.add('hidden');
|
||||||
alert("Error while loading search results: " + reason);
|
alert('Error while loading search results: ' + reason);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
|
@ -189,8 +189,8 @@ const SearchResults = (() => {
|
||||||
// TODO: Expand/collapse description
|
// TODO: Expand/collapse description
|
||||||
const description = $('.searchResult-description', entry);
|
const description = $('.searchResult-description', entry);
|
||||||
Object.assign(description, {
|
Object.assign(description, {
|
||||||
textContent: userstyleSearchResult.description.replace(/<.*?>/g, ""),
|
textContent: userstyleSearchResult.description.replace(/<.*?>/g, ''),
|
||||||
title: userstyleSearchResult.description.replace(/<.*?>/g, "")
|
title: userstyleSearchResult.description.replace(/<.*?>/g, '')
|
||||||
});
|
});
|
||||||
|
|
||||||
const authorLink = $('.searchResult-authorLink', entry);
|
const authorLink = $('.searchResult-authorLink', entry);
|
||||||
|
@ -212,10 +212,10 @@ const SearchResults = (() => {
|
||||||
|
|
||||||
/** Installs the current userstyleSearchResult into stylus. */
|
/** Installs the current userstyleSearchResult into stylus. */
|
||||||
function install(event) {
|
function install(event) {
|
||||||
UserStylesAPI.fetch("/api/v1/styles/" + userstyleSearchResult.id)
|
UserStylesAPI.fetch('/api/v1/styles/' + userstyleSearchResult.id)
|
||||||
.then(styleObject => {
|
.then(styleObject => {
|
||||||
console.log("TODO: Install style ID", userstyleSearchResult.id);
|
console.log('TODO: Install style ID', userstyleSearchResult.id);
|
||||||
console.log("Full styleObject:", styleObject);
|
console.log('Full styleObject:', styleObject);
|
||||||
/*
|
/*
|
||||||
* FIXME
|
* FIXME
|
||||||
* Sample full styleObject: https://userstyles.org/api/v1/styles/70271
|
* Sample full styleObject: https://userstyles.org/api/v1/styles/70271
|
||||||
|
@ -233,11 +233,11 @@ const SearchResults = (() => {
|
||||||
notify: true
|
notify: true
|
||||||
});
|
});
|
||||||
saveStyleSafe(styleObject);
|
saveStyleSafe(styleObject);
|
||||||
alert("TODO: Install style ID #" + userstyleSearchResult.id + " name '" + userstyleSearchResult.name + "'");
|
alert('TODO: Install style ID #' + userstyleSearchResult.id + ' name "' + userstyleSearchResult.name + '"');
|
||||||
})
|
})
|
||||||
.catch(reason => {
|
.catch(reason => {
|
||||||
console.log("Error during installation:", reason);
|
console.log('Error during installation:', reason);
|
||||||
alert("Error installing style: " + reason);
|
alert('Error installing style: ' + reason);
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user