Skip to content

Commit 98c6ad4

Browse files
committed
Release version 2.12
Fix options page on some browsers
1 parent b564c09 commit 98c6ad4

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

background.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,6 @@ let historyProcessor;
314314

315315
let opt; //Master options variable
316316

317-
//Get proper storage mechanism
318-
function storage() {
319-
return chrome.storage.sync || chrome.storage.local;
320-
}
321-
322317
//Load settings
323318
function loadSettings() {
324319
storage().get(DEFAULT_OPTIONS(), function(items) {

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"short_name": "DynamicHistory",
1010
"author": "nulldev",
1111
"description": "Automagically delete history based on the keywords on the page!",
12-
"version": "2.11",
12+
"version": "2.12",
1313
"options_ui": {
1414
"page": "options.html",
1515
"chrome_style": true,

options.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
* Core JS for Settings
1313
*/
1414

15-
//Get proper storage mechanism
16-
function storage() {
17-
//Attempt to use synced storage, otherwise fallback to local storage
18-
return chrome.storage.sync || chrome.storage.local;
19-
}
20-
2115
//Load settings
2216
function loadSettings(callback) {
2317
storage().get(DEFAULT_OPTIONS(), function(items) {
@@ -230,7 +224,7 @@ jQuery(document).ready(function () {
230224
$("#clear_modal .close").click(hideModal);
231225
$("#clear_no_btn").click(hideModal);
232226
$("#clear_yes_btn").click(function() {
233-
chrome.storage.sync.clear(function() {
227+
storage().clear(function() {
234228
loadSettings();
235229
});
236230
hideModal();

shared.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,56 @@ function DEFAULT_OPTIONS() {
4242
jsCode: ''
4343
};
4444
}
45+
46+
//Get proper storage mechanism
47+
function storage() {
48+
// Reliable storage shim
49+
return {
50+
get: function(def, callback) {
51+
// Always try sync storage first
52+
if(chrome.storage.sync != null) {
53+
chrome.storage.sync.get(def, function(items) {
54+
if(items != null) {
55+
// Sync storage works! Use sync storage items!
56+
callback(items);
57+
} else {
58+
// Sync storage not available
59+
// use local
60+
chrome.storage.local.get(def, callback);
61+
}
62+
});
63+
} else {
64+
// Sync storage not enabled so only choice is local
65+
chrome.storage.local.get(def, callback);
66+
}
67+
},
68+
set: function(contents, callback) {
69+
// Set both storages (cannot reliably detect which is available)
70+
if(chrome.storage.sync != null) {
71+
// Set sync first (callback will still be called even
72+
// if sync is disabled)
73+
chrome.storage.sync.set(contents, function() {
74+
// Done setting sync, set local
75+
chrome.storage.local.set(contents, callback);
76+
});
77+
} else {
78+
// Sync not enabled, only set local
79+
chrome.storage.local.set(contents, callback);
80+
}
81+
},
82+
clear: function(callback) {
83+
// Clear both storages (cannot reliably detect which is available)
84+
if(chrome.storage.sync != null) {
85+
// Clear sync first (callback will still be called even
86+
// if sync is disabled)
87+
chrome.storage.sync.clear(function() {
88+
// Done clearing sync, clear local
89+
chrome.storage.local.clear(callback);
90+
});
91+
} else {
92+
// Sync not enabled, only clear local
93+
chrome.storage.local.clear(callback);
94+
}
95+
}
96+
};
97+
}

0 commit comments

Comments
 (0)