79615360

Date: 2025-05-10 10:06:24
Score: 0.5
Natty:
Report link

To add :hover and :active styles to dynamically injected buttons in your Tampermonkey script, you need to inject CSS into the page, because element.style only supports inline styles and does not support pseudo-classes like :hover or :active.

Here’s how you can inject a tag into the page using JavaScript, and define your button styles there:

Add a unique class to your buttons, e.g. .my-tampermonkey-button. Inject a block with CSS rules, including :hover and :active.

https://code.livegap.com/?st=a50pc81142l

This way, your buttons will respond to :hover and :active, and you still get per-button styling via element.style if needed.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Omar Sedki