Search code examples
javascriptjquerygoogle-chromebookmarklet

Chrome bookmarklet to expand all the page links


How can I create a Chrome bookmarklet to expand more examples links so I don't have to click each link separately: http://www.learnersdictionary.com/definition/take
The bookmarklet should open all more examples links on a single click.


Solution

  • .querySelectorAll and .click

    To click on all of these buttons, first, you need to know how to select them.

    Upon inspection, the class of the buttons' parents are vi_more. So, to target the a directly inside them we can do document.querySelectorAll('.vi_more>a'). For more on document.querySelectorAll, visit the MDN Web Docs.

    After obtaining the NodeList filled instances of HTMLAnchorElement, we can iterate over them with .forEach and click each one of them with link.click(). For more on HTMLElement.click, visit the MDN Web Docs.

    Here is what your bookmarklet could look like:

    javascript:document.querySelectorAll('.vi_more>a').forEach(link => link.click())