Open All Links in new tabs

195 views
Skip to first unread message

Help99

unread,
Oct 22, 2020, 5:41:45 PM10/22/20
to greasemonkey-users
In each page there are 25 javascript links meaning, link won't show up until I click on it. I would like to to open these 25 links at once by a key press or automatically.

LWChris

unread,
Oct 28, 2020, 1:11:57 PM10/28/20
to greasemon...@googlegroups.com

Hi,

first, find a way to identify the set of all links (e. g. all links "...with the CSS class named 'some-link'", "...in the third 'div' element of the 'body'", "...within a 'li' element", etc.)

Then you need to follow these steps:

  1. Define two methods 'onKeyPressed' and 'openTheLinks'
  2. Below them, add a key press event listener with 'document.addEventListener("keypress", onKeyPressed)'
  3. In 'onKeyPressed', check the KeyboardEvent properties to test if your desired keyboard shortcut was pressed
  4. If the desired shortcut was detected, call 'openTheLinks'
  5. In 'openTheLinks', select the links with the appropiate 'document.querySelector' call
  6. Loop over the result set of selected link elements
  7. For each link element, get the href-url and call 'window.open(url, "_blank")'

Pitfalls to avoid, read documentation about these topics first:

  • for 2.: "keypressed" might not always be the best event choice depending on your use-case; sometimes you need to use "keydown" or "keyup"
  • for 3.: there's a lot of different properties to check with varying support between browsers, pressed key and chosen event
  • for 4.: you might want to stop event propagation if the shortcut you intend to use is already used for something else on the site or in the browser

Chris

Am 22.10.2020 um 23:41 schrieb Help99:
In each page there are 25 javascript links meaning, link won't show up until I click on it. I would like to to open these 25 links at once by a key press or automatically.
--
You received this message because you are subscribed to the Google Groups "greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to greasemonkey-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/greasemonkey-users/551f10db-11dd-4e6b-90d4-832b4443fe4bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages