1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00
Raymond Hill 2018-11-08 19:58:45 -02:00
parent b5bed0641f
commit ec55191a25
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -26,37 +26,40 @@
/******************************************************************************/ /******************************************************************************/
(function() { (function() {
let extToTypeMap = new Map([ const extToTypeMap = new Map([
['eot','font'],['otf','font'],['svg','font'],['ttf','font'],['woff','font'],['woff2','font'], ['eot','font'],['otf','font'],['svg','font'],['ttf','font'],['woff','font'],['woff2','font'],
['mp3','media'],['mp4','media'],['webm','media'], ['mp3','media'],['mp4','media'],['webm','media'],
['gif','image'],['ico','image'],['jpeg','image'],['jpg','image'],['png','image'],['webp','image'] ['gif','image'],['ico','image'],['jpeg','image'],['jpg','image'],['png','image'],['webp','image']
]); ]);
let denormalizeTypes = function(aa) { // https://www.reddit.com/r/uBlockOrigin/comments/9vcrk3/bug_in_ubo_1173_betas_when_saving_files_hosted_on/
// Some types can be mapped from 'other', thus include 'other' if and
// only if the caller is interested in at least one of those types.
const denormalizeTypes = function(aa) {
if ( aa.length === 0 ) { if ( aa.length === 0 ) {
return Array.from(vAPI.net.validTypes); return Array.from(vAPI.net.validTypes);
} }
let out = []; const out = new Set();
let i = aa.length, let i = aa.length;
type,
needOther = true;
while ( i-- ) { while ( i-- ) {
type = aa[i]; const type = aa[i];
if ( vAPI.net.validTypes.has(type) ) { if ( vAPI.net.validTypes.has(type) ) {
out.push(type); out.add(type);
}
if ( type === 'other' ) {
needOther = false;
} }
} }
if ( needOther ) { if ( out.has('other') === false ) {
out.push('other'); for ( const type of extToTypeMap.values() ) {
if ( out.has(type) ) {
out.add('other');
break;
} }
return out; }
}
return Array.from(out);
}; };
let headerValue = function(headers, name) { const headerValue = function(headers, name) {
var i = headers.length; let i = headers.length;
while ( i-- ) { while ( i-- ) {
if ( headers[i].name.toLowerCase() === name ) { if ( headers[i].name.toLowerCase() === name ) {
return headers[i].value.trim(); return headers[i].value.trim();
@ -65,7 +68,7 @@
return ''; return '';
}; };
let parsedURL = new URL('https://www.example.org/'); const parsedURL = new URL('https://www.example.org/');
vAPI.net.normalizeDetails = function(details) { vAPI.net.normalizeDetails = function(details) {
// Chromium 63+ supports the `initiator` property, which contains // Chromium 63+ supports the `initiator` property, which contains
@ -95,13 +98,11 @@
} }
// The rest of the function code is to normalize type // The rest of the function code is to normalize type
if ( type !== 'other' ) { if ( type !== 'other' ) { return; }
return;
}
// Try to map known "extension" part of URL to request type. // Try to map known "extension" part of URL to request type.
parsedURL.href = details.url; parsedURL.href = details.url;
let path = parsedURL.pathname, const path = parsedURL.pathname,
pos = path.indexOf('.', path.length - 6); pos = path.indexOf('.', path.length - 6);
if ( pos !== -1 && (type = extToTypeMap.get(path.slice(pos + 1))) ) { if ( pos !== -1 && (type = extToTypeMap.get(path.slice(pos + 1))) ) {
details.type = type; details.type = type;
@ -127,7 +128,7 @@
}; };
vAPI.net.denormalizeFilters = function(filters) { vAPI.net.denormalizeFilters = function(filters) {
let urls = filters.urls || [ '<all_urls>' ]; const urls = filters.urls || [ '<all_urls>' ];
let types = filters.types; let types = filters.types;
if ( Array.isArray(types) ) { if ( Array.isArray(types) ) {
types = denormalizeTypes(types); types = denormalizeTypes(types);