-
-
Save wooparadog/296eeb1ea21051c67859d4dc1973c1eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/background.js b/background.js | |
index 731b483..e69de29 100644 | |
--- a/background.js | |
+++ b/background.js | |
@@ -1,33 +0,0 @@ | |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
-// Use of this source code is governed by a BSD-style license that can be | |
-// found in the LICENSE file. | |
- | |
-chrome.cookies.onChanged.addListener(function(info) { | |
- console.log("onChanged" + JSON.stringify(info.cookie)); | |
-}); | |
- | |
-/*function focusOrCreateTab(url) { | |
- chrome.windows.getAll({"populate":true}, function(windows) { | |
- var existing_tab = null; | |
- for (var i in windows) { | |
- var tabs = windows[i].tabs; | |
- for (var j in tabs) { | |
- var tab = tabs[j]; | |
- if (tab.url == url) { | |
- existing_tab = tab; | |
- break; | |
- } | |
- } | |
- } | |
- if (existing_tab) { | |
- chrome.tabs.update(existing_tab.id, {"selected":true}); | |
- } else { | |
- chrome.tabs.create({"url":url, "selected":true}); | |
- } | |
- }); | |
-} | |
- | |
-chrome.browserAction.onClicked.addListener(function(tab) { | |
- var manager_url = chrome.extension.getURL("manager.html"); | |
- focusOrCreateTab(manager_url); | |
-});*/ | |
\ No newline at end of file | |
diff --git a/manifest.json b/manifest.json | |
index b292bb8..8efa042 100644 | |
--- a/manifest.json | |
+++ b/manifest.json | |
@@ -1,7 +1,10 @@ | |
{ | |
- "background": { | |
- "scripts": [ "background.js", "scripts/jquery-3.1.1.min.js" ] | |
- }, | |
+ "content_scripts": [ | |
+ { | |
+ "matches": ["http://*/*", "https://*/*"], | |
+ "js": ["contentScript.js"] | |
+ } | |
+ ], | |
"browser_action": { | |
"default_icon": "cookie.png", | |
"default_popup": "profiles.html" | |
@@ -16,7 +19,7 @@ | |
"manifest_version": 2, | |
"name": "Cookie Profile Switcher", | |
"options_page": "options.html", | |
- "permissions": [ "cookies", "tabs", "http://*/*", "https://*/*", "storage" ], | |
+ "permissions": [ "cookies", "activeTab", "http://*/*", "https://*/*", "storage"], | |
"update_url": "https://clients2.google.com/service/update2/crx", | |
"version": "1.3.2" | |
} | |
diff --git a/profiles.js b/profiles.js | |
index 3f0ff32..5ac024d 100644 | |
--- a/profiles.js | |
+++ b/profiles.js | |
@@ -3,329 +3,324 @@ var origProfileTable = ""; | |
// BEGIN DOMAIN FUNCTIONS // | |
function getHostName(url) { | |
- var match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i); | |
- if (match != null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) { | |
+ var match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i); | |
+ if (match != null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) { | |
return match[2]; | |
- } | |
- else { | |
- return null; | |
- } | |
+ } | |
+ else { | |
+ return null; | |
+ } | |
} | |
function getDomain(url) { | |
- var hostName = getHostName(url); | |
- var domain = url; | |
- | |
- if (hostName != null) { | |
- var parts = hostName.split('.').reverse(); | |
- | |
- if (parts != null && parts.length > 1) { | |
- domain = parts[1] + '.' + parts[0]; | |
- | |
- if (hostName.toLowerCase().indexOf('.co.uk') != -1 && parts.length > 2) { | |
- domain = parts[2] + '.' + domain; | |
- } | |
- } | |
+ var hostName = getHostName(url); | |
+ var domain = url; | |
+ | |
+ if (hostName != null) { | |
+ var parts = hostName.split('.').reverse(); | |
+ | |
+ if (parts != null && parts.length > 1) { | |
+ domain = parts[1] + '.' + parts[0]; | |
+ | |
+ if (hostName.toLowerCase().indexOf('.co.uk') != -1 && parts.length > 2) { | |
+ domain = parts[2] + '.' + domain; | |
+ } | |
} | |
- | |
- return domain; | |
+ } | |
+ | |
+ return domain; | |
} | |
// END DOMAIN FUNCTIONS // | |
// BEGIN PROFILE FUNCTIONS // | |
function addProfileListeners(){ | |
- var classname = document.getElementsByClassName("changeProfile"); | |
- | |
- for (var i = 0; i < classname.length; i++) { | |
- classname[i].addEventListener('click', changeProfile, false); | |
- } | |
- | |
- var classname = document.getElementsByClassName("editProfile"); | |
- | |
- for (var i = 0; i < classname.length; i++) { | |
- classname[i].addEventListener('click', editProfile, false); | |
- } | |
- var classname = document.getElementsByClassName("removeProfile"); | |
- | |
- for (var i = 0; i < classname.length; i++) { | |
- classname[i].addEventListener('click', removeProfile, false); | |
- } | |
- document.querySelector('#profileCreate_button').addEventListener('click', newProfile, false); | |
+ var classname = document.getElementsByClassName("changeProfile"); | |
+ | |
+ for (var i = 0; i < classname.length; i++) { | |
+ classname[i].addEventListener('click', changeProfile, false); | |
+ } | |
+ | |
+ var classname = document.getElementsByClassName("editProfile"); | |
+ | |
+ for (var i = 0; i < classname.length; i++) { | |
+ classname[i].addEventListener('click', editProfile, false); | |
+ } | |
+ var classname = document.getElementsByClassName("removeProfile"); | |
+ | |
+ for (var i = 0; i < classname.length; i++) { | |
+ classname[i].addEventListener('click', removeProfile, false); | |
+ } | |
+ document.querySelector('#profileCreate_button').addEventListener('click', newProfile, false); | |
} | |
function editProfile(event){ | |
- var target = event.target; | |
- var oldProfileName = target.getAttribute('data-profileName'); | |
- console.log("Clicked"); | |
- $(target).html("save"); | |
- $(target).parent().parent().parent().find('.changeProfile').hide(); | |
- $(target).parent().parent().parent().find('.profileLabel').hide(); | |
- $(target).parent().parent().parent().find('input').show(); | |
- target.removeEventListener('click', editProfile, false); | |
- target.addEventListener('click', saveProfileName, false); | |
- //$(target).parent().parent().parent().find('input').text(target.getAttribute('data-profileName')); | |
- | |
- | |
- | |
- | |
+ var target = event.target; | |
+ var oldProfileName = target.getAttribute('data-profileName'); | |
+ console.log("Clicked"); | |
+ $(target).html("save"); | |
+ $(target).parent().parent().parent().find('.changeProfile').hide(); | |
+ $(target).parent().parent().parent().find('.profileLabel').hide(); | |
+ $(target).parent().parent().parent().find('input').show(); | |
+ target.removeEventListener('click', editProfile, false); | |
+ target.addEventListener('click', saveProfileName, false); | |
+ //$(target).parent().parent().parent().find('input').text(target.getAttribute('data-profileName')); | |
+ | |
+ | |
+ | |
+ | |
} | |
function saveProfileName(event){ | |
- var target = event.target; | |
- | |
- | |
- chrome.storage.local.get('profiles', function(items){ | |
- var currentDomain = $('#domain_label').html(); | |
- var currentProfile = $('#profile_label').html(); | |
- var profile = {}; | |
- var domainProfile = {}; | |
- | |
- if(jQuery.isEmptyObject(items) || jQuery.isEmptyObject(items.profiles) || jQuery.isEmptyObject(items.profiles[currentDomain])){ | |
- domainProfile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {}}}'); | |
- if(!jQuery.isEmptyObject(items.profiles)){ | |
- profile = JSON.parse(JSON.stringify(items.profiles)); | |
- } | |
- profile[currentDomain] = domainProfile; | |
- | |
- } | |
- else{ | |
- profile = items.profiles; | |
- console.log(JSON.stringify(profile)); | |
- domainProfile = profile[currentDomain]; | |
- } | |
- if (target.getAttribute('data-profileName') !== $(target).parent().parent().parent().find('input').text()) { | |
- var temp = JSON.parse(JSON.stringify(profile)); | |
- var newProfileName = $(target).parent().parent().parent().find('input').val(); | |
- delete profile[currentDomain]['profileData'][target.getAttribute('data-profileName')]; | |
- profile[currentDomain]['profileData'][newProfileName] = temp[currentDomain]['profileData'][target.getAttribute('data-profileName')]; | |
- if(profile[currentDomain]['currentProfile'] == target.getAttribute('data-profileName')){ | |
- profile[currentDomain]['currentProfile'] = newProfileName; | |
- } | |
- chrome.storage.local.set({ "profiles": profile }, function(){ | |
- loadProfiles(); | |
- }); | |
- } | |
- | |
- | |
- //console.log(JSON.stringify(profile)); | |
- }); | |
+ var target = event.target; | |
+ | |
+ | |
+ chrome.storage.local.get('profiles', function(items){ | |
+ var currentDomain = $('#domain_label').html(); | |
+ var currentProfile = $('#profile_label').html(); | |
+ var profile = {}; | |
+ var domainProfile = {}; | |
+ | |
+ if(jQuery.isEmptyObject(items) || jQuery.isEmptyObject(items.profiles) || jQuery.isEmptyObject(items.profiles[currentDomain])){ | |
+ domainProfile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {"Storage": {}, "Cookie": {}}}}'); | |
+ if(!jQuery.isEmptyObject(items.profiles)){ | |
+ profile = JSON.parse(JSON.stringify(items.profiles)); | |
+ } | |
+ profile[currentDomain] = domainProfile; | |
+ | |
+ } | |
+ else{ | |
+ profile = items.profiles; | |
+ console.log(JSON.stringify(profile)); | |
+ domainProfile = profile[currentDomain]; | |
+ } | |
+ if (target.getAttribute('data-profileName') !== $(target).parent().parent().parent().find('input').text()) { | |
+ var temp = JSON.parse(JSON.stringify(profile)); | |
+ var newProfileName = $(target).parent().parent().parent().find('input').val(); | |
+ delete profile[currentDomain]['profileData'][target.getAttribute('data-profileName')]; | |
+ profile[currentDomain]['profileData'][newProfileName] = temp[currentDomain]['profileData'][target.getAttribute('data-profileName')]; | |
+ if(profile[currentDomain]['currentProfile'] == target.getAttribute('data-profileName')){ | |
+ profile[currentDomain]['currentProfile'] = newProfileName; | |
+ } | |
+ chrome.storage.local.set({ "profiles": profile }, function(){ | |
+ loadProfiles(); | |
+ }); | |
+ } | |
+ | |
+ | |
+ //console.log(JSON.stringify(profile)); | |
+ }); | |
} | |
function removeProfile(event){ | |
- var target = event.target.getAttribute('data-profileName'); | |
- chrome.storage.local.get('profiles', function(items){ | |
- var currentDomain = $('#domain_label').html(); | |
- var currentProfile = $('#profile_label').html(); | |
- var profile = items.profiles; | |
- | |
- delete profile[currentDomain]['profileData'][target]; | |
- | |
- var newProfile = Object.keys(profile[currentDomain]['profileData'])[0]; | |
- var passedVar = {'target':{'innerHTML':newProfile},'saveData':false}; | |
- | |
- if(currentProfile == target){ | |
- profile[currentDomain]['currentProfile'] = newProfile; | |
- } | |
- | |
- chrome.storage.local.set({ "profiles": profile }, function(){ | |
- if(currentProfile == target){changeProfile(passedVar);} | |
- loadProfiles(); | |
- }); | |
- //console.log(JSON.stringify(profile)); | |
- }); | |
+ var target = event.target.getAttribute('data-profileName'); | |
+ chrome.storage.local.get('profiles', function(items){ | |
+ var currentDomain = $('#domain_label').html(); | |
+ var currentProfile = $('#profile_label').html(); | |
+ var profile = items.profiles; | |
+ | |
+ delete profile[currentDomain]['profileData'][target]; | |
+ | |
+ var newProfile = Object.keys(profile[currentDomain]['profileData'])[0]; | |
+ var passedVar = {'target':{'innerHTML':newProfile},'saveData':false}; | |
+ | |
+ if(currentProfile == target){ | |
+ profile[currentDomain]['currentProfile'] = newProfile; | |
+ } | |
+ | |
+ chrome.storage.local.set({ "profiles": profile }, function(){ | |
+ if(currentProfile == target){changeProfile(passedVar);} | |
+ loadProfiles(); | |
+ }); | |
+ //console.log(JSON.stringify(profile)); | |
+ }); | |
} | |
function resetDomain(){ | |
- chrome.storage.local.get('profiles', function(items){ | |
- var currentDomain = $('#domain_label').html(); | |
- var profile = items.profiles; | |
- | |
- delete profile[currentDomain]; | |
- | |
- chrome.storage.local.set({ "profiles": profile }, function(){ | |
- loadProfiles(); | |
- }); | |
- }); | |
+ chrome.storage.local.get('profiles', function(items){ | |
+ var currentDomain = $('#domain_label').html(); | |
+ var profile = items.profiles; | |
+ | |
+ delete profile[currentDomain]; | |
+ | |
+ chrome.storage.local.set({ "profiles": profile }, function(){ | |
+ loadProfiles(); | |
+ }); | |
+ }); | |
} | |
function loadProfiles(){ | |
- if(origProfileTable == ""){ | |
- origProfileTable = $('#profileTable').html(); | |
- } | |
- else{ | |
- $('#profileTable').html(origProfileTable); | |
- } | |
- chrome.storage.local.get('profiles', function(items){ | |
- var domain = $('#domain_label').html(); | |
- var profile; | |
- | |
- if(jQuery.isEmptyObject(items) || jQuery.isEmptyObject(items.profiles) || jQuery.isEmptyObject(items.profiles[currentDomain])){ | |
- profile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {}}}'); | |
- } | |
- else{ | |
- profile = items.profiles[domain]; | |
- } | |
- $('#profile_label').html(profile['currentProfile']); | |
- //$('#storage_label').html(JSON.stringify(profile['profileData'])); | |
- | |
- for (var profileData in profile['profileData']){ | |
- if (typeof profile['profileData'][profileData] !== 'function') { | |
- var tableRef = document.getElementById('profileTable').getElementsByTagName('tbody')[0]; | |
- // Insert a row in the table at row index 0 | |
- var newRow = tableRef.insertRow(tableRef.rows.length - 1); | |
- // Insert a cell in the row at index 0 | |
- var newCell = newRow.insertCell(0); | |
- // Append a text node to the cell | |
- | |
- var textbox = document.createElement('input'); | |
- textbox.setAttribute("hidden", "true"); | |
- textbox.type = "textbox"; | |
- textbox.setAttribute("value", profileData); | |
- | |
- var a = document.createElement('a'); | |
- | |
- var linkText = document.createTextNode(profileData); | |
- | |
- if($('#profile_label').html() != profileData){ | |
- a.appendChild(linkText); | |
- a.href = "#"; | |
- a.className = "changeProfile"; | |
- | |
- newCell.appendChild(a); | |
- } | |
- else{ | |
- var span = document.createElement('a'); | |
- span.className = "profileLabel"; | |
- span.appendChild(linkText); | |
- | |
- newCell.appendChild(span); | |
- } | |
- | |
- newCell.appendChild(textbox); | |
- | |
- | |
- var newCell2 = newRow.insertCell(1); | |
- newCell2.className = "no-wrap"; | |
- var a2 = document.createElement('a'); | |
- var link2Text = document.createTextNode("edit"); | |
- | |
- a2.appendChild(link2Text); | |
- a2.href = "#"; | |
- a2.setAttribute('data-profileName', profileData); | |
- a2.className = "editProfile"; | |
- | |
- var a3 = document.createElement('a'); | |
- var link3Text = document.createTextNode("remove"); | |
- | |
- a3.appendChild(link3Text); | |
- a3.href = "#"; | |
- a3.setAttribute('data-profileName', profileData); | |
- a3.className = "removeProfile"; | |
- | |
- var cellSpan = document.createElement('span'); | |
- cellSpan.appendChild(a2); | |
- cellSpan.appendChild(document.createTextNode(" ")); | |
- cellSpan.appendChild(a3); | |
- cellSpan.className = "smallText"; | |
- | |
- newCell2.appendChild(cellSpan); | |
- } | |
- } | |
- var tableRef = document.getElementById('profileTable').getElementsByTagName('tbody')[0]; | |
- if(tableRef.rows.length < 4){ | |
- tableRef.getElementsByClassName('removeProfile')[0].parentNode.removeChild(tableRef.getElementsByClassName('removeProfile')[0]); | |
- } | |
- addProfileListeners(); | |
- //console.log(JSON.stringify(profile)); | |
- loadDomainCookieStore(); | |
- }); | |
+ if(origProfileTable == ""){ | |
+ origProfileTable = $('#profileTable').html(); | |
+ } | |
+ else{ | |
+ $('#profileTable').html(origProfileTable); | |
+ } | |
+ chrome.storage.local.get('profiles', function(items){ | |
+ var domain = $('#domain_label').html(); | |
+ var profile; | |
+ | |
+ if(jQuery.isEmptyObject(items) || jQuery.isEmptyObject(items.profiles) || jQuery.isEmptyObject(items.profiles[currentDomain])){ | |
+ profile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {"Storage": {}, "Cookie": {}}}}'); | |
+ } | |
+ else{ | |
+ profile = items.profiles[domain]; | |
+ } | |
+ $('#profile_label').html(profile['currentProfile']); | |
+ //$('#storage_label').html(JSON.stringify(profile['profileData'])); | |
+ | |
+ for (var profileData in profile['profileData']){ | |
+ if (typeof profile['profileData'][profileData] !== 'function') { | |
+ var tableRef = document.getElementById('profileTable').getElementsByTagName('tbody')[0]; | |
+ // Insert a row in the table at row index 0 | |
+ var newRow = tableRef.insertRow(tableRef.rows.length - 1); | |
+ // Insert a cell in the row at index 0 | |
+ var newCell = newRow.insertCell(0); | |
+ // Append a text node to the cell | |
+ | |
+ var textbox = document.createElement('input'); | |
+ textbox.setAttribute("hidden", "true"); | |
+ textbox.type = "textbox"; | |
+ textbox.setAttribute("value", profileData); | |
+ | |
+ var a = document.createElement('a'); | |
+ | |
+ var linkText = document.createTextNode(profileData); | |
+ | |
+ if($('#profile_label').html() != profileData){ | |
+ a.appendChild(linkText); | |
+ a.href = "#"; | |
+ a.className = "changeProfile"; | |
+ | |
+ newCell.appendChild(a); | |
+ } | |
+ else{ | |
+ var span = document.createElement('a'); | |
+ span.className = "profileLabel"; | |
+ span.appendChild(linkText); | |
+ | |
+ newCell.appendChild(span); | |
+ } | |
+ | |
+ newCell.appendChild(textbox); | |
+ | |
+ | |
+ var newCell2 = newRow.insertCell(1); | |
+ newCell2.className = "no-wrap"; | |
+ var a2 = document.createElement('a'); | |
+ var link2Text = document.createTextNode("edit"); | |
+ | |
+ a2.appendChild(link2Text); | |
+ a2.href = "#"; | |
+ a2.setAttribute('data-profileName', profileData); | |
+ a2.className = "editProfile"; | |
+ | |
+ var a3 = document.createElement('a'); | |
+ var link3Text = document.createTextNode("remove"); | |
+ | |
+ a3.appendChild(link3Text); | |
+ a3.href = "#"; | |
+ a3.setAttribute('data-profileName', profileData); | |
+ a3.className = "removeProfile"; | |
+ | |
+ var cellSpan = document.createElement('span'); | |
+ cellSpan.appendChild(a2); | |
+ cellSpan.appendChild(document.createTextNode(" ")); | |
+ cellSpan.appendChild(a3); | |
+ cellSpan.className = "smallText"; | |
+ | |
+ newCell2.appendChild(cellSpan); | |
+ } | |
+ } | |
+ var tableRef = document.getElementById('profileTable').getElementsByTagName('tbody')[0]; | |
+ if(tableRef.rows.length < 4){ | |
+ tableRef.getElementsByClassName('removeProfile')[0].parentNode.removeChild(tableRef.getElementsByClassName('removeProfile')[0]); | |
+ } | |
+ addProfileListeners(); | |
+ //console.log(JSON.stringify(profile)); | |
+ loadDomainCookieStore(); | |
+ }); | |
} | |
function newProfile(){ | |
- chrome.storage.local.get('profiles', function(items){ | |
- var currentDomain = $('#domain_label').html(); | |
- var newProfileName = $('#profileName_input').val(); | |
- var profile = {}; | |
- var domainProfile = {}; | |
- | |
- if(jQuery.isEmptyObject(items) || jQuery.isEmptyObject(items.profiles) || jQuery.isEmptyObject(items.profiles[currentDomain])){ | |
- domainProfile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {}}}'); | |
- } | |
- else{ | |
- domainProfile = items.profiles[currentDomain]; | |
- profile = items['profiles']; | |
- } | |
- | |
- domainProfile['profileData'][newProfileName] = ""; | |
- profile[currentDomain] = domainProfile; | |
- | |
- | |
- $('#profile_label').html(profile['currentProfile']); | |
- //$('#storage_label').html(JSON.stringify(profile)); | |
- | |
- if(newProfileName != "") | |
- { | |
- chrome.storage.local.set({ "profiles": profile }, function(){ | |
- loadProfiles(); | |
- }); | |
- } | |
- | |
- return; | |
- }); | |
+ chrome.storage.local.get('profiles', function(items){ | |
+ var currentDomain = $('#domain_label').html(); | |
+ var newProfileName = $('#profileName_input').val(); | |
+ var profile = {}; | |
+ var domainProfile = {}; | |
+ | |
+ if(jQuery.isEmptyObject(items) || jQuery.isEmptyObject(items.profiles) || jQuery.isEmptyObject(items.profiles[currentDomain])){ | |
+ domainProfile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {"Storage": {}, "Cookie": {}}}}'); | |
+ } | |
+ else{ | |
+ domainProfile = items.profiles[currentDomain]; | |
+ profile = items['profiles']; | |
+ } | |
+ | |
+ domainProfile['profileData'][newProfileName] = {"Cookie": {}, "Storage": {}}; | |
+ profile[currentDomain] = domainProfile; | |
+ | |
+ | |
+ $('#profile_label').html(profile['currentProfile']); | |
+ //$('#storage_label').html(JSON.stringify(profile)); | |
+ | |
+ if(newProfileName != "") | |
+ { | |
+ chrome.storage.local.set({ "profiles": profile }, function(){ | |
+ loadProfiles(); | |
+ }); | |
+ } | |
+ | |
+ return; | |
+ }); | |
} | |
function extrapolateUrlFromCookie(cookie) { | |
- var prefix = cookie.secure ? "https://" : "http://"; | |
- if (cookie.domain.charAt(0) == ".") | |
- prefix += "www"; | |
+ var prefix = cookie.secure ? "https://" : "http://"; | |
+ if (cookie.domain.charAt(0) == ".") | |
+ prefix += "www"; | |
- return prefix + cookie.domain + cookie.path; | |
+ return prefix + cookie.domain + cookie.path; | |
} | |
function changeProfile(event){ | |
- var target = event.target; | |
- var saveData = event.saveData; | |
- var currentDomain = $('#domain_label').html(); | |
- chrome.cookies.getAll({domain: currentDomain}, function(cookies) { | |
- var currentProfile = $('#profile_label').html(); | |
- | |
- chrome.storage.local.get('profiles', function(items){ | |
- var currentDomain = $('#domain_label').html(); | |
- var oldProfileData = cookies; | |
- var newProfileData = items.profiles[currentDomain]['profileData'][target.innerHTML]; | |
- | |
- var profile = items.profiles; | |
- var domainProfiles = profile[currentDomain]['profileData']; | |
- | |
- domainProfiles[currentProfile] = oldProfileData; | |
- profile[currentDomain]['currentProfile'] = target.innerHTML; | |
- profile[currentDomain]['profileData'] = domainProfiles; | |
- | |
- | |
- for(var i=0; i<cookies.length;i++) { | |
- chrome.cookies.remove({url: extrapolateUrlFromCookie(cookies[i]), name: cookies[i].name}); | |
- } | |
- | |
- if(newProfileData.length > 0){for (var i=0; i<newProfileData.length;i++){ | |
- newProfileData[i]['url'] = "http" + (newProfileData[i]['secure'] ? "s" : "") + "://" + newProfileData[i]['domain']; | |
- delete newProfileData[i]['hostOnly']; | |
- delete newProfileData[i]['session']; | |
- console.log(JSON.stringify(newProfileData)); | |
- chrome.cookies.set(newProfileData[i]); | |
- }} | |
- | |
- | |
- | |
- if (typeof saveData === 'undefined' || saveData == true) { | |
- chrome.storage.local.set({ "profiles": profile }, function(){ | |
- loadProfiles(); | |
- }); | |
- } | |
- | |
- | |
- //$('#storage_label').text(JSON.stringify(newProfileData)); | |
- | |
- chrome.tabs.query({active: true, currentWindow: true}, function (arrayOfTabs) { | |
- var code = 'window.location.reload();'; | |
- chrome.tabs.executeScript(arrayOfTabs[0].id, {code: code}); | |
- }); | |
- | |
- }); | |
- | |
- }); | |
- //$('#message_label').text("Profile Change Button clicked " + target.innerHTML); | |
+ var target = event.target; | |
+ var saveData = event.saveData; | |
+ var currentDomain = $('#domain_label').html(); | |
+ chrome.cookies.getAll({domain: currentDomain}, function(cookies) { | |
+ chrome.storage.local.get('profiles', function(items){ | |
+ chrome.tabs.sendMessage(tab.id, {request: "localStorage"}, function(localStorage) { | |
+ var currentDomain = $('#domain_label').html(); | |
+ var oldProfileData = {'Cookie': cookies, 'Storage': localStorage}; | |
+ var newProfileCookieData = items.profiles[currentDomain]['profileData'][target.innerHTML]['Cookie']; | |
+ var newProfileStorageData = items.profiles[currentDomain]['profileData'][target.innerHTML]['Storage']; | |
+ var profile = items.profiles; | |
+ var domainProfiles = profile[currentDomain]['profileData']; | |
+ var currentProfile = $('#profile_label').html(); | |
+ | |
+ chrome.tabs.sendMessage(tab.id, {request: "refreshLocalStorage", data: newProfileStorageData}, function(resp) { | |
+ domainProfiles[currentProfile] = oldProfileData; | |
+ profile[currentDomain]['currentProfile'] = target.innerHTML; | |
+ profile[currentDomain]['profileData'] = domainProfiles; | |
+ | |
+ for(var i=0; i<cookies.length;i++) { | |
+ chrome.cookies.remove({url: extrapolateUrlFromCookie(cookies[i]), name: cookies[i].name}); | |
+ } | |
+ | |
+ if(newProfileCookieData.length > 0){for (var i=0; i<newProfileCookieData.length;i++){ | |
+ newProfileCookieData[i]['url'] = "http" + (newProfileCookieData[i]['secure'] ? "s" : "") + "://" + newProfileCookieData[i]['domain']; | |
+ delete newProfileCookieData[i]['hostOnly']; | |
+ delete newProfileCookieData[i]['session']; | |
+ console.log(JSON.stringify(newProfileCookieData)); | |
+ chrome.cookies.set(newProfileCookieData[i]); | |
+ }} | |
+ if (typeof saveData === 'undefined' || saveData == true) { | |
+ chrome.storage.local.set({ "profiles": profile }, function(){ | |
+ loadProfiles(); | |
+ }); | |
+ } | |
+ //$('#storage_label').text(JSON.stringify(newProfileCookieData)); | |
+ chrome.tabs.query({active: true, currentWindow: true}, function (arrayOfTabs) { | |
+ var code = 'window.location.reload();'; | |
+ chrome.tabs.executeScript(arrayOfTabs[0].id, {code: code}); | |
+ }); | |
+ }); | |
+ | |
+ }); | |
+ }); | |
+ }); | |
+ //$('#message_label').text("Profile Change Button clicked " + target.innerHTML); | |
} | |
// END PROFILE FUNCTIONS // | |
@@ -333,41 +328,30 @@ function changeProfile(event){ | |
// BEGIN COOKIE FUNCTIONS // | |
function loadDomainCookieStore(){ | |
- var currentDomain = $('#domain_label').html(); | |
- chrome.cookies.getAll({domain: currentDomain}, function(cookies) { | |
- //$('#cookie_label').text(JSON.stringify(cookies)); | |
- }); | |
+ var currentDomain = $('#domain_label').html(); | |
+ chrome.cookies.getAll({domain: currentDomain}, function(cookies) { | |
+ //$('#cookie_label').text(JSON.stringify(cookies)); | |
+ }); | |
} | |
// END COOKIE FUNCTIONS // | |
- | |
- | |
- | |
- | |
function domainLoaded(){ //CODE TO EXECUTE WHEN DOMAIN HAS BEEN LOADED | |
- document.getElementById('domain_label').innerHTML = currentDomain; | |
- $('#profileCreate_button').data('domain', currentDomain); | |
+ document.getElementById('domain_label').innerHTML = currentDomain; | |
+ $('#profileCreate_button').data('domain', currentDomain); | |
} | |
function init(){ //POP-UP OPENED, INITIALIZE | |
- chrome.tabs.query({active: true, lastFocusedWindow: true}, function(tabs) { | |
- tab = tabs[0]; | |
- url = tab.url; | |
- currentDomain = getDomain(url); | |
- domainLoaded(); | |
- }); | |
- document.querySelector('#profileCreate_button').addEventListener('click', newProfile, false); | |
- loadProfiles(); | |
+ chrome.tabs.query({active: true, lastFocusedWindow: true}, function(tabs) { | |
+ tab = tabs[0]; | |
+ url = tab.url; | |
+ currentDomain = getDomain(url); | |
+ domainLoaded(); | |
+ }); | |
+ document.querySelector('#profileCreate_button').addEventListener('click', newProfile, false); | |
+ loadProfiles(); | |
} | |
document.addEventListener('DOMContentLoaded', function() { | |
init(); | |
document.querySelector('#profileCreate_button').addEventListener('click', newProfile); | |
- //document.body.addEventListener('click', focusFilter); | |
- //document.querySelector('#remove_button').addEventListener('click', removeAll); | |
- //document.querySelector('#import_button').addEventListener('click', importCookies); | |
- //document.querySelector('#filter_div input').addEventListener( | |
- // 'input', reloadCookieTable); | |
- //document.querySelector('#filter_div button').addEventListener( | |
- // 'click', resetFilter); | |
-}); | |
\ No newline at end of file | |
+}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/background.js b/background.js | |
index 731b483..e69de29 100644 | |
--- a/background.js | |
+++ b/background.js | |
@@ -1,33 +0,0 @@ | |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
-// Use of this source code is governed by a BSD-style license that can be | |
-// found in the LICENSE file. | |
- | |
-chrome.cookies.onChanged.addListener(function(info) { | |
- console.log("onChanged" + JSON.stringify(info.cookie)); | |
-}); | |
- | |
-/*function focusOrCreateTab(url) { | |
- chrome.windows.getAll({"populate":true}, function(windows) { | |
- var existing_tab = null; | |
- for (var i in windows) { | |
- var tabs = windows[i].tabs; | |
- for (var j in tabs) { | |
- var tab = tabs[j]; | |
- if (tab.url == url) { | |
- existing_tab = tab; | |
- break; | |
- } | |
- } | |
- } | |
- if (existing_tab) { | |
- chrome.tabs.update(existing_tab.id, {"selected":true}); | |
- } else { | |
- chrome.tabs.create({"url":url, "selected":true}); | |
- } | |
- }); | |
-} | |
- | |
-chrome.browserAction.onClicked.addListener(function(tab) { | |
- var manager_url = chrome.extension.getURL("manager.html"); | |
- focusOrCreateTab(manager_url); | |
-});*/ | |
\ No newline at end of file | |
diff --git a/manifest.json b/manifest.json | |
index b292bb8..8efa042 100644 | |
--- a/manifest.json | |
+++ b/manifest.json | |
@@ -1,7 +1,10 @@ | |
{ | |
- "background": { | |
- "scripts": [ "background.js", "scripts/jquery-3.1.1.min.js" ] | |
- }, | |
+ "content_scripts": [ | |
+ { | |
+ "matches": ["http://*/*", "https://*/*"], | |
+ "js": ["contentScript.js"] | |
+ } | |
+ ], | |
"browser_action": { | |
"default_icon": "cookie.png", | |
"default_popup": "profiles.html" | |
@@ -16,7 +19,7 @@ | |
"manifest_version": 2, | |
"name": "Cookie Profile Switcher", | |
"options_page": "options.html", | |
- "permissions": [ "cookies", "tabs", "http://*/*", "https://*/*", "storage" ], | |
+ "permissions": [ "cookies", "activeTab", "http://*/*", "https://*/*", "storage"], | |
"update_url": "https://clients2.google.com/service/update2/crx", | |
"version": "1.3.2" | |
} | |
diff --git a/profiles.js b/profiles.js | |
index 3f0ff32..5ac024d 100644 | |
--- a/profiles.js | |
+++ b/profiles.js | |
@@ -79,7 +79,7 @@ function saveProfileName(event){ | |
var domainProfile = {}; | |
if(jQuery.isEmptyObject(items) || jQuery.isEmptyObject(items.profiles) || jQuery.isEmptyObject(items.profiles[currentDomain])){ | |
- domainProfile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {}}}'); | |
+ domainProfile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {"Storage": {}, "Cookie": {}}}}'); | |
if(!jQuery.isEmptyObject(items.profiles)){ | |
profile = JSON.parse(JSON.stringify(items.profiles)); | |
} | |
@@ -155,7 +155,7 @@ function loadProfiles(){ | |
var profile; | |
if(jQuery.isEmptyObject(items) || jQuery.isEmptyObject(items.profiles) || jQuery.isEmptyObject(items.profiles[currentDomain])){ | |
- profile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {}}}'); | |
+ profile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {"Storage": {}, "Cookie": {}}}}'); | |
} | |
else{ | |
profile = items.profiles[domain]; | |
@@ -243,14 +243,14 @@ function newProfile(){ | |
var domainProfile = {}; | |
if(jQuery.isEmptyObject(items) || jQuery.isEmptyObject(items.profiles) || jQuery.isEmptyObject(items.profiles[currentDomain])){ | |
- domainProfile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {}}}'); | |
+ domainProfile = JSON.parse('{"currentProfile":"Profile 1", "profileData":{"Profile 1": {"Storage": {}, "Cookie": {}}}}'); | |
} | |
else{ | |
domainProfile = items.profiles[currentDomain]; | |
profile = items['profiles']; | |
} | |
- domainProfile['profileData'][newProfileName] = ""; | |
+ domainProfile['profileData'][newProfileName] = {"Cookie": {}, "Storage": {}}; | |
profile[currentDomain] = domainProfile; | |
@@ -279,52 +279,47 @@ function changeProfile(event){ | |
var saveData = event.saveData; | |
var currentDomain = $('#domain_label').html(); | |
chrome.cookies.getAll({domain: currentDomain}, function(cookies) { | |
- var currentProfile = $('#profile_label').html(); | |
- | |
chrome.storage.local.get('profiles', function(items){ | |
+ chrome.tabs.sendMessage(tab.id, {request: "localStorage"}, function(localStorage) { | |
var currentDomain = $('#domain_label').html(); | |
- var oldProfileData = cookies; | |
- var newProfileData = items.profiles[currentDomain]['profileData'][target.innerHTML]; | |
- | |
+ var oldProfileData = {'Cookie': cookies, 'Storage': localStorage}; | |
+ var newProfileCookieData = items.profiles[currentDomain]['profileData'][target.innerHTML]['Cookie']; | |
+ var newProfileStorageData = items.profiles[currentDomain]['profileData'][target.innerHTML]['Storage']; | |
var profile = items.profiles; | |
var domainProfiles = profile[currentDomain]['profileData']; | |
+ var currentProfile = $('#profile_label').html(); | |
+ chrome.tabs.sendMessage(tab.id, {request: "refreshLocalStorage", data: newProfileStorageData}, function(resp) { | |
domainProfiles[currentProfile] = oldProfileData; | |
profile[currentDomain]['currentProfile'] = target.innerHTML; | |
profile[currentDomain]['profileData'] = domainProfiles; | |
- | |
for(var i=0; i<cookies.length;i++) { | |
chrome.cookies.remove({url: extrapolateUrlFromCookie(cookies[i]), name: cookies[i].name}); | |
} | |
- if(newProfileData.length > 0){for (var i=0; i<newProfileData.length;i++){ | |
- newProfileData[i]['url'] = "http" + (newProfileData[i]['secure'] ? "s" : "") + "://" + newProfileData[i]['domain']; | |
- delete newProfileData[i]['hostOnly']; | |
- delete newProfileData[i]['session']; | |
- console.log(JSON.stringify(newProfileData)); | |
- chrome.cookies.set(newProfileData[i]); | |
+ if(newProfileCookieData.length > 0){for (var i=0; i<newProfileCookieData.length;i++){ | |
+ newProfileCookieData[i]['url'] = "http" + (newProfileCookieData[i]['secure'] ? "s" : "") + "://" + newProfileCookieData[i]['domain']; | |
+ delete newProfileCookieData[i]['hostOnly']; | |
+ delete newProfileCookieData[i]['session']; | |
+ console.log(JSON.stringify(newProfileCookieData)); | |
+ chrome.cookies.set(newProfileCookieData[i]); | |
}} | |
- | |
- | |
- | |
if (typeof saveData === 'undefined' || saveData == true) { | |
chrome.storage.local.set({ "profiles": profile }, function(){ | |
loadProfiles(); | |
}); | |
} | |
- | |
- | |
- //$('#storage_label').text(JSON.stringify(newProfileData)); | |
- | |
+ //$('#storage_label').text(JSON.stringify(newProfileCookieData)); | |
chrome.tabs.query({active: true, currentWindow: true}, function (arrayOfTabs) { | |
var code = 'window.location.reload();'; | |
chrome.tabs.executeScript(arrayOfTabs[0].id, {code: code}); | |
}); | |
- | |
}); | |
}); | |
+ }); | |
+ }); | |
//$('#message_label').text("Profile Change Button clicked " + target.innerHTML); | |
} | |
// END PROFILE FUNCTIONS // | |
@@ -340,10 +335,6 @@ function loadDomainCookieStore(){ | |
} | |
// END COOKIE FUNCTIONS // | |
- | |
- | |
- | |
- | |
function domainLoaded(){ //CODE TO EXECUTE WHEN DOMAIN HAS BEEN LOADED | |
document.getElementById('domain_label').innerHTML = currentDomain; | |
$('#profileCreate_button').data('domain', currentDomain); | |
@@ -363,11 +354,4 @@ function init(){ //POP-UP OPENED, INITIALIZE | |
document.addEventListener('DOMContentLoaded', function() { | |
init(); | |
document.querySelector('#profileCreate_button').addEventListener('click', newProfile); | |
- //document.body.addEventListener('click', focusFilter); | |
- //document.querySelector('#remove_button').addEventListener('click', removeAll); | |
- //document.querySelector('#import_button').addEventListener('click', importCookies); | |
- //document.querySelector('#filter_div input').addEventListener( | |
- // 'input', reloadCookieTable); | |
- //document.querySelector('#filter_div button').addEventListener( | |
- // 'click', resetFilter); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment