fix #840 (need confirmation)

pull/2/head 1.1.16
gorhill 8 years ago
parent 8660d35dcf
commit 3ff2926871
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

@ -2,7 +2,7 @@
"manifest_version": 2, "manifest_version": 2,
"name": "uMatrix", "name": "uMatrix",
"short_name": "uMatrix", "short_name": "uMatrix",
"version": "1.1.14", "version": "1.1.16",
"description": "__MSG_extShortDesc__", "description": "__MSG_extShortDesc__",
"icons": { "icons": {
"16": "img/icon_16.png", "16": "img/icon_16.png",

@ -85,31 +85,39 @@ vAPI.closePopup = function() {
// This storage is optional, but it is nice to have, for a more polished user // This storage is optional, but it is nice to have, for a more polished user
// experience. // experience.
// This can throw in some contexts (like in devtool).
try {
vAPI.localStorage = self.localStorage;
} catch (ex) {
}
// https://github.com/gorhill/uBlock/issues/2824 // https://github.com/gorhill/uBlock/issues/2824
// Use a dummy localStorage if for some reasons it's not available. // Use a dummy localStorage if for some reasons it's not available.
if ( vAPI.localStorage instanceof Object === false ) {
vAPI.localStorage = { // https://github.com/gorhill/uMatrix/issues/840
length: 0, // Always use a wrapper to seamlessly handle exceptions
clear: function() {
}, vAPI.localStorage = {
getItem: function() { clear: function() {
return null; try {
}, window.localStorage.clear();
key: function() { } catch(ex) {
throw new RangeError();
},
removeItem: function() {
},
setItem: function() {
} }
}; },
} getItem: function(key) {
try {
return window.localStorage.getItem(key);
} catch(ex) {
}
return null;
},
removeItem: function(key) {
try {
window.localStorage.removeItem(key);
} catch(ex) {
}
},
setItem: function(key, value) {
try {
window.localStorage.setItem(key, value);
} catch(ex) {
}
}
};
/******************************************************************************/ /******************************************************************************/

@ -489,13 +489,22 @@ var evaluateURLs = function(tabId, requests) {
} }
if ( placeholders === null ) { if ( placeholders === null ) {
var bg = vAPI.localStorage.getItem('placeholderBackground');
placeholders = { placeholders = {
background: bg, background:
border: vAPI.localStorage.getItem('placeholderBorder'), vAPI.localStorage.getItem('placeholderBackground') ||
iframe: vAPI.localStorage.getItem('placeholderDocument').replace('{{bg}}', bg), µm.defaultLocalUserSettings.placeholderBackground,
img: vAPI.localStorage.getItem('placeholderImage') border:
vAPI.localStorage.getItem('placeholderBorder') ||
µm.defaultLocalUserSettings.placeholderBorder,
iframe:
vAPI.localStorage.getItem('placeholderDocument') ||
µm.defaultLocalUserSettings.placeholderDocument,
img:
vAPI.localStorage.getItem('placeholderImage') ||
µm.defaultLocalUserSettings.placeholderImage
}; };
placeholders.iframe =
placeholders.iframe.replace('{{bg}}', placeholders.background);
} }
response.placeholders = placeholders; response.placeholders = placeholders;

@ -35,8 +35,8 @@
// Stuff which is good to do very early so as to avoid visual glitches. // Stuff which is good to do very early so as to avoid visual glitches.
(function() { (function() {
var paneContentPaddingTop = localStorage.getItem('paneContentPaddingTop'), var paneContentPaddingTop = vAPI.localStorage.getItem('paneContentPaddingTop'),
touchDevice = localStorage.getItem('touchDevice'); touchDevice = vAPI.localStorage.getItem('touchDevice');
if ( typeof paneContentPaddingTop === 'string' ) { if ( typeof paneContentPaddingTop === 'string' ) {
document.querySelector('.paneContent').style.setProperty( document.querySelector('.paneContent').style.setProperty(
@ -50,7 +50,7 @@
document.addEventListener('touchstart', function onTouched(ev) { document.addEventListener('touchstart', function onTouched(ev) {
document.removeEventListener(ev.type, onTouched); document.removeEventListener(ev.type, onTouched);
document.body.setAttribute('data-touch', 'true'); document.body.setAttribute('data-touch', 'true');
localStorage.setItem('touchDevice', 'true'); vAPI.localStorage.setItem('touchDevice', 'true');
resizePopup(); resizePopup();
}); });
} }
@ -71,7 +71,7 @@ var resizePopup = (function() {
paneContent = doc.querySelector('.paneContent'); paneContent = doc.querySelector('.paneContent');
if ( paddingTop !== paneContent.style.paddingTop ) { if ( paddingTop !== paneContent.style.paddingTop ) {
paneContent.style.setProperty('padding-top', paddingTop); paneContent.style.setProperty('padding-top', paddingTop);
localStorage.setItem('paneContentPaddingTop', paddingTop); vAPI.localStorage.setItem('paneContentPaddingTop', paddingTop);
} }
document.body.classList.toggle( document.body.classList.toggle(
'hConstrained', 'hConstrained',

@ -54,7 +54,7 @@ var µm = µMatrix;
*/ */
var defaultLocalUserSettings = { µm.defaultLocalUserSettings = {
// data-URI background courtesy of https://github.com/dev-random // data-URI background courtesy of https://github.com/dev-random
// https://github.com/gorhill/uMatrix/issues/429#issuecomment-194548243 // https://github.com/gorhill/uMatrix/issues/429#issuecomment-194548243
placeholderBackground: [ placeholderBackground: [
@ -135,15 +135,15 @@ var onAllDone = function() {
µm.assets.addObserver(µm.assetObserver.bind(µm)); µm.assets.addObserver(µm.assetObserver.bind(µm));
µm.scheduleAssetUpdater(µm.userSettings.autoUpdate ? 7 * 60 * 1000 : 0); µm.scheduleAssetUpdater(µm.userSettings.autoUpdate ? 7 * 60 * 1000 : 0);
for ( var key in defaultLocalUserSettings ) { for ( var key in µm.defaultLocalUserSettings ) {
if ( defaultLocalUserSettings.hasOwnProperty(key) === false ) { if (µm. defaultLocalUserSettings.hasOwnProperty(key) === false ) {
continue; continue;
} }
if ( if (
vAPI.localStorage.getItem(key) === null || vAPI.localStorage.getItem(key) === null ||
rwLocalUserSettings.hasOwnProperty(key) === false rwLocalUserSettings.hasOwnProperty(key) === false
) { ) {
vAPI.localStorage.setItem(key, defaultLocalUserSettings[key]); vAPI.localStorage.setItem(key, µm.defaultLocalUserSettings[key]);
} }
} }

Loading…
Cancel
Save