mirror of https://github.com/gorhill/uBlock.git
Use CDN URLs as fall back URLs
Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/1566#issuecomment-826473517 Additionally, add more CDN URLs to default filter lists.
This commit is contained in:
parent
0f580ec204
commit
2a5e67e3f5
|
@ -22,6 +22,11 @@
|
|||
"contentURL": [
|
||||
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badlists.txt",
|
||||
"assets/ublock/badlists.txt"
|
||||
],
|
||||
"cdnURLs": [
|
||||
"https://gitcdn.xyz/repo/uBlockOrigin/uAssets/master/filters/badlists.txt",
|
||||
"https://cdn.jsdelivr.net/gh/uBlockOrigin/uAssets@master/filters/badlists.txt",
|
||||
"https://cdn.statically.io/gh/uBlockOrigin/uAssets/master/filters/badlists.txt"
|
||||
]
|
||||
},
|
||||
"ublock-filters": {
|
||||
|
@ -47,6 +52,11 @@
|
|||
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt",
|
||||
"assets/ublock/badware.txt"
|
||||
],
|
||||
"cdnURLs": [
|
||||
"https://gitcdn.xyz/repo/uBlockOrigin/uAssets/master/filters/badware.txt",
|
||||
"https://cdn.jsdelivr.net/gh/uBlockOrigin/uAssets@master/filters/badware.txt",
|
||||
"https://cdn.statically.io/gh/uBlockOrigin/uAssets/master/filters/badware.txt"
|
||||
],
|
||||
"supportURL": "https://github.com/gorhill/uBlock/wiki/Badware-risks",
|
||||
"instructionURL": "https://github.com/gorhill/uBlock/wiki/Badware-risks"
|
||||
},
|
||||
|
@ -57,6 +67,11 @@
|
|||
"contentURL": [
|
||||
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt",
|
||||
"assets/ublock/privacy.txt"
|
||||
],
|
||||
"cdnURLs": [
|
||||
"https://gitcdn.xyz/repo/uBlockOrigin/uAssets/master/filters/privacy.txt",
|
||||
"https://cdn.jsdelivr.net/gh/uBlockOrigin/uAssets@master/filters/privacy.txt",
|
||||
"https://cdn.statically.io/gh/uBlockOrigin/uAssets/master/filters/privacy.txt"
|
||||
]
|
||||
},
|
||||
"ublock-abuse": {
|
||||
|
@ -66,6 +81,11 @@
|
|||
"contentURL": [
|
||||
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt",
|
||||
"assets/ublock/resource-abuse.txt"
|
||||
],
|
||||
"cdnURLs": [
|
||||
"https://gitcdn.xyz/repo/uBlockOrigin/uAssets/master/filters/resource-abuse.txt",
|
||||
"https://cdn.jsdelivr.net/gh/uBlockOrigin/uAssets@master/filters/resource-abuse.txt",
|
||||
"https://cdn.statically.io/gh/uBlockOrigin/uAssets/master/filters/resource-abuse.txt"
|
||||
]
|
||||
},
|
||||
"ublock-unbreak": {
|
||||
|
|
|
@ -730,14 +730,20 @@ api.get = async function(assetKey, options = {}) {
|
|||
|
||||
const assetRegistry = await getAssetSourceRegistry();
|
||||
assetDetails = assetRegistry[assetKey] || {};
|
||||
let contentURLs = [];
|
||||
const contentURLs = [];
|
||||
if ( typeof assetDetails.contentURL === 'string' ) {
|
||||
contentURLs = [ assetDetails.contentURL ];
|
||||
contentURLs.push(assetDetails.contentURL);
|
||||
} else if ( Array.isArray(assetDetails.contentURL) ) {
|
||||
contentURLs = assetDetails.contentURL.slice(0);
|
||||
contentURLs.push(...assetDetails.contentURL);
|
||||
} else if ( reIsExternalPath.test(assetKey) ) {
|
||||
assetDetails.content = 'filters';
|
||||
contentURLs = [ assetKey ];
|
||||
contentURLs.push(assetKey);
|
||||
}
|
||||
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/1566#issuecomment-826473517
|
||||
// Use CDN URLs as fall back URLs.
|
||||
if ( Array.isArray(assetDetails.cdnURLs) ) {
|
||||
contentURLs.push(...assetDetails.cdnURLs);
|
||||
}
|
||||
|
||||
for ( const contentURL of contentURLs ) {
|
||||
|
@ -776,24 +782,31 @@ const getRemote = async function(assetKey) {
|
|||
return details;
|
||||
};
|
||||
|
||||
let contentURLs = [];
|
||||
const contentURLs = [];
|
||||
if ( typeof assetDetails.contentURL === 'string' ) {
|
||||
contentURLs = [ assetDetails.contentURL ];
|
||||
contentURLs.push(assetDetails.contentURL);
|
||||
} else if ( Array.isArray(assetDetails.contentURL) ) {
|
||||
contentURLs = assetDetails.contentURL.slice(0);
|
||||
contentURLs.push(...assetDetails.contentURL);
|
||||
}
|
||||
|
||||
// If asked to be gentle on remote servers, favour using dedicated CDN
|
||||
// servers. If more than one CDN server is present, randomly shuffle the
|
||||
// set of servers so as to spread the bandwidth burden.
|
||||
if ( remoteServerFriendly && Array.isArray(assetDetails.cdnURLs) ) {
|
||||
//
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/1566#issuecomment-826473517
|
||||
// In case of manual update, use CDNs URLs as fall back URLs.
|
||||
if ( Array.isArray(assetDetails.cdnURLs) ) {
|
||||
const cdnURLs = assetDetails.cdnURLs.slice();
|
||||
for ( let i = 0, n = cdnURLs.length; i < n; i++ ) {
|
||||
const j = Math.floor(Math.random() * n);
|
||||
if ( j === i ) { continue; }
|
||||
[ cdnURLs[j], cdnURLs[i] ] = [ cdnURLs[i], cdnURLs[j] ];
|
||||
}
|
||||
contentURLs.unshift(...cdnURLs);
|
||||
if ( remoteServerFriendly ) {
|
||||
contentURLs.unshift(...cdnURLs);
|
||||
} else {
|
||||
contentURLs.push(...cdnURLs);
|
||||
}
|
||||
}
|
||||
|
||||
for ( const contentURL of contentURLs ) {
|
||||
|
|
Loading…
Reference in New Issue