Replace localStorage
calls with prefs
calls
This commit is contained in:
parent
e7f6c62e01
commit
f54a70fe07
|
@ -316,7 +316,7 @@ chrome.tabs.onAttached.addListener(function(tabId, data) {
|
|||
if (tabData.url.indexOf(editFullUrl) == 0) {
|
||||
chrome.windows.get(tabData.windowId, {populate: true}, function(win) {
|
||||
// If there's only one tab in this window, it's been dragged to new window
|
||||
localStorage['openEditInWindow'] = win.tabs.length == 1 ? "true" : "false";
|
||||
prefs.setPref('openEditInWindow', win.tabs.length == 1);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
2
edit.js
2
edit.js
|
@ -24,7 +24,7 @@ function setupCodeMirror(textarea) {
|
|||
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter", "CodeMirror-lint-markers"],
|
||||
matchBrackets: true,
|
||||
lint: CodeMirror.lint.css,
|
||||
smartIndent: (typeof localStorage["smart-indent"] == "undefined") || localStorage["smart-indent"] == "true",
|
||||
smartIndent: prefs.getPref("smart-indent"),
|
||||
extraKeys: {"Ctrl-Space": "autocomplete"}
|
||||
});
|
||||
editors.push(cm);
|
||||
|
|
|
@ -10,7 +10,7 @@ function notifyAllTabs(request) {
|
|||
}
|
||||
|
||||
function updateBadgeText(tab) {
|
||||
if (localStorage["show-badge"] == "true") {
|
||||
if (prefs.getPref("show-badge")) {
|
||||
function stylesReceived(styles) {
|
||||
var t = getBadgeText(styles);
|
||||
console.log("Tab " + tab.id + " (" + tab.url + ") badge text set to '" + t + "'.");
|
||||
|
|
2
popup.js
2
popup.js
|
@ -122,7 +122,7 @@ function getId(event) {
|
|||
|
||||
function openLinkInTabOrWindow(event) {
|
||||
event.preventDefault();
|
||||
if (localStorage['openEditInWindow'] == 'true') {
|
||||
if (prefs.getPref('openEditInWindow', false)) {
|
||||
chrome.windows.create({url: event.target.href});
|
||||
} else {
|
||||
chrome.tabs.create({url: event.target.href});
|
||||
|
|
22
storage.js
22
storage.js
|
@ -21,20 +21,10 @@ function getDatabase(ready, error) {
|
|||
} else if (stylishDb.version == "1.4") {
|
||||
dbV15(stylishDb, error, ready);
|
||||
} else {
|
||||
defaultPrefs();
|
||||
ready(stylishDb);
|
||||
}
|
||||
}
|
||||
|
||||
function defaultPrefs() {
|
||||
if (!("show-badge" in localStorage)) {
|
||||
localStorage["show-badge"] = true;
|
||||
}
|
||||
if (!("smart-indent" in localStorage)) {
|
||||
localStorage["smart-indent"] = true;
|
||||
}
|
||||
}
|
||||
|
||||
function dbV11(d, error, done) {
|
||||
d.changeVersion(d.version, '1.1', function (t) {
|
||||
t.executeSql('CREATE TABLE styles (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, url TEXT, updateUrl TEXT, md5Url TEXT, name TEXT NOT NULL, code TEXT NOT NULL, enabled INTEGER NOT NULL, originalCode TEXT NULL);');
|
||||
|
@ -148,20 +138,16 @@ function isCheckbox(el) {
|
|||
|
||||
function changePref(event) {
|
||||
var el = event.target;
|
||||
var value = isCheckbox(el) ? el.checked : el.value;
|
||||
localStorage[el.id] = value
|
||||
notifyAllTabs({method: "prefChanged", prefName: el.id, value: value});
|
||||
prefs.setPref(el.id, isCheckbox(el) ? el.checked : el.value);
|
||||
}
|
||||
|
||||
// Accepts a hash of pref name to default value
|
||||
function loadPrefs(prefs) {
|
||||
for (var id in prefs) {
|
||||
var value = typeof localStorage[id] == "undefined" ? prefs[id] : localStorage[id];
|
||||
var value = this.prefs.getPref(id);
|
||||
var el = document.getElementById(id);
|
||||
if (isCheckbox(el)) {
|
||||
if (value == "true") {
|
||||
el.checked = true;
|
||||
}
|
||||
el.checked = value;
|
||||
} else {
|
||||
el.value = value;
|
||||
}
|
||||
|
@ -174,7 +160,7 @@ var prefs = {
|
|||
|
||||
// defaults
|
||||
"openEditInWindow": false, // new editor opens in a own browser window
|
||||
"show-badge": false, // display text on popup menu icon
|
||||
"show-badge": true, // display text on popup menu icon
|
||||
"smart-indent": true, // CodeMirror smart indent
|
||||
|
||||
"popup.breadcrumbs": true, // display "New style" links as URL breadcrumbs
|
||||
|
|
Loading…
Reference in New Issue
Block a user