-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webext): add save to anchr context menu option (resolve #51)
- Loading branch information
Showing
4 changed files
with
49 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Context Menu | ||
|
||
browser.contextMenus.create({ | ||
id: 'anchr-link', | ||
title: 'Save Link to Anchr', | ||
contexts: ['link'] | ||
}, () => { }) | ||
|
||
browser.contextMenus.onClicked.addListener((info, tab) => { | ||
switch (info.menuItemId) { | ||
case 'anchr-link': | ||
browser.storage.local.get('token') | ||
.then(token => token && token.token && browser.storage.local.set({ | ||
tempLink: { | ||
url: info.linkUrl, | ||
title: info.linkText, | ||
} | ||
})) | ||
// normally, popup should be opened only after the callback returns | ||
// unfortunately, that is not allowed, as the call must happen directly from within an user action handler | ||
// however, calls to resolve collections, etc. in app.js take long enough for value to be present then | ||
browser.browserAction.openPopup() | ||
break | ||
} | ||
}) |