Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
AdeelH committed Mar 5, 2023
1 parent c0b618b commit 8453584
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
"48": "icon-48.png",
"16": "icon-16.png"
}
}
}
2 changes: 1 addition & 1 deletion options.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ <h3 class="option-section-heading">Caching</h3>
<script src="options.js" type="module"></script>
</body>

</html>
</html>
8 changes: 4 additions & 4 deletions options.js
Original file line number Diff line number Diff line change
@@ -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);

Expand Down Expand Up @@ -40,7 +40,7 @@ async function saveOptions() {
};
try {
await updateOptions(options);
} catch(e) {
} catch (e) {
notifyFailure();
}
notifySuccess();
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@
<iframe id="tFrame" class="hidden" src="template.html"></iframe>
</body>

</html>
</html>
32 changes: 16 additions & 16 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getOptions, getCurrentTabUrl, navigateTo} 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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ function setSearchDefaults(opts) {
}

function setUiState(state, params = null) {
switch(state) {
switch (state) {
case 'SEARCH_BEGIN': {
DOM.statusDiv.text('Searching ...'); break;
}
Expand Down
14 changes: 7 additions & 7 deletions reddit.js
Original file line number Diff line number Diff line change
@@ -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=';
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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] = {
Expand All @@ -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;
}
8 changes: 4 additions & 4 deletions template.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
<script src="js/jquery.min.js"></script>
<script>
Handlebars.registerHelper('selected', function(val, options) {
let div = $('<div>').html(options.fn(this));
div.find(`[value=${val}]`).attr('selected', true);
return div.html();
let div = $('<div>').html(options.fn(this));
div.find(`[value=${val}]`).attr('selected', true);
return div.html();
});

Handlebars.registerHelper('pluralize', function(str, n) {
Expand All @@ -81,7 +81,7 @@
let template = Handlebars.compile($('#search-results-template').html());
window.addEventListener('message', evt => {
evt.source.postMessage(
{html: template(evt.data.context)},
{ html: template(evt.data.context) },
evt.origin
);
});
Expand Down

0 comments on commit 8453584

Please sign in to comment.