mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-06-02 10:24:59 +12:00
code review
This commit is contained in:
parent
d32137ced0
commit
fb639870df
|
@ -207,8 +207,10 @@ var collapser = (function() {
|
|||
srcProps[tagName],
|
||||
placeholders[tagName].replace('{{url}}', request.url)
|
||||
);
|
||||
target.style.setProperty('border', placeholders.border, 'important');
|
||||
target.style.setProperty('background', placeholders.background, 'important');
|
||||
if ( tagName !== 'iframe' ) {
|
||||
target.style.setProperty('border', placeholders.border, 'important');
|
||||
target.style.setProperty('background', placeholders.background, 'important');
|
||||
}
|
||||
}
|
||||
|
||||
// Renew map: I believe that even if all properties are deleted, an
|
||||
|
|
|
@ -441,10 +441,16 @@ var contentScriptLocalStorageHandler = function(tabId, pageURL) {
|
|||
// Evaluate many URLs against the matrix.
|
||||
|
||||
var evaluateURLs = function(tabId, requests) {
|
||||
var collapse = µm.userSettings.collapseBlocked;
|
||||
var response = {
|
||||
collapse: collapse,
|
||||
requests: requests
|
||||
};
|
||||
|
||||
// Create evaluation context
|
||||
var tabContext = µm.tabContextManager.lookup(tabId);
|
||||
if ( tabContext === null ) {
|
||||
return requests;
|
||||
return response;
|
||||
}
|
||||
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 = {
|
||||
'iframe': 'sub_frame',
|
||||
'img': 'image'
|
||||
};
|
||||
|
||||
var placeholders = null;
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
var onMessage = function(request, sender, callback) {
|
||||
|
@ -505,18 +531,7 @@ var onMessage = function(request, sender, callback) {
|
|||
break;
|
||||
|
||||
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;
|
||||
|
||||
case 'getUserAgentReplaceStr':
|
||||
|
|
|
@ -84,7 +84,9 @@ var defaultLocalUserSettings = {
|
|||
placeholderDocument: [
|
||||
'data:text/html,',
|
||||
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>'),
|
||||
'{{url}}',
|
||||
encodeURIComponent('</body></html>')
|
||||
|
|
Loading…
Reference in a new issue