Giter Site home page Giter Site logo

Comments (6)

SanderRonde avatar SanderRonde commented on May 28, 2024

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.

catbehemoth avatar catbehemoth commented on May 28, 2024

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.

SanderRonde avatar SanderRonde commented on May 28, 2024

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.

catbehemoth avatar catbehemoth commented on May 28, 2024

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.

SanderRonde avatar SanderRonde commented on May 28, 2024

Can you export your settings and paste them here? Then I can try it myself and see where it stops working.

from customrightclickmenu.

SanderRonde avatar SanderRonde commented on May 28, 2024

Closing this issue for now as there's been no update in ~2 weeks

from customrightclickmenu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.