mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
code review
This commit is contained in:
parent
690421aead
commit
abc7a526da
@ -983,19 +983,8 @@ vAPI.cloud = (function() {
|
|||||||
var maxStorageSize = chrome.storage.sync.QUOTA_BYTES;
|
var maxStorageSize = chrome.storage.sync.QUOTA_BYTES;
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
deviceName: ''
|
defaultDeviceName: window.navigator.platform,
|
||||||
};
|
deviceName: window.localStorage.getItem('deviceName') || ''
|
||||||
|
|
||||||
var getDeviceName = function() {
|
|
||||||
// Assign a permanent user-friendly id to this uBlock instance if one does
|
|
||||||
// not exist. This will allow to have some sort of identifier for a user
|
|
||||||
// to possibly identify the source of cloud data.
|
|
||||||
var name = window.localStorage.getItem('deviceName') || '';
|
|
||||||
if ( name !== '' ) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
return window.navigator.platform;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is used to find out a rough count of how many chunks exists:
|
// This is used to find out a rough count of how many chunks exists:
|
||||||
@ -1004,6 +993,7 @@ vAPI.cloud = (function() {
|
|||||||
// This allows reading a single item with only 2 sync operations -- a
|
// This allows reading a single item with only 2 sync operations -- a
|
||||||
// good thing given chrome.storage.syncMAX_WRITE_OPERATIONS_PER_MINUTE
|
// good thing given chrome.storage.syncMAX_WRITE_OPERATIONS_PER_MINUTE
|
||||||
// and chrome.storage.syncMAX_WRITE_OPERATIONS_PER_HOUR.
|
// and chrome.storage.syncMAX_WRITE_OPERATIONS_PER_HOUR.
|
||||||
|
|
||||||
var getCoarseChunkCount = function(dataKey, callback) {
|
var getCoarseChunkCount = function(dataKey, callback) {
|
||||||
var bin = {};
|
var bin = {};
|
||||||
for ( var i = 0; i < maxChunkCountPerItem; i += 16 ) {
|
for ( var i = 0; i < maxChunkCountPerItem; i += 16 ) {
|
||||||
@ -1016,9 +1006,6 @@ vAPI.cloud = (function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Could loop backward... let's assume for now
|
|
||||||
// maxChunkCountPerItem could be something else than a
|
|
||||||
// multiple of 16.
|
|
||||||
var chunkCount = 0;
|
var chunkCount = 0;
|
||||||
for ( var i = 0; i < maxChunkCountPerItem; i += 16 ) {
|
for ( var i = 0; i < maxChunkCountPerItem; i += 16 ) {
|
||||||
if ( bin[dataKey + i.toString()] === '' ) {
|
if ( bin[dataKey + i.toString()] === '' ) {
|
||||||
@ -1052,7 +1039,7 @@ vAPI.cloud = (function() {
|
|||||||
|
|
||||||
var push = function(dataKey, data, callback) {
|
var push = function(dataKey, data, callback) {
|
||||||
var item = JSON.stringify({
|
var item = JSON.stringify({
|
||||||
'source': getDeviceName(),
|
'source': options.deviceName || options.defaultDeviceName,
|
||||||
'tstamp': Date.now(),
|
'tstamp': Date.now(),
|
||||||
'data': data
|
'data': data
|
||||||
});
|
});
|
||||||
@ -1129,7 +1116,6 @@ vAPI.cloud = (function() {
|
|||||||
if ( typeof callback !== 'function' ) {
|
if ( typeof callback !== 'function' ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(options);
|
callback(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1140,11 +1126,10 @@ vAPI.cloud = (function() {
|
|||||||
|
|
||||||
if ( typeof details.deviceName === 'string' ) {
|
if ( typeof details.deviceName === 'string' ) {
|
||||||
window.localStorage.setItem('deviceName', details.deviceName);
|
window.localStorage.setItem('deviceName', details.deviceName);
|
||||||
|
options.deviceName = details.deviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeof callback === 'function' ) {
|
getOptions(callback);
|
||||||
callback(options);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -2905,35 +2905,28 @@ vAPI.cloud = (function() {
|
|||||||
var cloudBranchPath = extensionBranchPath + '.cloudStorage';
|
var cloudBranchPath = extensionBranchPath + '.cloudStorage';
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
|
defaultDeviceName: '',
|
||||||
deviceName: ''
|
deviceName: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
var getDeviceName = function() {
|
// User-supplied device name.
|
||||||
|
try {
|
||||||
|
options.deviceName = Services.prefs
|
||||||
|
.getBranch(extensionBranchPath + '.')
|
||||||
|
.getCharPref('deviceName');
|
||||||
|
} catch(ex) {
|
||||||
|
}
|
||||||
|
|
||||||
|
var getDefaultDeviceName = function() {
|
||||||
var name = '';
|
var name = '';
|
||||||
|
|
||||||
// User-supplied device name.
|
|
||||||
var branch = Services.prefs.getBranch(extensionBranchPath + '.');
|
|
||||||
try {
|
try {
|
||||||
name = branch.getCharPref('deviceName');
|
name = Services.prefs
|
||||||
|
.getBranch('services.sync.client.')
|
||||||
|
.getCharPref('name');
|
||||||
} catch(ex) {
|
} catch(ex) {
|
||||||
}
|
}
|
||||||
options.deviceName = name;
|
|
||||||
if ( name !== '' ) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No name: try to use device name specified by user in Preferences.
|
return name || window.navigator.platform || window.navigator.oscpu;
|
||||||
branch = Services.prefs.getBranch('services.sync.client.');
|
|
||||||
try {
|
|
||||||
name = branch.getCharPref('name');
|
|
||||||
} catch(ex) {
|
|
||||||
}
|
|
||||||
if ( name !== '' ) {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No name: use os/cpu.
|
|
||||||
return window.navigator.platform || window.navigator.oscpu;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var start = function(dataKeys) {
|
var start = function(dataKeys) {
|
||||||
@ -2954,7 +2947,7 @@ vAPI.cloud = (function() {
|
|||||||
var push = function(datakey, data, callback) {
|
var push = function(datakey, data, callback) {
|
||||||
var branch = Services.prefs.getBranch(cloudBranchPath + '.');
|
var branch = Services.prefs.getBranch(cloudBranchPath + '.');
|
||||||
var bin = {
|
var bin = {
|
||||||
'source': getDeviceName(),
|
'source': options.deviceName || getDefaultDeviceName(),
|
||||||
'tstamp': Date.now(),
|
'tstamp': Date.now(),
|
||||||
'data': data
|
'data': data
|
||||||
};
|
};
|
||||||
@ -2981,7 +2974,7 @@ vAPI.cloud = (function() {
|
|||||||
if ( typeof callback !== 'function' ) {
|
if ( typeof callback !== 'function' ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
options.defaultDeviceName = getDefaultDeviceName();
|
||||||
callback(options);
|
callback(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2994,11 +2987,10 @@ vAPI.cloud = (function() {
|
|||||||
|
|
||||||
if ( typeof details.deviceName === 'string' ) {
|
if ( typeof details.deviceName === 'string' ) {
|
||||||
branch.setCharPref('deviceName', details.deviceName);
|
branch.setCharPref('deviceName', details.deviceName);
|
||||||
|
options.deviceName = details.deviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeof callback === 'function' ) {
|
getOptions(callback);
|
||||||
callback(options);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
<a type="text/plain" target="_blank" href=""></a>
|
<a type="text/plain" target="_blank" href=""></a>
|
||||||
<a class="fa" style="display: none;" target="_blank"></a>
|
<a class="fa" style="display: none;" target="_blank"></a>
|
||||||
<a href="" style="display: none;" target="_blank"></a>: <!--
|
<a href="" style="display: none;" target="_blank"></a>: <!--
|
||||||
--><span class="dim"></span><!--
|
--><span class="counts dim"></span><!--
|
||||||
--><span class="status unsecure" style="display: none;">http</span><!--
|
--><span class="status unsecure" style="display: none;">http</span><!--
|
||||||
--><span class="status new" style="display: none;" data-i18n="3pExternalListNew"></span><!--
|
--><span class="status new" style="display: none;" data-i18n="3pExternalListNew"></span><!--
|
||||||
--><span class="status obsolete" style="display: none;" data-i18n="3pExternalListObsolete"></span><!--
|
--><span class="status obsolete" style="display: none;" data-i18n="3pExternalListObsolete"></span><!--
|
||||||
|
@ -116,7 +116,7 @@ var renderFilterLists = function() {
|
|||||||
elem.css('display', '');
|
elem.css('display', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
elem = li.descendants('span:nth-of-type(1)');
|
elem = li.descendants('span.counts');
|
||||||
var text = listStatsTemplate
|
var text = listStatsTemplate
|
||||||
.replace('{{used}}', renderNumber(!entry.off && !isNaN(+entry.entryUsedCount) ? entry.entryUsedCount : 0))
|
.replace('{{used}}', renderNumber(!entry.off && !isNaN(+entry.entryUsedCount) ? entry.entryUsedCount : 0))
|
||||||
.replace('{{total}}', !isNaN(+entry.entryCount) ? renderNumber(entry.entryCount) : '?');
|
.replace('{{total}}', !isNaN(+entry.entryCount) ? renderNumber(entry.entryCount) : '?');
|
||||||
@ -486,10 +486,8 @@ var renderExternalLists = function() {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var externalListsChangeHandler = function() {
|
var externalListsChangeHandler = function() {
|
||||||
uDom('#externalListsApply').prop(
|
uDom.nodeFromId('externalListsApply').disabled =
|
||||||
'disabled',
|
uDom.nodeFromId('externalLists').value.trim() === externalLists;
|
||||||
this.value.trim() === externalLists
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user