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

Support for video/audio in iframe #932

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

blono
Copy link

@blono blono commented Mar 28, 2022

To accommodate video/audio in iframes, I have added the ability to change the playback speed via an interactive context menu.

…ange the playback speed via an interactive context menu.
@pepijnmm
Copy link
Contributor

pepijnmm commented Mar 28, 2022

I think the idea is good but why do you use an onInstalled listener?
also can't the code be smaller for example with a array foreach same for the onmessage calls.
is the multiplyPlaybackRate btw needed? as you already check if the audio/video exists so just calling on playbackrate straight away would be easier right?

const speedMod = (multiplier) => {
	const elements = document.querySelectorAll('video, audio');
	if (elements) {
		for (let i = 0; i < elements.length; ++i) {
			try {
				const element = elements[i];
				if (element != null && media.playbackRate != null) {
					media.playbackRate *= multiplier;
				}
			} catch (e) {
				console.error(e);
			}
		}
	}
}

Not sure if the if elements is needed as i would expect there to always get a array back filled or empty.

@blono
Copy link
Author

blono commented Mar 28, 2022

I'm sorry. You are right, I was aware of the things you pointed out, but I thought they were minor details, so I ended up implementing them now.
The indentation in background.js is also set to 4 characters, and the log output uses console.err instead of log, which is also provided, so I would appreciate it if you could either reject the PR or merge only the necessary parts.

@pepijnmm
Copy link
Contributor

pepijnmm commented Mar 28, 2022

so I would appreciate it if you could either reject the PR or merge only the necessary parts.

I can't do either it's not my repository. I am only giving feedback so that you can implement it cleaner.
Other than that I don't think it's possible to only implement parts. it's or the whole merge request or nothing.

@igrigorik
Copy link
Owner

I like the functionality but agree with @pepijnmm's feedback on the implementation. Do you have bandwidth to update/clean it up?

@igrigorik igrigorik added the blocked:external This can't be fixed without changes to an external system or website label May 24, 2024
@blono
Copy link
Author

blono commented May 24, 2024

  1. Simplified the implementation of the speedMod function in inject.js to reflect the review results.
  2. The context menu generation in background.js has not been modified because if it is not executed in the onInstalled event, the menu will be generated many times, resulting in a duplicate menu ID generation error.
    Reference: https://developer.chrome.com/docs/extensions/develop/ui/context-menu
    https://stackoverflow.com/questions/64318529/cannot-create-item-with-duplicate-context-menu-id-in-extension

Please check it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked:external This can't be fixed without changes to an external system or website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants