Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Have a shortcut for “Read aloud selected text” #354

Open
nhan000 opened this issue Oct 31, 2023 · 5 comments
Open

Feature request: Have a shortcut for “Read aloud selected text” #354

nhan000 opened this issue Oct 31, 2023 · 5 comments

Comments

@nhan000
Copy link

nhan000 commented Oct 31, 2023

Currently, right clicking after selecting a piece of text brings up this option, which I really like and use a lot:

image

However, there is no equivalent of such function in the shortcut list:

image

The “Activate the extension” and “Play/Pause” shortcuts does a similar job, but not exactly equivalent. (Extra details: if an existing reading is ongoing, “Play/Pause” shortcut play/pause that instead of starting a new one with the selected text. Plus, it doesn't work on all pages. The “Activate the extension” open the pop up every time and is quite distracting.)

I'm wondering if the “Play/Pause” shortcut can be made to have different functions depending on the situation:

  • If a piece of text is selected: Read selected text.
  • If no text is selected: Play/Pause.

Thanks a lot for making this awesome plugin!

@ken107
Copy link
Owner

ken107 commented Nov 11, 2023

The behavior of the right-click context menu is a bit special. When you right click on the selection, the browser grabs the selected text and hands it directly to our context-menu event handler to read aloud. This is different from the other activation methods, which has to inject code into the page to grab the selected text.

For this reason, we can't make a keyboard shortcut that replicate the exact equivalent behavior. Our keyboard handler will hvae to inject code to grab the text. But the "Play/Pause" and "Activate the extension" shortcuts are already doing that.

Now since you don't want to popup to appear, you are left with the "Play/Pause" method. Your issue is you want the shortcut to start reading anew instead of pausing. Unfortunately Chrome only allows maximum 4 keyboard shortcuts. We cannot add another one without removing something.

A workaround you can use right now is to press the Stop shortcut first, and then the Play/Pause shortcut. But this leads me to this train of thought. Maybe we can change the "Play/Pause" shortcut to just "Play", and make it always play anew. Then change the "Stop" shortcut to "Pause/Resume". After all, the user doesn't care about the distinction between pause and stop. Let me think more about this.

@nhan000
Copy link
Author

nhan000 commented Nov 13, 2023

Unfortunately Chrome only allows maximum 4 keyboard shortcuts.

Oh that explains why most extensions I see only have that many shortcuts. However, there're also many other plugins that allow more than 4 shortcuts (uBlock Origin — 7, Global Speed — 16), Tweaks for YouTube — ~ 20)

My current work around is exactly as you said — to use Stop and then Play. Your proposal to change around these shortcuts make sense to me. If there's difficulty choosing what functions to give to a shortcut, I'd recommend you to look at Global Speed. I really like how it allows users to really deeply customize its shortcuts.

The work around though doesn't work with selected text from pages such as https://www.autohotkey.com/docs/v2/Program.htm. But right click → Read aloud selected text work.

Btw, I have a somewhat related request: Is there a way to for the plugin to read aloud the clipboard content? I'm thinking if I can be in any app, copy text, and then use a global shortcut to have this extension read that block of text aloud. Let me know if I should make a separate feature request. This would also help with reading selected text from the autohokey page above (select text → copy → read instead of right click and select the Read aloud option). Thank you!

@ken107
Copy link
Owner

ken107 commented Nov 13, 2023

Ah thank you, I had the wrong assumption about the 4-shortcut limits. So we can have as many shortcuts defined as we want, but only 4 active at any one time, I suppose. I'll see what shortcuts to add that makes sense.

The behavior of the right-click context menu is a bit special. When you right click on the selection, the browser grabs the selected text and hands it directly to our context-menu event handler to read aloud. This is different from the other activation methods, which has to inject code into the page to grab the selected text.

On sites like autohotkey.com, the regular activation method is unable to grab the selected text because the selection is inside in iframe. Technically we could traverse all the frames and find which one has text selected, but if the frame is cross-domain, we won't be able to access it. In that case, only the right-click method will work.

@nhan000
Copy link
Author

nhan000 commented Nov 13, 2023

but only 4 active at any one time

I've had 5 active shortcuts from an extension, so there can be more active shortcuts :D

@ken107
Copy link
Owner

ken107 commented Nov 14, 2023

Ah, you're right. Users can set as many as they want. Indeed only 4 can be declared by the extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants