Google Books - load clicked links in a new tab

A small UserScript to ensure that links in a page of Google Books results load to a new tab, on click

  1. // ==UserScript==
  2. // @name Google Books - load clicked links in a new tab
  3. // @version 1.0
  4. // @namespace dhaden
  5. // @description A small UserScript to ensure that links in a page of Google Books results load to a new tab, on click
  6. // @author dhaden
  7. // @match https://www.google.com/search?q=*tbm=bks*
  8. // @license MIT
  9. // @grant none
  10. // @run-at document-end
  11. // ==/UserScript==
  12.  
  13. // Add code to launch the links in a new tab, on each link being clicked
  14. const whitelist = [
  15. "posting.php",
  16. "#top",
  17. ];
  18.  
  19. for (const link of document.querySelectorAll("a")) {
  20. if (!whitelist.some(term => link.href.includes(term))) {
  21. link.target = "_blank";
  22. }
  23. }