I need hotkeys Alt + ] and Alt + [. I have manifest.json like:
{
...
"commands": {
"nextTrack": {
"suggested_key": {
"default": "Alt+]"
},
"description": "Next track"
},
"previousTrack": {
"suggested_key": {
"default": "Alt+["
},
"description": "Previous track"
},
"toggle": {
"suggested_key": {
"default": "Alt+P"
},
"description": "Toggle pause"
}
},
...
}
When I enable my extension I get:
Could not load extension from '~/project'.
Invalid value for 'commands[1].default': Alt+].
What is way to use that hotkeys?
Only uppercase letters (A-Z) and digits (0-9) are valid values, as you can see by looking at the source code of the chrome.commands API.
If you want to use other characters, inject a content script in every page which binds a keydown event:
document.addEventListener('keydown', function(event) {
if (!event.ctrlKey && event.altKey && event.which === 80/*P*/) {
// Dispatch a custom message, handled by your extension
chrome.runtime.sendMessage('Alt+P');
}
}, true); // <-- True is important
Disadvantages of this method
Keyboard focus must be within a page where the content script is activated. The shortcut will fail if you're inside the Developer tools, omnibar, etc.
Even if you use <all_urls> as a match pattern, it won't work on non http(s) / file / ftp(s) schemes like chrome:, data:, chrome-extension:, about: or the Chrome Web store.
You can run into problems with detecting the [ character, if the keyboard layout does not support it, or uses a different key code.
There's no built-in support for customizing this shortcut (as a user, visit chrome://extensions/, scroll to the bottom and click on "Configure commands" to change the extension's shortcut).
I suggest to pick a different shortcut, or change the way how your extension is controlled (through a page / browser action popup, for instance).
Related
I just installed WPy64-3940 that comes with JupyterLab 3.0.14 .
To my surprise, now my code comes decorated with things called "pycodestyle".
As you can see below, the code is underlined in orange and a popup can appear.
I do not like that at all, it perturbs my reading.
Would you know where this comes from and how I can disable this?
Thanks
Michel
This is not a built-in feature of JupyterLab, but an extension called jupyterlab-lsp. As one of the authors I am surprised to see it included by default on the WPy64 distribution, and sorry you don't like it. Here are three potential solutions:
Ignore this specific diagnostic message (recommended). Right click to bring up context menu and select "Show diagnostics panel"; hover mouse over the row with diagnostic message that you do not like, right click, select "Ignore diagnostics like this".
Disable pycodestyle diagnostic provider completely in setting of the language server. Click on "Settings" menu (top menu bar) → "Advanced Settings Editor" and choose "Language Servers" tab. Copy paste the following settings ("pyls" is the old server, "pylsp" is the new one - only one is needed but I do not know which one you are using); you can also disable other sources of diagnostics for this language server here:
{
"language_servers": {
"pyls": {
"serverSettings": {
"pyls": {
"plugins": {
"pydocstyle": {
"enabled": false
},
"pyflakes": {
"enabled": true
},
"flake8": {
"enabled": false
}
}
},
"pylsp": {
"plugins": {
"pydocstyle": {
"enabled": false
},
"pyflakes": {
"enabled": true
},
"flake8": {
"enabled": false
}
}
}
}
}
}
}
Disable all diagnostics by going to "Diagnostics" tab and adding a catch-all regular-expression rule like this:
{
"ignoreMessagesPatterns": [".*"]
}
Disable the LSP extension altogether. It is probably best to consult whoever creates WPy64-3940 on how to do this.
I'm trying my first steps in writing a minimal Chrome extension, and I cannot figure out why it does not execute my clientScript.js.
This is my manifest.json:
{
"name": "Sit back, relax and enjoy",
"version": "0.1",
"description": "Finds and clicks the +extra channel points button when it is available",
"permissions": [ "activeTab" ],
"content_scripts": [
{
"matches": [ "https://twitch.tv/*" ],
"js": [ "contentScript.js" ],
"run_at": "document_idle"
}
],
"manifest_version": 2
}
And this is the the script that I want executed on pages that match https://twitch.tv/*:
let intervalTimer
function sibareaen() {
const btn = document.querySelector('.tw-button.tw-button--success.tw-interactive')
if (btn) {
btn.click()
console.log('At your service - clicked the button for you!')
}
}
function toggleSibareaen(on) {
switch (on) {
case true:
intervalTimer = setInterval(sibareaen, 750)
break
case false:
clearInterval(intervalTimer)
break
default:
clearInterval(intervalTimer)
}
}
console.log('At your service - ready to click for you!')
toggleSibareaen(true)
I have both files in the same folder:
Also, I have properly "installed" the extension:
The console shows no errors related to the extension.
What am I missing?
Assuming you did reload the tab (the content scripts are injected only on initial tab load, see this for more info and a workaround), you're probably a victim of the infamous Google's decision to hide www in the address bar: if you enter the edit mode and select/copy the entire text (or simply double-click the address) you will see the site's URL is actually https://www.twitch.tv/ so your manifest.json has an incorrect URL pattern that doesn't match the real site.
Simply use a generalized pattern like "https://*.twitch.tv/*" that will match both https://www.twitch.tv/ and https://twitch.tv/ and any other subdomain(s).
P.S. as a debugging step, you can check if the content script is even injected by looking at the context selector in devtools console toolbar or in devtools -> Sources -> Content scripts panel. And if you want to restore the classic address bar behavior, see https://superuser.com/a/1498561
This manifest.json works fine.
"commands": {
"_execute_browser_action": {
"suggested_key": {
"windows": "Alt+S",
"mac": "Alt+S",
"chromeos": "Alt+S",
"linux": "Alt+S"
}
}
},
How do I allow users to reassign shortcuts? I would like to reassign them right from popup. I have created input, which suppose to be filled with a single letter. This letter suppose to replace 'S' in the manifest. How do I save it into manifest or overwrite shortcut?
You can't integrate shortcut changing in your interface, but you can have a button that links to chrome://extensions/configureCommands
I tried this : https://developer.chrome.com/extensions/options.html and made an option page.
So a selection has been added under my extension icon with the name of Option.
My question is that is there a way to rename Option and change it something like Setting or some words in other languages ?
The "Options" label at chrome://extensions is automatically adapted to the user's language. Extensions cannot change the value of this label.
The value of the "Options" option at the dropdown menu at the extension's button cannot be customized either, but you can create a new context menu item under the button as of Chrome 38. E.g.
chrome.contextMenus.create({
id: 'show-settings', // or any other name
title: 'Settings',
contexts: ['page_action', 'browser_action']
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
if (info.menuItemId == 'show-settings') {
chrome.tabs.create({
url: chrome.runtime.getURL('settings.html')
});
}
});
I suggest to just stick to "Options" though, because users do already know what the option does. Consistency in UI/UX is important, imagine how you productive you'd be if every application had a different way of (e.g.) closing/quiting the application.
manifest.json to test the previous script:
{
"name": "Contextmenu on browserAction button",
"version": "1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "Right-click to see a context menu"
},
"permissions": [
"contextMenus"
]
}
Easier way to trigger events.
chrome.contextMenus.create({
title: 'GitHub',
contexts: ['page_action'],
onclick: () => console.log('GitHub'),
});
I'm trying to implement keyboard shortcuts into a Chrome extension.
I have managed this, but I'd like to have a keyboard shortcut that makes use of the num pad rather than the numbers along the top (well, in addition to).
Below is my manifest and script.
Perhaps this is a limitation of Chrome commands.
manifest.json
{
"name": "Shortcut Test",
"version": "1",
"manifest_version": 2,
"background": {"scripts": ["background.js"]},
"commands": {
"shortcut_test": {
"suggested_key": {
"default": "Ctrl+0",
"windows": "Ctrl+0"
},
"description": "A test shortcut"
}
}
}
background.js
chrome.commands.onCommand.addListener(function(command){
console.log(command);
});
Yep, commands currently has a very limited key selection. Just normal letters and numbers.