diff --git a/chrome.js b/chrome.js index b181407..93c07c9 100644 --- a/chrome.js +++ b/chrome.js @@ -53,7 +53,7 @@ export function updateOptions(data) { export function getOptions(query) { return new Promise((resolve, reject) => { - chrome.storage.sync.get({options: query}, data => resolve(data.options)); + chrome.storage.sync.get({ options: query }, data => resolve(data.options)); }); } diff --git a/manifest.json b/manifest.json index 9842940..e1126a7 100644 --- a/manifest.json +++ b/manifest.json @@ -33,4 +33,4 @@ "48": "icon-48.png", "16": "icon-16.png" } -} \ No newline at end of file +} diff --git a/options.html b/options.html index 7f479c8..cbd9a34 100644 --- a/options.html +++ b/options.html @@ -202,4 +202,4 @@

Caching

- \ No newline at end of file + diff --git a/options.js b/options.js index 08d076a..793c7c1 100644 --- a/options.js +++ b/options.js @@ -1,5 +1,5 @@ -import {getOptions, updateOptions} from './chrome.js'; -import {allOptions} from './query.js'; +import { getOptions, updateOptions } from './chrome.js'; +import { allOptions } from './query.js'; $(document).ready(init); @@ -40,7 +40,7 @@ async function saveOptions() { }; try { await updateOptions(options); - } catch(e) { + } catch (e) { notifyFailure(); } notifySuccess(); @@ -52,7 +52,7 @@ async function restoreOptions() { console.log(opts); DOM.opts.oldReddit.prop('checked', opts.oldReddit); - + DOM.opts.exactMatch.prop('checked', opts.search.exactMatch); DOM.opts.ignoreQs.prop('checked', opts.search.ignoreQs); DOM.opts.ytHandling.prop('checked', opts.search.ytHandling); diff --git a/popup.html b/popup.html index 7896d48..32208ef 100644 --- a/popup.html +++ b/popup.html @@ -66,4 +66,4 @@ - \ No newline at end of file + diff --git a/popup.js b/popup.js index e2106df..e8189fa 100644 --- a/popup.js +++ b/popup.js @@ -1,7 +1,7 @@ -import {getOptions, getCurrentTabUrl} from './chrome.js'; -import {processUrl, isYoutubeUrl, getYoutubeVideoId} from './url.js'; -import {findOnReddit} from './reddit.js'; -import {popupDefaults} from './query.js'; +import { getOptions, getCurrentTabUrl, navigateTo } from './chrome.js'; +import { processUrl, isYoutubeUrl, getYoutubeVideoId } from './url.js'; +import { findOnReddit } from './reddit.js'; +import { popupDefaults } from './query.js'; // DOM handles let DOM; @@ -77,7 +77,7 @@ function registerHandlers(opts) { } }); - DOM.opts.ytCheckbox.change(function(e) { + DOM.opts.ytCheckbox.change(function(e) { if (this.checked) { setUiState('YT_VID'); } else { @@ -156,18 +156,18 @@ function onRequestError(error, userClicked = false) { return; } retry_countdown -= 1; - setUiState('AJAX_ERROR', {msg: error.statusText, delay: retry_countdown}); + setUiState('AJAX_ERROR', { msg: error.statusText, delay: retry_countdown }); setTimeout(() => onRequestError(error, userClicked), 1e3); } -/* post age calculation */ +/* post age calculation */ const timeUnits = [ - {factor: 1/(1e3), name: 'seconds', decis: 0}, - {factor: 1/(1e3*60), name: 'minutes', decis: 0}, - {factor: 1/(1e3*60*60), name: 'hours', decis: 0}, - {factor: 1/(1e3*60*60*24), name: 'days', decis: 0}, - {factor: 1/(1e3*60*60*24*30), name: 'months', decis: 0}, - {factor: 1/(1e3*60*60*24*30*12), name: 'years', decis: 1} + { factor: 1 / (1e3), name: 'seconds', decis: 0 }, + { factor: 1 / (1e3 * 60), name: 'minutes', decis: 0 }, + { factor: 1 / (1e3 * 60 * 60), name: 'hours', decis: 0 }, + { factor: 1 / (1e3 * 60 * 60 * 24), name: 'days', decis: 0 }, + { factor: 1 / (1e3 * 60 * 60 * 24 * 30), name: 'months', decis: 0 }, + { factor: 1 / (1e3 * 60 * 60 * 24 * 30 * 12), name: 'years', decis: 1 } ]; function calcAge(timestampSeconds) { let diffMillis = Date.now() - (timestampSeconds * 1e3); @@ -189,12 +189,12 @@ let fieldMappings = Object.freeze({ function sortPosts(posts, orderBy = 'score', desc = true) { if (orderBy == 'subreddit') { - return posts.sort((a, b) => + return posts.sort((a, b) => a.data.subreddit.localeCompare(b.data.subreddit) * (2 * desc - 1) ); } let field = fieldMappings[orderBy]; - let comparator = (a, b) => + let comparator = (a, b) => (a.data[field] - b.data[field]) * (1 - 2 * desc); return posts.sort(comparator); } @@ -242,7 +242,7 @@ function setSearchDefaults(opts) { } function setUiState(state, params = null) { - switch(state) { + switch (state) { case 'SEARCH_BEGIN': { DOM.statusDiv.text('Searching ...'); break; } diff --git a/reddit.js b/reddit.js index 2b33e25..d267445 100644 --- a/reddit.js +++ b/reddit.js @@ -1,5 +1,5 @@ -import {getOptions, searchCache, cache, ignoreRejection} from './chrome.js'; -import {DEFAULT_CACHE_PERIOD_MINS} from './query.js'; +import { getOptions, searchCache, cache, ignoreRejection } from './chrome.js'; +import { DEFAULT_CACHE_PERIOD_MINS } from './query.js'; export const SEARCH_API = 'https://api.reddit.com/search.json?sort=top&t=all&limit=100&q=url:'; export const INFO_API = 'https://reddit.com/api/info.json?url='; @@ -38,7 +38,7 @@ export async function search(query, useCache = true, exact = true) { } else { let posts = await getPostsViaApi(requestUrl); if (otherResults) { - posts.other = otherResults.posts.length + posts.other = otherResults.posts.length; } return posts; } @@ -60,7 +60,7 @@ export async function add_duplicates(posts) { return posts; } let all_ids = new Set(posts.map((p) => p.data.id)); - let id = posts[0].data.id + let id = posts[0].data.id; let duplicates = await get_duplicates_for_id(id); let newPosts = duplicates.filter(p => !all_ids.has(p.data.id)); let expandedPosts = posts.concat(newPosts); @@ -71,7 +71,7 @@ export async function get_duplicates_for_id(post_id) { const requestUrl = `${DUPLICATES_API}${post_id}`; // the duplicates API endpoint returns an array of 2, the 2nd element of // which contains the duplicate posts - const res = await makeApiRequest(requestUrl) + const res = await makeApiRequest(requestUrl); const posts = (res.length > 1) ? res[1].data.children : []; return posts; } @@ -84,7 +84,7 @@ export async function makeApiRequest(url) { export async function cachePosts(query, posts, exact) { const key = exact ? 'exact' : 'nonExact'; const old_cache = await searchCache(query); - + let objectToStore = {}; let data = old_cache[query] || {}; data[key] = { @@ -106,6 +106,6 @@ export async function checkCacheValidity(cache, key) { const diff = Date.now() - data.time; const query = { cache: { period: DEFAULT_CACHE_PERIOD_MINS } }; const opts = await getOptions(query); - const not_expired = diff < +(opts.cache.period) * 60000 + const not_expired = diff < +(opts.cache.period) * 60000; return not_expired; } diff --git a/template.html b/template.html index 003dc2d..34da0db 100644 --- a/template.html +++ b/template.html @@ -69,9 +69,9 @@