1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-20 01:12:38 +01:00
This commit is contained in:
gorhill 2015-03-30 17:42:12 -04:00
parent eb27478cc7
commit 5b34efc55e
5 changed files with 81 additions and 6 deletions

View File

@ -319,9 +319,6 @@ vAPI.tabs.open = function(details) {
vAPI.tabs.replace = function(tabId, url) {
var targetURL = url;
if ( typeof targetURL !== 'string' || targetURL === '' ) {
return;
}
// extension pages
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
@ -340,7 +337,6 @@ vAPI.tabs.replace = function(tabId, url) {
if ( chrome.runtime.lastError ) {
return;
}
});
};

View File

@ -377,6 +377,24 @@
/******************************************************************************/
// Replace the URL of a tab. Noop if the tab does not exist.
vAPI.tabs.replace = function(tabId, url) {
var targetURL = url;
// extension pages
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
targetURL = vAPI.getURL(targetURL);
}
var tab = this.stack[tabId];
if ( tab ) {
tab.url = targetURL;
}
};
/******************************************************************************/
vAPI.tabs.remove = function(tabIds) {
if(tabIds instanceof SafariBrowserTab) {
tabIds = this.getTabId(tabIds);

View File

@ -96,6 +96,8 @@ if ( window.history.length > 1 ) {
uDom('#proceedTemporary').attr('href', details.url).on('click', proceedTemporary);
uDom('#proceedPermanent').attr('href', details.url).on('click', proceedPermanent);
/******************************************************************************/
})();
/******************************************************************************/

View File

@ -96,8 +96,8 @@ var reURLPostHostnameAnchors = /[\/?#]/;
var pageHostnameRegister = '';
var requestHostnameRegister = '';
var filterRegister = null;
var categoryRegister = '';
//var filterRegister = null;
//var categoryRegister = '';
/******************************************************************************/

View File

@ -219,6 +219,11 @@ var onBeforeRootFrameRequest = function(details) {
// Filtering
if ( result === '' && µb.getNetFilteringSwitch(requestURL) ) {
result = µb.staticNetFilteringEngine.matchString(context);
// https://github.com/gorhill/uBlock/issues/1128
// Do not block if the match begins after the hostname.
if ( result !== '' ) {
result = toBlockDocResult(requestURL, requestHostname, result);
}
}
// Log
@ -246,6 +251,60 @@ var onBeforeRootFrameRequest = function(details) {
/******************************************************************************/
var toBlockDocResult = function(url, hostname, result) {
if ( result.charAt(1) !== 'b' ) {
return '';
}
// Quick test: if the result starts with `|` or `||`, then this means the
// match is before the path part of the URL for sure.
// Examples: sb:|http:// sb:||example.com^
if ( result.charAt(3) === '|' ) {
return result;
}
// Make a regex out of the result
var reText = result.slice(3);
var pos = reText.indexOf('$');
if ( pos > 0 ) {
reText = reText.slice(0, pos);
}
// Matches whole URL
if ( reText === '*' ) {
return result;
}
// We are going to have to take the long way to find out
if ( reText.charAt(0) === '/' && reText.slice(-1) === '/' ) {
reText = reText.slice(1, -1);
} else {
reText = reText
.replace(/\./g, '\\.')
.replace(/\?/g, '\\?')
.replace(/^\|\|/, '')
.replace(/\^/g, '.')
.replace(/^\|/g, '^')
.replace(/\|$/g, '$')
.replace(/\*/g, '.*');
}
var re = new RegExp(reText, 'gi');
var matches = re.exec(url);
if ( matches === null ) {
return '';
}
// verify that the match starts before the path
if ( matches.index < url.indexOf(hostname) + hostname.length ) {
return result;
}
return '';
};
/******************************************************************************/
// Intercept and filter behind-the-scene requests.
var onBeforeBehindTheSceneRequest = function(details) {