1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-02 02:14:52 +12:00

code review: easier to maintain

This commit is contained in:
gorhill 2015-05-03 08:18:06 -04:00
parent fb639870df
commit 818a3db9e4
3 changed files with 31 additions and 16 deletions

View file

@ -154,7 +154,6 @@ var collapser = (function() {
var pendingRequests = {};
var pendingRequestCount = 0;
var srcProps = {
'iframe': 'src',
'img': 'src'
};
@ -194,23 +193,35 @@ var collapser = (function() {
entry = pendingRequests[request.id];
delete pendingRequests[request.id];
pendingRequestCount -= 1;
// Not blocked
if ( !request.blocked ) {
continue;
}
target = entry.target;
// No placeholders
if ( collapse ) {
target.style.setProperty('display', 'none', 'important');
continue;
}
tagName = target.localName;
target.setAttribute(
srcProps[tagName],
placeholders[tagName].replace('{{url}}', request.url)
);
if ( tagName !== 'iframe' ) {
target.style.setProperty('border', placeholders.border, 'important');
target.style.setProperty('background', placeholders.background, 'important');
// Special case: iframe
if ( tagName === 'iframe' ) {
target.setAttribute(
'src',
'data:text/html,' + encodeURIComponent(placeholders.iframe.replace('{{url}}', request.url))
);
continue;
}
// Everything else
target.setAttribute(srcProps[tagName], placeholders[tagName]);
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

View file

@ -479,7 +479,7 @@ var evaluateURLs = function(tabId, requests) {
placeholders = {
background: bg,
border: vAPI.localStorage.getItem('placeholderBorder'),
iframe: vAPI.localStorage.getItem('placeholderDocument').replace('{{bg}}', encodeURIComponent(bg)),
iframe: vAPI.localStorage.getItem('placeholderDocument').replace('{{bg}}', bg),
img: vAPI.localStorage.getItem('placeholderImage')
};
}

View file

@ -82,14 +82,18 @@ var defaultLocalUserSettings = {
].join(''),
placeholderBorder: '1px solid rgba(0, 0, 0, 0.05)',
placeholderDocument: [
'data:text/html,',
encodeURIComponent('<html><head><style>'),
encodeURIComponent('body { background: '),
'{{bg}}',
encodeURIComponent('; color: gray; font: 12px sans-serif; margin: 0; padding: 2px; white-space: nowrap; }'),
encodeURIComponent('</style></head><body>'),
'<html><head><style>',
'body { ',
'background: {{bg}};',
'color: gray;',
'font: 12px sans-serif;',
'margin: 0;',
'padding: 2px;',
'white-space: nowrap;',
'}',
'</style></head><body>',
'{{url}}',
encodeURIComponent('</body></html>')
'</body></html>'
].join(''),
placeholderImage: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
};