mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Merge branch 'master' of github.com:gorhill/uBlock
This commit is contained in:
commit
72f0f8a67d
3 changed files with 36 additions and 64 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
<key>Author</key>
|
<key>Author</key>
|
||||||
<string>{author}</string>
|
<string>Chris Aljoudi (core by gorhill)</string>
|
||||||
<key>Builder Version</key>
|
<key>Builder Version</key>
|
||||||
<string>534.57.2</string>
|
<string>534.57.2</string>
|
||||||
<key>CFBundleDisplayName</key>
|
<key>CFBundleDisplayName</key>
|
||||||
|
|
@ -83,8 +83,8 @@
|
||||||
<string>All</string>
|
<string>All</string>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
<!-- <key>Update Manifest URL</key>
|
<key>Update Manifest URL</key>
|
||||||
<string>https://raw.githubusercontent.com/gorhill/uBlock/master/dist/Update.plist</string> -->
|
<string>https://chrismatic.io/ublock/Update.plist</string>
|
||||||
<key>Website</key>
|
<key>Website</key>
|
||||||
<string>https://github.com/gorhill/uBlock</string>
|
<string>https://github.com/gorhill/uBlock</string>
|
||||||
</dict>
|
</dict>
|
||||||
|
|
|
||||||
|
|
@ -190,21 +190,32 @@ vAPI.tabs = {
|
||||||
vAPI.tabs.registerListeners = function() {
|
vAPI.tabs.registerListeners = function() {
|
||||||
var onNavigation = this.onNavigation;
|
var onNavigation = this.onNavigation;
|
||||||
|
|
||||||
this.onNavigation = function(e) {
|
safari.application.addEventListener('beforeNavigate', function(e) {
|
||||||
// e.url is not present for local files or data URIs,
|
if ( !e.target || !e.target.url || e.target.url === 'about:blank' ) {
|
||||||
// or probably for those URLs which we don't have access to
|
|
||||||
if ( !e.target || !e.target.url ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var url = e.target.url, tabId = vAPI.tabs.getTabId(e.target);
|
||||||
|
if ( vAPI.tabs.popupCandidate ) {
|
||||||
|
var details = {
|
||||||
|
url: url,
|
||||||
|
tabId: tabId,
|
||||||
|
sourceTabId: vAPI.tabs.popupCandidate
|
||||||
|
};
|
||||||
|
vAPI.tabs.popupCandidate = false;
|
||||||
|
if ( vAPI.tabs.onPopup(details) ) {
|
||||||
|
e.preventDefault();
|
||||||
|
if ( vAPI.tabs.stack[details.sourceTabId] ) {
|
||||||
|
vAPI.tabs.stack[details.sourceTabId].activate();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
onNavigation({
|
onNavigation({
|
||||||
|
url: url,
|
||||||
frameId: 0,
|
frameId: 0,
|
||||||
tabId: vAPI.tabs.getTabId(e.target),
|
tabId: tabId
|
||||||
url: e.target.url
|
|
||||||
});
|
});
|
||||||
};
|
}, true);
|
||||||
|
|
||||||
safari.application.addEventListener('navigate', this.onNavigation, true);
|
|
||||||
|
|
||||||
// onClosed handled in the main tab-close event
|
// onClosed handled in the main tab-close event
|
||||||
// onUpdated handled via monitoring the history.pushState on web-pages
|
// onUpdated handled via monitoring the history.pushState on web-pages
|
||||||
|
|
@ -577,27 +588,6 @@ vAPI.messaging.broadcast = function(message) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
safari.application.addEventListener('beforeNavigate', function(e) {
|
|
||||||
if ( !vAPI.tabs.popupCandidate || e.url === 'about:blank' ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var details = {
|
|
||||||
url: e.url,
|
|
||||||
tabId: vAPI.tabs.getTabId(e.target),
|
|
||||||
sourceTabId: vAPI.tabs.popupCandidate
|
|
||||||
};
|
|
||||||
|
|
||||||
vAPI.tabs.popupCandidate = null;
|
|
||||||
|
|
||||||
if ( vAPI.tabs.onPopup(details) ) {
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
if ( vAPI.tabs.stack[details.sourceTabId] ) {
|
|
||||||
vAPI.tabs.stack[details.sourceTabId].activate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,47 +191,31 @@ if ( location.protocol === 'safari-extension:' ) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
window.MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
|
|
||||||
|
|
||||||
if ( !window.MutationObserver ) {
|
|
||||||
// Dummy, minimalistic shim for older versions (<6)
|
|
||||||
// only supports node insertions, but currently we don't use it for anything else
|
|
||||||
window.MutationObserver = function(handler) {
|
|
||||||
this.observe = function(target) {
|
|
||||||
target.addEventListener('DOMNodeInserted', function(e) {
|
|
||||||
handler([{ addedNodes: [e.target] }]);
|
|
||||||
}, true);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
var beforeLoadEvent = document.createEvent('Event');
|
var beforeLoadEvent = document.createEvent('Event');
|
||||||
beforeLoadEvent.initEvent('beforeload');
|
beforeLoadEvent.initEvent('beforeload');
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var frameId = window === window.top ? 0 : Date.now() % 1E5;
|
var frameId = window === window.top ? 0 : Date.now() % 1E5;
|
||||||
|
var parentFrameId = frameId ? 0 : -1;
|
||||||
var linkHelper = document.createElement('a');
|
var linkHelper = document.createElement('a');
|
||||||
var onBeforeLoad = function(e, details) {
|
var onBeforeLoad = function(e, details) {
|
||||||
if ( e.url && e.url.slice(0, 5) === 'data:' ) {
|
if ( e.url && e.url.lastIndexOf('data:', 0) === 0 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
linkHelper.href = details ? details.url : e.url;
|
linkHelper.href = details ? details.url : e.url;
|
||||||
|
var url = linkHelper.href;
|
||||||
|
|
||||||
if ( linkHelper.protocol !== 'http:' && linkHelper.protocol !== 'https:' ) {
|
if ( url.lastIndexOf('http:', 0) === -1 && url.lastIndexOf('https:', 0) === -1) {
|
||||||
if ( !(details && details.type === 'popup') ) {
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( details ) {
|
if ( details ) {
|
||||||
details.url = linkHelper.href;
|
details.url = url;
|
||||||
} else {
|
} else {
|
||||||
details = {
|
details = {
|
||||||
url: linkHelper.href
|
url: url
|
||||||
};
|
};
|
||||||
|
|
||||||
switch ( e.target.nodeName.toLowerCase() ) {
|
switch ( e.target.nodeName.toLowerCase() ) {
|
||||||
|
|
@ -274,7 +258,7 @@ var onBeforeLoad = function(e, details) {
|
||||||
// tabId is determined in the background script
|
// tabId is determined in the background script
|
||||||
// details.tabId = null;
|
// details.tabId = null;
|
||||||
details.frameId = frameId;
|
details.frameId = frameId;
|
||||||
details.parentFrameId = frameId ? 0 : -1;
|
details.parentFrameId = parentFrameId;
|
||||||
details.timeStamp = Date.now();
|
details.timeStamp = Date.now();
|
||||||
|
|
||||||
var response = safari.self.tab.canLoad(e, details);
|
var response = safari.self.tab.canLoad(e, details);
|
||||||
|
|
@ -316,11 +300,10 @@ var onBeforeLoad = function(e, details) {
|
||||||
document.addEventListener('beforeload', onBeforeLoad, true);
|
document.addEventListener('beforeload', onBeforeLoad, true);
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// block pop-ups, intercept xhr requests, and apply site patches
|
// block pop-ups, intercept xhr requests, and apply site patches
|
||||||
var firstMutation = function() {
|
var firstMutation = function() {
|
||||||
document.removeEventListener('DOMSubtreeModified', firstMutation, true);
|
document.removeEventListener('DOMSubtreeModified', firstMutation, true);
|
||||||
firstMutation = null;
|
firstMutation = false;
|
||||||
|
|
||||||
var randEventName = uniqueId();
|
var randEventName = uniqueId();
|
||||||
|
|
||||||
|
|
@ -337,11 +320,10 @@ var firstMutation = function() {
|
||||||
var tmpJS = document.createElement('script');
|
var tmpJS = document.createElement('script');
|
||||||
var tmpScript = ['(function() {',
|
var tmpScript = ['(function() {',
|
||||||
'var block = function(u, t) {',
|
'var block = function(u, t) {',
|
||||||
'var e = document.createEvent("CustomEvent"),',
|
'var e = new CustomEvent("' + randEventName +'",',
|
||||||
'd = {url: u, type: t};',
|
'{detail: {url: u, type: t}, bubbles: false});',
|
||||||
'e.initCustomEvent("' + randEventName + '", false, false, d);',
|
|
||||||
'dispatchEvent(e);',
|
'dispatchEvent(e);',
|
||||||
'return d.url === false;',
|
'return e.detail.url === false;',
|
||||||
'}, wo = open, xo = XMLHttpRequest.prototype.open;',
|
'}, wo = open, xo = XMLHttpRequest.prototype.open;',
|
||||||
'open = function(u) {',
|
'open = function(u) {',
|
||||||
'return block(u, "popup") ? null : wo.apply(this, arguments);',
|
'return block(u, "popup") ? null : wo.apply(this, arguments);',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue