diff --git a/cookies.css b/cookies.css index 6d19371..76b3590 100755 --- a/cookies.css +++ b/cookies.css @@ -72,7 +72,6 @@ html, body { border-right: none; } - .intro { display: block; color: #888; @@ -174,7 +173,8 @@ button { box-shadow: 1px 2px 3px rgba(0, 0, 0, 0.12); } -input { +input, +textarea { box-shadow: 1px 2px 3px rgba(0, 0, 0, 0.17); } @@ -301,3 +301,25 @@ button#global-flag.active { background-clip: border-box; background-position: 4px center; } + +#settings-view { + padding: 10px; +} + +textarea#log { + background-color: #eee; + color: #557; + display: block; + border-radius: 8px; + border: 1px solid #ccc; + margin: 0px; + padding: 6px 12px; + font-weight: bold; + width: 100%; + min-height: 10em; + max-height: 10em; + min-width: 100%; + max-width: 100%; + margin-bottom: 10px; + resize:none; +} diff --git a/cookies.html b/cookies.html index 5dd0556..07045e0 100755 --- a/cookies.html +++ b/cookies.html @@ -21,8 +21,13 @@ + -

Flag status

FlaggedPermittedAuto flagged
+

Flag status

FlaggedPermittedAuto flagged
diff --git a/cookies.js b/cookies.js index 68ddab4..341485e 100755 --- a/cookies.js +++ b/cookies.js @@ -1,5 +1,5 @@ -// Shouldnt be required to make changes from here??? -var domainURL = '' // The active domain url +let domainURL = '' // The active domain url +let logData = [] // The log data we seen as a report to the settings view // Clear the cookies which are enabled for the domain in browser storage async function clearCookies (action) { @@ -12,16 +12,22 @@ async function clearCookies (action) { let domainCookies = await browser.cookies.getAll({url: domainURL}) for (let cookie of domainCookies) { if (data[domainURL][cookie.name] === false) { - console.log("Permitted cookie on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'") + let msg = "Permitted cookie on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'" + addToLogData(msg) + console.log(msg) continue } let details = { url: domainURL, name: cookie.name } if ((await browser.cookies.remove(details)) !== null) { if (data[domainURL][cookie.name] === true) { - console.log("Deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'") + let msg = "Deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'" + addToLogData(msg) + console.log(msg) } else { - console.log("Auto-flag deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'") + let msg = "Auto-flag deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'" + addToLogData(msg) + console.log(msg) } } } @@ -32,22 +38,30 @@ async function clearCookies (action) { for (let cookie of domainCookies) { let details = { url: domainURL, name: cookie.name } if ((await browser.cookies.remove(details)) !== null) { - console.log("Global-flag deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'") + let msg = "Global-flag deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'" + addToLogData(msg) + console.log(msg) } } } else { for (let cookie of domainCookies) { if (data[domainURL][cookie.name] !== undefined && data[domainURL][cookie.name] === false) { - console.log("Permitted cookie on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'") + let msg = "Permitted cookie on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'" + addToLogData(msg) + console.log(msg) continue } let details = { url: domainURL, name: cookie.name } if ((await browser.cookies.remove(details)) !== null) { if (data[domainURL] !== undefined && data[domainURL][cookie.name] !== undefined && data[domainURL][cookie.name] === true) { - console.log("Deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'") + let msg = "Deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'" + addToLogData(msg) + console.log(msg) } else { - console.log("Global-flag deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'") + let msg = "Global-flag deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'" + addToLogData(msg) + console.log(msg) } } } @@ -55,13 +69,17 @@ async function clearCookies (action) { } else { for (let cookie in data[domainURL]) { if (data[domainURL][cookie] === false) { - console.log("Permitted cookie on '" + action + "', cookie: '" + cookie + "' for '" + domainURL + "'") + let msg = "Permitted cookie on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'" + addToLogData(msg) + console.log(msg) continue } let details = { url: domainURL, name: cookie } if ((await browser.cookies.remove(details)) != null) { - console.log("Deleted on '" + action + "', cookie: '" + cookie + "' for '" + domainURL + "'") + let msg = "Deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'" + addToLogData(msg) + console.log(msg) } } } @@ -81,9 +99,21 @@ async function setdomainURLOnActivation (activeInfo) { } } -let clearCookiesOnUpdate = (tabId, changeInfo, tab) => { +async function clearCookiesOnUpdate (tabId, changeInfo, tab) { if (changeInfo.status && changeInfo.status === 'loading') { - clearCookies('tab loading') + clearCookies('tab load') + if (changeInfo['url'] === undefined) { + clearDomainLog(); + } + } else if (changeInfo.status && changeInfo.status === 'complete') { + if (logData !== '') { + let data = await browser.storage.local.get() + + if (data['flagCookies'] === undefined) data['flagCookies'] = {} + + data['flagCookies']['logData'] = logData + await browser.storage.local.set(data) + } } } @@ -91,6 +121,27 @@ let clearCookiesOnLeave = (tabId, moveInfo) => { clearCookies('tab close/window close') } +// -------------------------------------------------------------------------------------------------------------------------------- +// Log info +function clearDomainLog () { + if (logData !== []) { + let newLog = []; + for (let entry of logData) { + if (entry.indexOf(domainURL) === -1) { + newLog.push(entry) + } + } + + logData = newLog + } +} + +function addToLogData (msg) { + if (logData.indexOf(msg) === -1) logData.push(msg) +} + +// -------------------------------------------------------------------------------------------------------------------------------- + browser.tabs.onRemoved.addListener(clearCookiesOnLeave) browser.tabs.onUpdated.addListener(clearCookiesOnUpdate) browser.tabs.onActivated.addListener(setdomainURLOnActivation) diff --git a/flagCookies.js b/flagCookies.js index e1dc50c..26fc4c7 100644 --- a/flagCookies.js +++ b/flagCookies.js @@ -1,5 +1,6 @@ // -------------------------------------------------------------------------------------------------------------------------------- let domainURL = '' + // Slightly modifed version of list-cookies example on MDN github async function showCookiesForTab (tabs) { @@ -132,6 +133,14 @@ async function showCookiesForTab (tabs) { } document.getElementById('activeCookies').className = 'active' + if (data['flagCookies'] !== undefined && data['flagCookies']['logData'] !== '') { + let log = document.getElementById('log') + for (let entry of data['flagCookies']['logData']) { + if (entry.indexOf(domainURL) !== -1) { + log.textContent += entry + '\n'; + } + } + } } function addCookieToList (targetList, name, value) { @@ -331,11 +340,12 @@ function switchView (event) { let tabs = document.getElementById('tabs') for (let child of tabs.children) { - if (child !== event.target) { - child.removeAttribute('class') - } + if (child !== event.target) child.removeAttribute('class') } + let prefs = document.getElementById('prefs') + if (prefs !== event.target) prefs.removeAttribute('class') + event.target.className = 'active' if (list.children.length === 0) { @@ -511,6 +521,7 @@ function doSearch (searchVal, targetList) { document.getElementById('activeCookies').addEventListener('click', switchView) document.getElementById('flaggedCookies').addEventListener('click', switchView) document.getElementById('permittedCookies').addEventListener('click', switchView) +document.getElementById('prefs').addEventListener('click', switchView) document.getElementById('auto-flag').addEventListener('click', flagAutoSwitch) document.getElementById('global-flag').addEventListener('click', flagGlobalAuto) document.getElementById('searchBar').addEventListener('keyup', searchContent) diff --git a/manifest.json b/manifest.json index a83836d..16671aa 100644 --- a/manifest.json +++ b/manifest.json @@ -26,7 +26,7 @@ "homepage_url": "https://github.com/jrie/flagCookies", "manifest_version": 2, "name": "Flag Cookies", - "version": "1.53", + "version": "1.54", "permissions": ["cookies", "tabs", "", "storage"], "background": { "scripts": [