Skip to content

Commit

Permalink
Update to version 1.54
Browse files Browse the repository at this point in the history
- Added preferences view which contains the flag cookies clearing log so its visible what the add has done on the domain
  • Loading branch information
jrie committed Dec 27, 2017
1 parent 53a4db7 commit 3775d19
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 20 deletions.
26 changes: 24 additions & 2 deletions cookies.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ html, body {
border-right: none;
}


.intro {
display: block;
color: #888;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
7 changes: 6 additions & 1 deletion cookies.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
<ul class="hidden" id="cookie-list"></ul>
<ul class="hidden" id="cookie-list-flagged"></ul>
<ul class="hidden" id="cookie-list-permitted"></ul>
<div class="hidden" id="settings-view">
<!--<div id="settings-general"><h4 class="intro">General settings</h4><button>Delete all stored settings</button></div>-->
<div id="settings-log"><p class="intro">Log</p><textarea id="log" disabled="disabled" placeholder="Deletion log"></textarea></div>
<!--<div id="settings-domains"><ul class="domain-data"><li class="domainKey">Google.de</li><ul domain-settings></ul><li></ul></div>-->
</div>
</div>
<div class="legend"><p class="intro">Flag status</p><span id="leg-flagged">Flagged</span><span id="leg-permitted">Permitted</span><span id="leg-auto-flagged">Auto flagged</span><!--<button id="prefs">Preferences</button>--></div>
<div class="legend"><p class="intro">Flag status</p><span id="leg-flagged">Flagged</span><span id="leg-permitted">Permitted</span><span id="leg-auto-flagged">Auto flagged</span><button data-target="settings-view" id="prefs">Preferences</button></div>
</div>
<script src="flagCookies.js"></script>
</body>
Expand Down
77 changes: 64 additions & 13 deletions cookies.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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)
}
}
}
Expand All @@ -32,36 +38,48 @@ 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)
}
}
}
}
} 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)
}
}
}
Expand All @@ -81,16 +99,49 @@ 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)
}
}
}

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)
17 changes: 14 additions & 3 deletions flagCookies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// --------------------------------------------------------------------------------------------------------------------------------
let domainURL = ''

// Slightly modifed version of list-cookies example on MDN github

async function showCookiesForTab (tabs) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<all_urls>", "storage"],
"background": {
"scripts": [
Expand Down

0 comments on commit 3775d19

Please sign in to comment.