Skip to content

Commit

Permalink
run lint with --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-p committed Apr 25, 2018
1 parent b62f914 commit a593fff
Show file tree
Hide file tree
Showing 105 changed files with 2,749 additions and 2,810 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
},
"env": {
"webextensions": true,
"browser": true
"browser": true,
"jasmine": true
}
}
31 changes: 15 additions & 16 deletions shared/js/background/abp-lists.es6.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Load the abp-filter-parser node module and
* Load the abp-filter-parser node module and
* pre-process the easylists.
*
* This will be browserifyed and turned into abp.js by running 'grunt'
Expand All @@ -14,10 +14,10 @@ const ATB = require('./atb.es6')
const load = require('./load.es6')
const browserWrapper = require('./$BROWSER-wrapper.es6')

const ONEDAY = 1000*60*60*24
const ONEDAY = 1000 * 60 * 60 * 24

let lists = {
easylists : {
easylists: {
privacy: {
constantsName: 'privacyEasylist',
parser: abp,
Expand Down Expand Up @@ -52,8 +52,8 @@ let lists = {

var trackersWhitelistTemporary

function getTemporaryWhitelist() {
return trackersWhitelistTemporary;
function getTemporaryWhitelist () {
return trackersWhitelistTemporary
}

function getEasylists () {
Expand All @@ -66,7 +66,7 @@ function getWhitelists () {

/*
* Get the list data and use abp to parse.
* The parsed list data will be added to
* The parsed list data will be added to
* the easyLists object.
*/
function updateLists () {
Expand All @@ -76,17 +76,16 @@ function updateLists () {

for (let listType in lists) {
for (let name in lists[listType]) {

const list = lists[listType][name]
const constantsName = list.constantsName

let url = constants[constantsName]
if (!url) return
if (!url) return

let etag = settings.getSetting(constantsName + '-etag') || ''

// only add url params to contentblocking.js duckduckgo urls
if(url.match(/^https?:\/\/(.+)?duckduckgo.com\/contentblocking\.js/)) {
if (url.match(/^https?:\/\/(.+)?duckduckgo.com\/contentblocking\.js/)) {
if (atb) url += '&atb=' + atb
if (set_atb) url += '&set_atb=' + set_atb
if (versionParam) url += versionParam
Expand All @@ -97,14 +96,14 @@ function updateLists () {
// if we don't have parsed list data skip the etag to make sure we
// get a fresh copy of the list to process
if (Object.keys(list.parsed).length === 0) etag = ''

load.loadExtensionFile({url: url, source: 'external', etag: etag}, (listData, response) => {
const newEtag = response.getResponseHeader('etag') || ''
console.log('Updating list: ', name)

// sync new etag to storage
settings.updateSetting(constantsName + '-etag', newEtag)

list.parser.parse(listData, list.parsed)

list.isLoaded = true
Expand All @@ -120,7 +119,7 @@ function updateLists () {
// source: https://github.com/duckduckgo/content-blocking-whitelist/blob/master/trackers-whitelist-temporary.txt
load.loadExtensionFile({url: constants.trackersWhitelistTemporary, etag: trackersWhitelistTemporaryEtag, source: 'external'}, (listData, response) => {
const newTrackersWhitelistTemporaryEtag = response.getResponseHeader('etag') || ''
settings.updateSetting('trackersWhitelistTemporary-etag', newTrackersWhitelistTemporaryEtag);
settings.updateSetting('trackersWhitelistTemporary-etag', newTrackersWhitelistTemporaryEtag)

trackersWhitelistTemporary = listData.trim().split('\n')
})
Expand All @@ -141,7 +140,7 @@ function getVersionParam () {
// not exist then this is the initial install
if (lastEasylistUpdate) {
let delta = now - new Date(lastEasylistUpdate)

if (delta > ONEDAY) {
versionParam = `&v=${version}`
}
Expand Down
44 changes: 20 additions & 24 deletions shared/js/background/atb.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ var ATB = (() => {
let atbSetting = settings.getSetting('atb'),
setAtbSetting = settings.getSetting('set_atb')

if(!atbSetting || !setAtbSetting)
resolve(null)
if (!atbSetting || !setAtbSetting) { resolve(null) }

ATB.getSetAtb(atbSetting, setAtbSetting).then((newAtb) => {
if(newAtb !== setAtbSetting){
if (newAtb !== setAtbSetting) {
settings.updateSetting('set_atb', newAtb)
}
resolve(newAtb)
Expand All @@ -29,9 +28,9 @@ var ATB = (() => {
return new Promise((resolve) => {
var xhr = new XMLHttpRequest()

xhr.onreadystatechange = function() {
if(xhr.readyState === XMLHttpRequest.DONE){
if(xhr.status == 200){
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status == 200) {
let curATB = JSON.parse(xhr.responseText)
resolve(curATB.version)
}
Expand All @@ -41,21 +40,20 @@ var ATB = (() => {
let randomValue = Math.ceil(Math.random() * 1e7)
let AtbRequestURL = ddgAtbURL + randomValue + '&atb=' + atbSetting + '&set_atb=' + setAtb

xhr.open('GET', AtbRequestURL, true )
xhr.open('GET', AtbRequestURL, true)
xhr.send()
})
},

redirectURL: (request) => {
if(request.url.search(regExpAboutPage) !== -1){

if(request.url.indexOf('atb=') !== -1){
if (request.url.search(regExpAboutPage) !== -1) {
if (request.url.indexOf('atb=') !== -1) {
return
}

let atbSetting = settings.getSetting('atb')

if(!atbSetting){
if (!atbSetting) {
return
}

Expand All @@ -66,8 +64,7 @@ var ATB = (() => {
// if we have an anchor tag
if (urlParts.length === 2) {
newURL = urlParts[0] + '&atb=' + atbSetting + '#' + urlParts[1]
}
else {
} else {
newURL = request.url + '&atb=' + atbSetting
}

Expand All @@ -76,9 +73,9 @@ var ATB = (() => {
},

setInitialVersions: () => {
if(!settings.getSetting('atb')){
if (!settings.getSetting('atb')) {
let versions = ATB.calculateInitialVersions()
if(versions && versions.major && versions.minor){
if (versions && versions.major && versions.minor) {
settings.updateSetting('atb', `v${versions.major}-${versions.minor}`)
}
}
Expand All @@ -105,7 +102,7 @@ var ATB = (() => {
},

setAtbValuesFromSuccessPage: (atb) => {
if(settings.getSetting('set_atb')){ return }
if (settings.getSetting('set_atb')) { return }

settings.updateSetting('atb', atb)
settings.updateSetting('set_atb', atb)
Expand All @@ -116,7 +113,6 @@ var ATB = (() => {
},

inject: () => {

// skip this for non webextension browsers
if (!window.chrome) return

Expand Down Expand Up @@ -149,8 +145,8 @@ var ATB = (() => {
// only show post install page on install if:
// - the user wasn't already looking at the app install page
// - the user hasn't seen the page before
settings.ready().then( () => {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
settings.ready().then(() => {
chrome.tabs.query({currentWindow: true, active: true}, function (tabs) {
const domain = (tabs && tabs[0]) ? tabs[0].url : ''
if (ATB.canShowPostInstall(domain)) {
settings.updateSetting('hasSeenPostInstall', true)
Expand All @@ -171,18 +167,18 @@ var ATB = (() => {

if (!(domain && settings)) return false

return !settings.getSetting('hasSeenPostInstall')
&& !domain.match(regExpPostInstall)
&& !domain.match(regExpSoftwarePage)
return !settings.getSetting('hasSeenPostInstall') &&
!domain.match(regExpPostInstall) &&
!domain.match(regExpSoftwarePage)
},

migrate: () => {
// migrate localStorage ATB from the old extension over to settings
if(!settings.getSetting('atb') && localStorage['atb']) {
if (!settings.getSetting('atb') && localStorage['atb']) {
settings.updateSetting('atb', localStorage['atb'])
}

if(!settings.getSetting('set_atb') && localStorage['set_atb']) {
if (!settings.getSetting('set_atb') && localStorage['set_atb']) {
settings.updateSetting('set_atb', localStorage['set_atb'])
}
},
Expand Down
18 changes: 9 additions & 9 deletions shared/js/background/background.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ const events = require('./$BROWSER-events.es6')
const settings = require('./settings.es6')
const tabManager = require('./tab-manager.es6')

function Background() {
// clearing last search on browser startup
settings.updateSetting('last_search', '')
function Background () {
// clearing last search on browser startup
settings.updateSetting('last_search', '')

var os = "o";
if (window.navigator.userAgent.indexOf("Windows") != -1) os = "w";
if (window.navigator.userAgent.indexOf("Mac") != -1) os = "m";
if (window.navigator.userAgent.indexOf("Linux") != -1) os = "l";
var os = 'o'
if (window.navigator.userAgent.indexOf('Windows') != -1) os = 'w'
if (window.navigator.userAgent.indexOf('Mac') != -1) os = 'm'
if (window.navigator.userAgent.indexOf('Linux') != -1) os = 'l'

localStorage['os'] = os;
localStorage['os'] = os

events.onStartup()
events.onStartup()
}

var background
Expand Down
52 changes: 26 additions & 26 deletions shared/js/background/chrome-events.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/
const ATB = require('./atb.es6')

chrome.runtime.onInstalled.addListener(function(details) {
chrome.runtime.onInstalled.addListener(function (details) {
// only run the following section on install and on update
if (details.reason.match(/install|update/)) {
ATB.updateATBValues();
ATB.updateATBValues()
}

if (details.reason.match(/install/)) {
Expand Down Expand Up @@ -54,7 +54,7 @@ chrome.webRequest.onHeadersReceived.addListener(
chrome.webRequest.onBeforeRedirect.addListener(
tabManager.updateTabRedirectCount,
{
urls: ["*://*/*"]
urls: ['*://*/*']
}
)

Expand All @@ -64,35 +64,35 @@ chrome.webRequest.onBeforeRedirect.addListener(

const Companies = require('./companies.es6')

chrome.tabs.onUpdated.addListener( (id,info) => {
chrome.tabs.onUpdated.addListener((id, info) => {
// sync company data to storage when a tab finishes loading
if (info.status === "complete") {
if (info.status === 'complete') {
Companies.syncToStorage()
}

tabManager.createOrUpdateTab(id, info)
})

chrome.tabs.onRemoved.addListener( (id, info) => {
chrome.tabs.onRemoved.addListener((id, info) => {
// remove the tab object
tabManager.delete(id);
});
tabManager.delete(id)
})

// message popup to close when the active tab changes
chrome.tabs.onActivated.addListener(() => chrome.runtime.sendMessage({closePopup: true}))

// search via omnibox

chrome.omnibox.onInputEntered.addListener(function(text) {
chrome.tabs.query({
'currentWindow': true,
'active': true
}, function(tabs) {
chrome.tabs.update(tabs[0].id, {
url: "https://duckduckgo.com/?q=" + encodeURIComponent(text) + "&bext=" + localStorage['os'] + "cl"
});
});
});
chrome.omnibox.onInputEntered.addListener(function (text) {
chrome.tabs.query({
'currentWindow': true,
'active': true
}, function (tabs) {
chrome.tabs.update(tabs[0].id, {
url: 'https://duckduckgo.com/?q=' + encodeURIComponent(text) + '&bext=' + localStorage['os'] + 'cl'
})
})
})

/**
* MESSAGES
Expand All @@ -103,7 +103,7 @@ const settings = require('./settings.es6')

// handle any messages that come from content/UI scripts
// returning `true` makes it possible to send back an async response
chrome.runtime.onMessage.addListener( (req, sender, res) => {
chrome.runtime.onMessage.addListener((req, sender, res) => {
if (req.getCurrentTab) {
utils.getCurrentTab().then((tab) => {
res(tab)
Expand All @@ -121,19 +121,19 @@ chrome.runtime.onMessage.addListener( (req, sender, res) => {
} else if (req.getSetting) {
let name = req.getSetting['name']
settings.ready().then(() => {
res(settings.getSetting(name));
res(settings.getSetting(name))
})

return true
}

if(req.atb){
if (req.atb) {
ATB.setAtbValuesFromSuccessPage(req.atb)
}

// popup will ask for the browser type then it is created
if (req.getBrowser) {
res(utils.getBrowserName());
res(utils.getBrowserName())
return true
}

Expand Down Expand Up @@ -185,9 +185,9 @@ chrome.alarms.onAlarm.addListener(alarmEvent => {
/**
* on start up
*/
let onStartup = (() => {
chrome.tabs.query({currentWindow: true, status: 'complete'}, function(savedTabs){
for (var i = 0; i < savedTabs.length; i++){
let onStartup = () => {
chrome.tabs.query({currentWindow: true, status: 'complete'}, function (savedTabs) {
for (var i = 0; i < savedTabs.length; i++) {
var tab = savedTabs[i]

if (tab.url) {
Expand All @@ -199,7 +199,7 @@ let onStartup = (() => {
}
}
})
})
}

module.exports = {
onStartup: onStartup
Expand Down
Loading

0 comments on commit a593fff

Please sign in to comment.