From ea17ca828aabb9d598f21070dc23027f6c95a834 Mon Sep 17 00:00:00 2001 From: andryou Date: Tue, 7 Feb 2017 23:39:44 -0500 Subject: [PATCH] Improve sync --- html/updated.html | 1 + js/options.js | 11 +++--- js/scriptsafe.js | 98 ++++++++++++++++++++++++++++++++++------------- 3 files changed, 78 insertions(+), 32 deletions(-) diff --git a/html/updated.html b/html/updated.html index 1f6f215..60a6e08 100644 --- a/html/updated.html +++ b/html/updated.html @@ -40,6 +40,7 @@
  • Added ability to control the Keyboard Fingerprinting Protection keypress delay
  • Improved WebGL Fingerprint Protection
  • Improved Clipboard Interference Protection
  • +
  • Improved syncing reliability
  • Minor updates to German, Japanese, and Chinese (Traditional) locales
  • Updated unwanted content providers list
  • Minor panel updates
  • diff --git a/js/options.js b/js/options.js index e424646..b1d9554 100644 --- a/js/options.js +++ b/js/options.js @@ -294,19 +294,18 @@ function loadElement(id) { $("#"+id).val(localStorage[id]); } function saveCheckbox(id) { - localStorage[id] = document.getElementById(id).checked; if (id == 'syncenable') { if (!document.getElementById(id).checked) { syncstatus = 'false'; - return; - } - if (syncstatus == 'false') { - alert(bkg.getLocale("forcesyncimport")); - syncstatus = 'true'; } else { + if (syncstatus == 'false' && confirm(bkg.getLocale("forcesyncimport"))) { + bkg.importSyncHandle(1); + setTimeout(function(){ window.location.reload(1); }, 10000); + } syncstatus = 'true'; } } + localStorage[id] = document.getElementById(id).checked; } function saveElement(id) { localStorage[id] = $("#"+id).val(); diff --git a/js/scriptsafe.js b/js/scriptsafe.js index ed121d1..eb2191b 100644 --- a/js/scriptsafe.js +++ b/js/scriptsafe.js @@ -1001,21 +1001,28 @@ function freshSync(mode, force) { window.clearTimeout(synctimer); var settingssync = {}; var simplesettings = ''; + var fpsettings = ''; + var zarr = {}; + zarr['zw'] = []; + zarr['zb'] = []; + zarr['zfp'] = []; if (force) { - // mode == 0 = all; 1 = settings only; 2 = whitelist/blacklist - //if (mode == 0 || mode == 1) { for (var k in localStorage) { - if (k != "version" && k != "sync" && k != "scriptsafe_settings" && k != "lastSync" && k != "whiteList" && k != "blackList" && k != "whiteListCount" && k != "blackListCount" && k.substr(0, 10) != "whiteList_" && k.substr(0, 10) != "blackList_" && k.substr(0, 2) != "zb" && k.substr(0, 2) != "zw") { + if (k != "version" && k != "sync" && k != "scriptsafe_settings" && k != "lastSync" && k != "whiteList" && k != "blackList" && k != "whiteListCount" && k != "blackListCount" && k != "fpCount" && k.substr(0, 10) != "whiteList_" && k.substr(0, 10) != "blackList_" && k.substr(0, 2) != "zb" && k.substr(0, 2) != "zw" && k.substr(0, 2) != "fp") { simplesettings += k+"|"+localStorage[k]+"~"; + } else if (k.substr(0, 2) == "fp" && k != "fpCount") { + fpsettings += k+"|"+localStorage[k]+"~"; } + if (k.substr(0, 2) == "zw") zarr['zw'].push(k); + if (k.substr(0, 2) == "zb") zarr['zb'].push(k); + if (k.substr(0, 3) == "zfp") zarr['zfp'].push(k); + } + settingssync['scriptsafe_settings'] = simplesettings.slice(0,-1); + if (zarr['zw'].length) { + for (var x = 0; x < zarr['zw'].length; x++) delete localStorage[zarr['zw'][x]]; } - simplesettings = simplesettings.slice(0,-1); - settingssync['scriptsafe_settings'] = simplesettings; - //} - //if (mode == 0 || mode == 2) { var jsonstr = JSON.parse(localStorage['whiteList']).toString(); - var jsonstrlen = jsonstr.length; - var limit = (chrome.storage.sync.QUOTA_BYTES_PER_ITEM - Math.ceil(jsonstrlen/(chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 4)) - 4); + var limit = (chrome.storage.sync.QUOTA_BYTES_PER_ITEM - Math.ceil(jsonstr.length/(chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 4)) - 4); var i = 0; while (jsonstr.length > 0) { var segment = jsonstr.substr(0, limit); @@ -1026,9 +1033,11 @@ function freshSync(mode, force) { } localStorage['whiteListCount'] = i; settingssync['whiteListCount'] = i; + if (zarr['zb'].length) { + for (var x = 0; x < zarr['zb'].length; x++) delete localStorage[zarr['zb'][x]]; + } jsonstr = JSON.parse(localStorage['blackList']).toString(); - jsonstrlen = jsonstr.length; - limit = (chrome.storage.sync.QUOTA_BYTES_PER_ITEM - Math.ceil(jsonstrlen/(chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 4)) - 4); + limit = (chrome.storage.sync.QUOTA_BYTES_PER_ITEM - Math.ceil(jsonstr.length/(chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 4)) - 4); i = 0; while (jsonstr.length > 0) { var segment = jsonstr.substr(0, limit); @@ -1039,7 +1048,21 @@ function freshSync(mode, force) { } localStorage['blackListCount'] = i; settingssync['blackListCount'] = i; - //} + if (zarr['zfp'].length) { + for (var x = 0; x < zarr['zfp'].length; x++) delete localStorage[zarr['zfp'][x]]; + } + jsonstr = fpsettings.slice(0,-1); + limit = (chrome.storage.sync.QUOTA_BYTES_PER_ITEM - Math.ceil(jsonstr.length/(chrome.storage.sync.QUOTA_BYTES_PER_ITEM - 4)) - 4); + i = 0; + while (jsonstr.length > 0) { + var segment = jsonstr.substr(0, limit); + settingssync["zfp" + i] = segment; + localStorage["zfp" + i] = segment; + jsonstr = jsonstr.substr(limit); + i++; + } + localStorage['fpCount'] = i; + settingssync['fpCount'] = i; var milliseconds = (new Date).getTime(); localStorage['lastSync'] = milliseconds; settingssync['lastSync'] = milliseconds; @@ -1064,9 +1087,10 @@ function syncQueue() { function importSyncHandle(mode) { if (storageapi) { if (mode == '1' || (localStorage['sync'] == 'false' && mode == '0')) { + window.clearTimeout(synctimer); chrome.storage.sync.get(null, function(changes) { - if (typeof changes['lastSync'] !== 'undefined' && typeof changes['scriptsafe_settings'] !== 'undefined' && (typeof changes['zw0'] !== 'undefined' || typeof changes['zb0'] !== 'undefined')) { - if (changes['zw0'] != '' && changes['zw0'] != '*.googlevideo.com') { // ensure synced whitelist is not empty and not the default + if (typeof changes['lastSync'] !== 'undefined' && typeof changes['scriptsafe_settings'] !== 'undefined' && (typeof changes['zw0'] !== 'undefined' || typeof changes['zb0'] !== 'undefined' || typeof changes['zfp0'] !== 'undefined')) { + if (!optionExists('lastSync') || (optionExists('lastSync') && changes['lastSync'] >= localStorage['lastSync'])) { if (confirm(getLocale("syncdetect"))) { localStorage['syncenable'] = 'true'; localStorage['sync'] = 'true'; @@ -1124,20 +1148,42 @@ function importSync(changes, mode) { } function listsSync(mode) { if (mode == '1' || mode == '2') { - var concatlist = ''; - for (var i = 0; i < localStorage['whiteListCount']; i++) { - concatlist += localStorage['zw'+i]; + var concatlist; + if (optionExists('whiteListCount')) { + concatlist = ''; + for (var i = 0; i < localStorage['whiteListCount']; i++) { + concatlist += localStorage['zw'+i]; + } + var concatlistarr = concatlist.split(","); + if (concatlist == '' || concatlistarr.length == 0) localStorage['whiteList'] = JSON.stringify([]); + else localStorage['whiteList'] = JSON.stringify(concatlistarr); + } + if (optionExists('blackListCount')) { + concatlist = ''; + for (var i = 0; i < localStorage['blackListCount']; i++) { + concatlist += localStorage['zb'+i]; + } + concatlistarr = concatlist.split(","); + if (concatlist == '' || concatlistarr.length == 0) localStorage['blackList'] = JSON.stringify([]); + else localStorage['blackList'] = JSON.stringify(concatlistarr); } - var concatlistarr = concatlist.split(","); - if (concatlist == '' || concatlistarr.length == 0) localStorage['whiteList'] = JSON.stringify([]); - else localStorage['whiteList'] = JSON.stringify(concatlistarr); - concatlist = ''; - for (var i = 0; i < localStorage['blackListCount']; i++) { - concatlist += localStorage['zb'+i]; + if (optionExists('fpCount')) { + concatlist = ''; + for (var i = 0; i < localStorage['fpCount']; i++) { + concatlist += localStorage['zfp'+i]; + } + var settings = concatlist.split("~"); + if (settings.length > 0) { + $.each(settings, function(i, v) { + if ($.trim(v) != "") { + var settingentry = $.trim(v).split("|"); + if ($.trim(settingentry[1]) != '') { + localStorage[$.trim(settingentry[0])] = $.trim(settingentry[1]); + } + } + }); + } } - concatlistarr = concatlist.split(","); - if (concatlist == '' || concatlistarr.length == 0) localStorage['blackList'] = JSON.stringify([]); - else localStorage['blackList'] = JSON.stringify(concatlistarr); cacheLists(); cacheFpLists(); }