Skip to content

Commit

Permalink
Temporary context menu fix
Browse files Browse the repository at this point in the history
Does not respect settings…
  • Loading branch information
el1t committed Dec 4, 2016
1 parent 1503c39 commit 1e38b8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 86 deletions.
15 changes: 11 additions & 4 deletions platform/safari/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleDisplayName</key>
<string>{name}</string>
<key>CFBundleIdentifier</key>
<string>net.gorhill.uBlock</string>
<string>com.el1t.uBlock</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleShortVersionString</key>
Expand All @@ -18,6 +18,15 @@
<string>{buildNumber}</string>
<key>Chrome</key>
<dict>
<key>Context Menu Items</key>
<array>
<dict>
<key>Identifier</key>
<string>uBlock0-blockElement</string>
<key>Title</key>
<string>Block Element</string>
</dict>
</array>
<key>Database Quota</key>
<real>104857600</real>
<key>Global Page</key>
Expand Down Expand Up @@ -83,9 +92,7 @@
<string>All</string>
</dict>
</dict>
<key>Update Manifest URL</key>
<string>https://chrismatic.io/ublock/Update.plist</string>
<key>Website</key>
<string>https://chrismatic.io/</string>
<string>https://www.github.com/el1t/uBlock-Safari</string>
</dict>
</plist>
90 changes: 8 additions & 82 deletions platform/safari/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -852,90 +852,16 @@
/******************************************************************************/

vAPI.contextMenu = {
contextMap: {
frame: 'insideFrame',
link: 'linkHref',
image: 'srcUrl',
editable: 'editable'
}
};

/******************************************************************************/

vAPI.contextMenu.create = function(details, callback) {
var contexts = details.contexts;
var menuItemId = details.id;
var menuTitle = details.title;

if(Array.isArray(contexts) && contexts.length) {
contexts = contexts.indexOf('all') === -1 ? contexts : null;
} else {
// default in Chrome
contexts = ['page'];
}

this.onContextMenu = function(e) {
var uI = e.userInfo;

if(!uI || /^https?:\/\//i.test(uI.pageUrl) === false) {
return;
}

if(contexts) {
var invalidContext = true;
var ctxMap = vAPI.contextMenu.contextMap;

for(var i = 0; i < contexts.length; i++) {
var ctx = contexts[i];

if(ctx === 'audio' || ctx === 'video') {
if(uI[ctxMap['image']] && uI.tagName === ctx) {
invalidContext = false;
break;
}
} else if(uI[ctxMap[ctx]]) {
invalidContext = false;
break;
} else if(ctx === 'page') {
if(!(uI.insideFrame || uI.linkHref || uI.mediaType || uI.editable)) {
invalidContext = false;
break;
}
}
}

if(invalidContext) {
return;
}
}

e.contextMenu.appendContextMenuItem(menuItemId, menuTitle);
};

this.onContextMenuCmd = function(e) {
if(e.command === menuItemId) {
var tab = e.currentTarget.activeBrowserWindow.activeTab;
e.userInfo.menuItemId = menuItemId;
callback(e.userInfo, tab ? {
id: vAPI.tabs.getTabId(tab),
url: tab.url
} : undefined);
}
};

safari.application.addEventListener('contextmenu', this.onContextMenu);
safari.application.addEventListener('command', this.onContextMenuCmd);
};

/******************************************************************************/

vAPI.contextMenu.remove = function() {
safari.application.removeEventListener('contextmenu', this.onContextMenu);
safari.application.removeEventListener('command', this.onContextMenuCmd);
this.onContextMenu = null;
this.onContextMenuCmd = null;
_callback: null,
_entries: [],
onMustUpdate: function() {},
setEntries: function(entries, callback) {}
};

safari.application.addEventListener('command', function(e) {
var details = e.userInfo;
µBlock.elementPickerExec(vAPI.tabs.getTabId(safari.application.activeBrowserWindow.activeTab), details.tagName + '\t' + details.frameUrl || details.srcUrl || details.linkUrl || '');
});
/******************************************************************************/

vAPI.lastError = function() {
Expand Down

0 comments on commit 1e38b8c

Please sign in to comment.