From 7898148cfc328d9e6f6b6ca5f58d842200657463 Mon Sep 17 00:00:00 2001 From: Carl Gorringe Date: Tue, 13 Aug 2024 14:42:00 -0700 Subject: [PATCH] eslint formatting fixes --- .eslintrc.json | 6 ++++-- webextension/manifest.json | 4 ++-- webextension/scripts/background.js | 19 +++++-------------- webextension/scripts/utils.js | 11 +++++------ 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index dccecea0..8cf32b46 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,7 +2,8 @@ "extends": "standard", "env": { "browser": true, - "webextensions": true + "webextensions": true, + "worker": true }, "rules": { "indent": ["warn", 2, { "SwitchCase": 1, "MemberExpression": "off" }], @@ -13,7 +14,8 @@ "quote-props": "off", "one-var": "off", "padded-blocks": "off", - "dot-notation": "off" + "dot-notation": "off", + "semi": "off" }, "globals": { "$": "readonly" diff --git a/webextension/manifest.json b/webextension/manifest.json index ef37f7c5..f80f6579 100644 --- a/webextension/manifest.json +++ b/webextension/manifest.json @@ -33,7 +33,7 @@ "scripting", "webRequest" ], - "host_permissions":[ + "host_permissions": [ "https://archive.org/*", "https://*.archive.org/*", "https://hypothes.is/*", @@ -54,7 +54,7 @@ } ], "web_accessible_resources": [{ - "resources":[ "/css/archive.css","/images/*"], + "resources": ["/css/archive.css", "/images/*"], "matches": [""] }] } diff --git a/webextension/scripts/background.js b/webextension/scripts/background.js index 51dea602..f99bba0b 100644 --- a/webextension/scripts/background.js +++ b/webextension/scripts/background.js @@ -10,7 +10,7 @@ if (typeof importScripts === 'function') { // from 'utils.js' /* global isNotExcludedUrl, getCleanUrl, isArchiveUrl, isValidUrl, notifyMsg, openByWindowSetting, sleep, wmAvailabilityCheck, hostURL */ /* global initDefaultOptions, badgeCountText, getWaybackCount, newshosts, dateToTimestamp, fixedEncodeURIComponent, checkLastError */ -/* global hostHeaders, gCustomUserAgent, timestampToDate, isBadgeOnTop, isUrlInList, getTabKey, saveTabData, readTabData, initAutoExcludeList */ +/* global hostHeaders, timestampToDate, isBadgeOnTop, isUrlInList, saveTabData, clearTabData, readTabData, initAutoExcludeList */ /* global isDevVersion, checkAuthentication, setupContextMenus, cropPrefix, alertMsg */ let globalAPICache = new Map() @@ -333,7 +333,7 @@ function fetchAPI(url, onSuccess, onFail, postData = null) { * @param postData {object}: uses POST if present. * @return Promise if calls API, json data if in cache, null if loading in progress. */ - function fetchCachedAPI(url, onSuccess, onFail, postData = null) { +function fetchCachedAPI(url, onSuccess, onFail, postData = null) { if (typeof globalAPICache === 'undefined') { globalAPICache = new Map() } let data = globalAPICache.get(url) if (data === API_LOADING) { @@ -1029,7 +1029,7 @@ function clearCountCache() { * Doesn't update if cached "total" value was < 0. * @param url {string} */ - function incrementCount(url) { +function incrementCount(url) { // Retrieve the waybackCountCache object from chrome.storage chrome.storage.session.get(['waybackCountCache'], (result) => { if (chrome.runtime.lastError) { @@ -1068,7 +1068,6 @@ function clearCountCache() { }); } - function updateWaybackCountBadge(atab, url) { if (!atab) { return } chrome.storage.local.get(['wm_count_setting'], (settings) => { @@ -1125,31 +1124,26 @@ function setToolbarIcon(name, tabId = null) { async function addToolbarState(atab, state) { if (!atab) { return } - let tabKey = getTabKey(atab); let data = await readTabData(atab); let tbStates = toolbarStateFromTabData(data); if (!tbStates.has(state)) { // only save state if not already in set tbStates.add(state); - tbStatesArray = Array.from(tbStates); - await saveTabData(atab, { states: tbStatesArray }); + await saveTabData(atab, { states: Array.from(tbStates) }); } updateToolbar(atab, tbStates); } - // Remove state from the state set for given Tab, and update toolbar. async function removeToolbarState(atab, state) { if (!atab) { return } - let tabKey = getTabKey(atab); let data = await readTabData(atab); let tbStates = toolbarStateFromTabData(data); if (tbStates.has(state)) { // only save state if state to remove was in set tbStates.delete(state); - tbStatesArray = Array.from(tbStates); - await saveTabData(atab, { states: tbStatesArray }); + await saveTabData(atab, { states: Array.from(tbStates) }); } updateToolbar(atab, tbStates); } @@ -1177,12 +1171,10 @@ async function getToolbarState(atab) { async function clearToolbarState(atab) { if (!atab) { return } - const tabKey = getTabKey(atab); await clearTabData(atab, ['states']); updateToolbar(atab, null); } - /** * Updates the toolbar icon using the Set of states provided. * Only updates icon if atab is the currently active tab, else does nothing. @@ -1214,7 +1206,6 @@ function updateToolbar(atab, states) { }); } - /* * * Right-click Menu * * */ // Right-click context menu "Wayback Machine" inside the page. diff --git a/webextension/scripts/utils.js b/webextension/scripts/utils.js index 89727439..cbc7a520 100644 --- a/webextension/scripts/utils.js +++ b/webextension/scripts/utils.js @@ -166,7 +166,7 @@ function getUserInfo() { } }) .catch((e) => { - console.log("getUserInfo ERROR: ", e) + console.log('getUserInfo ERROR: ', e) }) } @@ -385,7 +385,7 @@ function wmAvailabilityCheck(url, onsuccess, onfail) { }) .catch((err) => { // catch the error in case of api failure - console.log("wmAvailabilityCheck ERROR: ", err) + console.log('wmAvailabilityCheck ERROR: ', err) }) } @@ -675,9 +675,8 @@ function opener(url, option, callback) { } }) } else { - - chrome.windows.getCurrent({populate: true}, (window) => { - // Access window properties + chrome.windows.getCurrent({ populate: true }, (window) => { + // Access window properties let h = window.width; let w = window.height; if (w > h) { @@ -731,7 +730,7 @@ function checkLastError() { if (chrome.runtime.lastError.message.startsWith('No tab with id:')) { // Skip } else { - console.log("checkLastError: ", chrome.runtime.lastError.message) + console.log('checkLastError: ', chrome.runtime.lastError.message) // console.trace() // uncomment while debugging } } else {