Skip to content

Commit

Permalink
Update to version 2.0.0
Browse files Browse the repository at this point in the history
- Sorted cookie removal and detection in Chrome and Opera, this wasnt working as expected before
- Updated the enable/disable of the toolbar button when the status is loading, otherwise we enable it (Chrome)
- Improved "base domain" detection, this goes for all browsers
  • Loading branch information
jrie committed Jan 8, 2018
1 parent 93a3e54 commit fa8697a
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ function chromeGetStorageAndClearCookies (action, data, cookies, domainURL, doLo
chrome.storage.local.get(null, function (data) { checkChromeHadNoErrors(); chromeGetStorageAndClearCookies(action, data, cookies, domainURL, false) })
return
} else if (cookies === null) {
let domain = getDomainURL(domainURL)
let domain = getURLDomain(domainURL)
chrome.cookies.getAll({domain: domain}, function (cookies) { checkChromeHadNoErrors(); chromeGetStorageAndClearCookies(action, data, cookies, domainURL, true) })
return
} else if (doLoadURLCookies === true) {
domainURL = domainURL.replace(/\/www./, '/')
chrome.cookies.getAll({url: domainURL}, function (cookieSub) {
let cookieDomain = domainURL.replace(/\/www./, '/')
chrome.cookies.getAll({url: cookieDomain}, function (cookieSub) {
checkChromeHadNoErrors()

for (let cookie of cookieSub) {
Expand Down Expand Up @@ -102,10 +102,15 @@ function getChromeActiveTabForClearing (action) {
})
}

function getDomainURL (domainURL) {
let modUrl = domainURL.replace(/(http|https):\/\//, '')
modUrl = modUrl.substr(0, modUrl.length - 1)
return modUrl
function getURLDomain (domainURL) {
let outDomainName = domainURL.replace(/(http|https):\/\//, '').replace('www.', '')
let tip1 = outDomainName.indexOf('.')
let tip2 = outDomainName.lastIndexOf('.')
if (tip1 !== tip2) {
return outDomainName.substr(tip1 + 1, tip2).replace('/', '')
} else {
return outDomainName.replace('/', '')
}
}

// Chrome + Firefox
Expand All @@ -129,14 +134,14 @@ async function clearCookiesWrapper (action, doChromeLoad) {
let domainURL = await getDomainURLFirefox()
if (domainURL === '') return
let currentTab = await getActiveTabFirefox()

let domain = getDomainURL(domainURL)
let data = await browser.storage.local.get()

let domain = getURLDomain(domainURL)
let cookies
let cookiesURL = []
if (currentTab.cookieStoreId !== undefined) {
cookies = await browser.cookies.getAll({domain: domain, storeId: currentTab.cookieStoreId})
cookiesURL = await browser.cookies.getAll({url: domainURL.replace(/\/www./, '/'), storeId: currentTab.cookieStoreId})
cookiesURL = await browser.cookies.getAll({url: domainURL, storeId: currentTab.cookieStoreId})

await browser.contextualIdentities.get(currentTab.cookieStoreId).then(firefoxOnGetContextSuccess, firefoxOnGetContextError)
} else {
Expand Down Expand Up @@ -179,18 +184,14 @@ async function clearCookiesAction (action, data, cookies, domainURL, activeCooki
let useWWW = false
let urls = [domainURL]

if (data[contextName] === undefined) {
data[contextName] = {}
if (domainURL.indexOf('www.') !== -1) {
useWWW = domainURL
domainURL = domainURL.replace('www.', '')
urls = [useWWW, domainURL]
}

if (data[contextName][domainURL] === undefined) {
let targetDomain = domainURL.replace(/\/www./, '/')
if (data[contextName][targetDomain] !== undefined) {
useWWW = domainURL
domainURL = targetDomain
urls = [useWWW, domainURL]
}
}
if (data[contextName] === undefined) data[contextName] = {}
if (data[contextName][domainURL] === undefined) data[contextName][domainURL] = {}

if (cookieData[domainURL] === undefined) {
cookieData[domainURL] = {}
Expand Down Expand Up @@ -441,10 +442,9 @@ async function clearCookiesOnNavigate (details) {
}

async function clearCookiesOnUpdate (tabId, changeInfo, tab) {
if (useChrome) chrome.browserAction.disable(tabId)
else browser.browserAction.disable(tabId)

if (changeInfo.status && changeInfo.status === 'loading') {
if (useChrome) chrome.browserAction.disable(tabId)
else browser.browserAction.disable(tabId)
clearCookiesWrapper('tab reload/load', useChrome, tab)
} else if (changeInfo.status && changeInfo.status === 'complete') {
if (useChrome) chrome.browserAction.enable(tabId)
Expand Down

0 comments on commit fa8697a

Please sign in to comment.