Browse Source

code review

pull/2/head
gorhill 10 years ago
parent
commit
fb639870df
  1. 2
      src/js/contentscript-end.js
  2. 43
      src/js/messaging.js
  3. 4
      src/js/start.js

2
src/js/contentscript-end.js

@ -207,9 +207,11 @@ var collapser = (function() {
srcProps[tagName], srcProps[tagName],
placeholders[tagName].replace('{{url}}', request.url) placeholders[tagName].replace('{{url}}', request.url)
); );
if ( tagName !== 'iframe' ) {
target.style.setProperty('border', placeholders.border, 'important'); target.style.setProperty('border', placeholders.border, 'important');
target.style.setProperty('background', placeholders.background, 'important'); target.style.setProperty('background', placeholders.background, 'important');
} }
}
// Renew map: I believe that even if all properties are deleted, an // Renew map: I believe that even if all properties are deleted, an
// object will still use more memory than a brand new one. // object will still use more memory than a brand new one.

43
src/js/messaging.js

@ -441,10 +441,16 @@ var contentScriptLocalStorageHandler = function(tabId, pageURL) {
// Evaluate many URLs against the matrix. // Evaluate many URLs against the matrix.
var evaluateURLs = function(tabId, requests) { var evaluateURLs = function(tabId, requests) {
var collapse = µm.userSettings.collapseBlocked;
var response = {
collapse: collapse,
requests: requests
};
// Create evaluation context // Create evaluation context
var tabContext = µm.tabContextManager.lookup(tabId); var tabContext = µm.tabContextManager.lookup(tabId);
if ( tabContext === null ) { if ( tabContext === null ) {
return requests;
return response;
} }
var rootHostname = tabContext.rootHostname; var rootHostname = tabContext.rootHostname;
@ -463,14 +469,34 @@ var evaluateURLs = function(tabId, requests) {
); );
} }
return requests;
if ( collapse ) {
placeholders = null;
return response;
}
if ( placeholders === null ) {
var bg = vAPI.localStorage.getItem('placeholderBackground');
placeholders = {
background: bg,
border: vAPI.localStorage.getItem('placeholderBorder'),
iframe: vAPI.localStorage.getItem('placeholderDocument').replace('{{bg}}', encodeURIComponent(bg)),
img: vAPI.localStorage.getItem('placeholderImage')
}; };
}
response.placeholders = placeholders;
return response;
};
/******************************************************************************/
var tagNameToRequestTypeMap = { var tagNameToRequestTypeMap = {
'iframe': 'sub_frame', 'iframe': 'sub_frame',
'img': 'image' 'img': 'image'
}; };
var placeholders = null;
/******************************************************************************/ /******************************************************************************/
var onMessage = function(request, sender, callback) { var onMessage = function(request, sender, callback) {
@ -505,18 +531,7 @@ var onMessage = function(request, sender, callback) {
break; break;
case 'evaluateURLs': case 'evaluateURLs':
response = {
collapse: µm.userSettings.collapseBlocked,
requests: evaluateURLs(tabId, request.requests)
};
if ( !response.collapse ) {
response.placeholders = {
background: vAPI.localStorage.getItem('placeholderBackground'),
border: vAPI.localStorage.getItem('placeholderBorder'),
iframe: vAPI.localStorage.getItem('placeholderDocument'),
img: vAPI.localStorage.getItem('placeholderImage')
};
}
response = evaluateURLs(tabId, request.requests);
break; break;
case 'getUserAgentReplaceStr': case 'getUserAgentReplaceStr':

4
src/js/start.js

@ -84,7 +84,9 @@ var defaultLocalUserSettings = {
placeholderDocument: [ placeholderDocument: [
'data:text/html,', 'data:text/html,',
encodeURIComponent('<html><head><style>'), encodeURIComponent('<html><head><style>'),
encodeURIComponent('body { color: gray; font: 12px sans-serif; margin: 0; padding: 2px; white-space: nowrap; }'),
encodeURIComponent('body { background: '),
'{{bg}}',
encodeURIComponent('; color: gray; font: 12px sans-serif; margin: 0; padding: 2px; white-space: nowrap; }'),
encodeURIComponent('</style></head><body>'), encodeURIComponent('</style></head><body>'),
'{{url}}', '{{url}}',
encodeURIComponent('</body></html>') encodeURIComponent('</body></html>')

Loading…
Cancel
Save