Browse Source

fix #840 (need confirmation)

pull/2/head 1.1.16
gorhill 7 years ago
parent
commit
3ff2926871
No known key found for this signature in database GPG Key ID: 25E1490B761470C2
  1. 2
      platform/chromium/manifest.json
  2. 52
      platform/chromium/vapi-common.js
  3. 19
      src/js/messaging.js
  4. 8
      src/js/popup.js
  5. 8
      src/js/start.js

2
platform/chromium/manifest.json

@ -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",

52
platform/chromium/vapi-common.js

@ -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 = {
length: 0,
clear: function() {
},
getItem: function() {
return null;
},
key: function() {
throw new RangeError();
},
removeItem: function() {
},
setItem: function() {
// https://github.com/gorhill/uMatrix/issues/840
// Always use a wrapper to seamlessly handle exceptions
vAPI.localStorage = {
clear: function() {
try {
window.localStorage.clear();
} catch(ex) {
} }
};
}
},
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) {
}
}
};
/******************************************************************************/ /******************************************************************************/

19
src/js/messaging.js

@ -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,
border: vAPI.localStorage.getItem('placeholderBorder'),
iframe: vAPI.localStorage.getItem('placeholderDocument').replace('{{bg}}', bg),
img: vAPI.localStorage.getItem('placeholderImage')
background:
vAPI.localStorage.getItem('placeholderBackground') ||
µm.defaultLocalUserSettings.placeholderBackground,
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;

8
src/js/popup.js

@ -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'),
touchDevice = localStorage.getItem('touchDevice');
var paneContentPaddingTop = vAPI.localStorage.getItem('paneContentPaddingTop'),
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',

8
src/js/start.js

@ -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 ) {
if ( defaultLocalUserSettings.hasOwnProperty(key) === false ) {
for ( var key in µm.defaultLocalUserSettings ) {
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