Comments (6)
The first step is to create a generic keyboard shortcut in chrome://extensions/shortcuts. I think this is the step you've already done. Simply create a shortcut to any of the "CRM Keyboard Shortcut number X" fields. The number at the end doesn't matter.
The second step is listening for this keypress and responding to it. You can do this by creating a script item, clicking the "background" tab and adding the following code:
crmAPI.background.addKeyboardListener('Ctrl+Shift+I', () => {
//Some callback
});
Where 'Ctrl+Shift+I' is replaced by the keyboard shortcut you want to register.
At this point you can do two things.
The first option is that you run all the logic in the backgroundpage (in the callback), which would be handy if you're creating a counter of howmany times you've pressed the keyboard shortcut or something along those lines.
The second option is to run a script on the page you're currently on, which is probably what you'll want to do. You can do this by putting the following code in the callback:
crmAPI.chrome('tabs.query', function (tabs) {
crmAPI.background.runSelf({
tabId: tabs[0].id
});
});
This will then run the regular script (the one you see if you switch from the background to the main tab) on the currently selected page.
I hope this answers your question.
from customrightclickmenu.
thank you for taking time to reply to me.
my idea I had, I'll explain to on google search example. I want to achieve: I select a word on a page, press ctrl+shift+1 and it runs the script of the menu item. Therefore I went with your second option, but it doesn't work, most likely due to my lack of scripting knowledge.
Can you tell what am i doing wrong?
I associated a shortcut in chrome://extensions/shortcuts as ctrl+shift+1 (CRM Keyboard Shortcut number 1)
then I added a new menu items from your "Commonly Used Search Engines" list, so the code of main tab looks like this:
var query; var url = "https://www.google.com/search?q=%s"; if (crmAPI.getSelection()) { query = crmAPI.getSelection(); } else { query = window.prompt('Please enter a search query'); } if (query) { window.open(url.replace(/%s/g,query), '_blank'); }
and background tap looks like this:
crmAPI.background.addKeyboardListener('Ctrl+Shift+1', () => { }); crmAPI.chrome('tabs.query', function (tabs) { crmAPI.background.runSelf({ tabId: tabs[0].id }); });
Thank you for your help.
from customrightclickmenu.
The first thing it could be is that the code that should run the script is outside of the listener. This means that instead of running when you press the shortcut, it runs when the background script is first started.
So instead of this code:
crmAPI.background.addKeyboardListener('Ctrl+Shift+1', () => {
});
crmAPI.chrome('tabs.query', function (tabs) {
crmAPI.background.runSelf({ tabId: tabs[0].id }); });
You should use this code:
crmAPI.background.addKeyboardListener('Ctrl+Shift+1', () => {
crmAPI.chrome('tabs.query', function (tabs) {
crmAPI.background.runSelf({ tabId: tabs[0].id });
});
});
from customrightclickmenu.
sorry, tried it still doesn't work.... if I have more time I'll send you screenshot, but i have done everything as you said. Thanks again for the extension.
from customrightclickmenu.
Can you export your settings and paste them here? Then I can try it myself and see where it stops working.
from customrightclickmenu.
Closing this issue for now as there's been no update in ~2 weeks
from customrightclickmenu.
Related Issues (20)
- [wiki] please give an example how to pass link as an argument for search engine HOT 3
- [wiki]How to add Copy Tab URL HOT 8
- [Questions] Window title! + couple extras HOT 8
- CRX_SIGNATURE_VERIFICATION_FAILED - Cant add extension to edge HOT 3
- [wiki] Download Tutorial HOT 26
- An error occurred. The package is invalid:“CRX_SIGNATURE_VERIFICATION_FAILED” HOT 1
- Can't run the script on chrome-extension:// page. HOT 1
- Is it possible to add items straight to the context menu and not into the submenu? HOT 3
- Cannot rename main node (Custom Menu) to something else in EDGE (works in Google) HOT 3
- Manage permissions dialog is not working HOT 2
- Project abandoned or in development HOT 7
- Bug: Cannot view or edit submenu HOT 1
- Is it possible the use the current tab url in the link settings? HOT 2
- add text to the context menu that when you click on the text it adds it to the form text box HOT 5
- Get text from the CRM item clicked HOT 18
- True copy and paste operation vs determining which field I right clicked in HOT 5
- addon hijacks .js file links HOT 11
- image right click HOT 2
- How to use CRM Keyboard Shortcut in extension shortcuts HOT 1
- Custom Delimiter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from customrightclickmenu.