Skip to content

Commit

Permalink
Improve sync
Browse files Browse the repository at this point in the history
  • Loading branch information
andryou committed Feb 8, 2017
1 parent 938da20 commit ea17ca8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 32 deletions.
1 change: 1 addition & 0 deletions html/updated.html
Expand Up @@ -40,6 +40,7 @@
<li>Added ability to control the Keyboard Fingerprinting Protection keypress delay</li>
<li>Improved WebGL Fingerprint Protection</li>
<li>Improved Clipboard Interference Protection</li>
<li>Improved syncing reliability</li>
<li>Minor updates to German, Japanese, and Chinese (Traditional) locales</li>
<li>Updated unwanted content providers list</li>
<li>Minor panel updates</li>
Expand Down
11 changes: 5 additions & 6 deletions js/options.js
Expand Up @@ -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();
Expand Down
98 changes: 72 additions & 26 deletions js/scriptsafe.js
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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';
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit ea17ca8

Please sign in to comment.