From 1b53169f57369caf4343d1892025250704d850a9 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Sat, 19 Mar 2016 14:30:47 -0400 Subject: [PATCH] lint --- src/auth.js | 22 +++++++++++----------- src/content.js | 10 +++++----- src/options.js | 12 ++++++------ src/storage.js | 1 + 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/auth.js b/src/auth.js index 030cfb8..dd5e3bf 100644 --- a/src/auth.js +++ b/src/auth.js @@ -1,10 +1,10 @@ +/* global chrome, queryString, getSyncStorage, setSyncStorage */ + const client_id = "1a3ac4d44a9e65a75a77"; const client_secret = "ab3c3a116e35d9fe11d409cb8c1205e9ae5a7e91"; const githubBaseUrl = "https://github.com/login/oauth/authorize"; const githubTokenUrl = "https://github.com/login/oauth/access_token"; -const redirectUri = chrome.identity.getRedirectURL('provider_cb'); - -console.log(redirectUri); +const redirectUri = chrome.identity.getRedirectURL("provider_cb"); const getAuthUrl = (base, callbackUrl, scope) => { let obj = { @@ -15,7 +15,7 @@ const getAuthUrl = (base, callbackUrl, scope) => { }; return `${base}?${queryString.stringify(obj)}`; -} +}; function getTokenFromCode(code) { let obj = { @@ -25,7 +25,7 @@ function getTokenFromCode(code) { }; return fetch(`${githubTokenUrl}?${queryString.stringify(obj)}`) - .then((res) => res.text(), (err) => { + .then((res) => res.text(), () => { throw new Error("Failed to get access_token"); }); } @@ -62,29 +62,29 @@ function getToken(url, interactive) { resolve(access_token); }); } else { - reject(new Error ('neither access_token nor code available')); + reject(new Error ("neither access_token nor code available")); } } else { - reject(new Error('Invalid redirect URI')); + reject(new Error("Invalid redirect URI")); } }); }); } function getTokenFromOauth() { - getSyncStorage({ 'access_token': null }) + getSyncStorage({ "access_token": null }) .then((res) => { if (!res.access_token) { - const url = getAuthUrl(githubBaseUrl, redirectUri, 'public_repo'); + const url = getAuthUrl(githubBaseUrl, redirectUri, "public_repo"); getToken(url, true) .then((token) => { - setSyncStorage({ 'access_token': token }); + setSyncStorage({ "access_token": token }); const accessTokenInput = document.getElementById("token-input"); accessTokenInput.value = token; document.querySelector("#feedback").textContent = "Access Token Set!"; }, (message) => { document.querySelector("#feedback").textContent = message; - }) + }); } else { document.querySelector("#feedback").textContent = "Access Token Already Set!"; } diff --git a/src/content.js b/src/content.js index 87ab85c..396dfe4 100644 --- a/src/content.js +++ b/src/content.js @@ -1,11 +1,11 @@ "use strict"; -/* global chrome, getSyncStorage, setStorage, getStorage */ +/* global $, getSyncStorage, setStorage, getStorage, gitHubInjection */ const isPR = (path) => /^\/[^/]+\/[^/]+\/pull\/\d+/.test(path); const isIssue = (path) => /^\/[^/]+\/[^/]+\/issues\/\d+/.test(path); -const getCurrentUser = () => $('.js-menu-target img').attr('alt').slice(1) || ""; -const isPrivate = () => $('.repo-private-label').length > 0; +const getCurrentUser = () => $(".js-menu-target img").attr("alt").slice(1) || ""; +const isPrivate = () => $(".repo-private-label").length > 0; function getContributor() { let $contributor = $(".timeline-comment-wrapper .timeline-comment-header-text strong"); @@ -24,7 +24,7 @@ function getContributorInfo() { let contributor = getContributor(); let ret = { - contributor: getContributor(), + contributor, currentNum, repoPath }; @@ -217,6 +217,6 @@ document.addEventListener("DOMContentLoaded", () => { if (getContributor()) { update(getContributorInfo()); } - }; + } }); }); diff --git a/src/options.js b/src/options.js index ec8f13a..d256c9d 100644 --- a/src/options.js +++ b/src/options.js @@ -1,4 +1,4 @@ -/* global getSyncStorage, setSyncStorage */ +/* global getSyncStorage, setSyncStorage, clearSyncStorage, getTokenFromOauth */ document.addEventListener("DOMContentLoaded", () => { const accessTokenInput = document.getElementById("token-input"); @@ -16,15 +16,15 @@ document.addEventListener("DOMContentLoaded", () => { oauthLink.addEventListener("click", () => { getTokenFromOauth(); - }) + }); clearCacheLink.addEventListener("click", () => { - let temp = accessTokenInput.value - chrome.storage.sync.clear((res) => { + let temp = accessTokenInput.value; + clearSyncStorage() + .then(() => { setSyncStorage({ "access_token": temp }); - document.querySelector("#feedback").textContent = "Storage Cleared"; }); - }) + }); }); diff --git a/src/storage.js b/src/storage.js index 200abca..542abc9 100644 --- a/src/storage.js +++ b/src/storage.js @@ -25,6 +25,7 @@ function promisify(func) { window.getSyncStorage = promisify(chrome.storage.sync.get.bind(chrome.storage.sync)); window.setSyncStorage = promisify(chrome.storage.sync.set.bind(chrome.storage.sync)); +window.clearSyncStorage = promisify(chrome.storage.sync.clear.bind(chrome.storage.sync)); window.setStorage = (CONTRIBUTOR, ORG_REPO_PATH, value) => { return window.setSyncStorage({