Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome | TamperMonkey script - Open all links in new tab

Tags:

tampermonkey

I need to open all the search results of each link new tab automatically. I have tried below script which I have found from here. I am unable to achieve the expected outcome. I am absolute new to scripting and help me fix or guide me through achieve the outcome.

// ==UserScript==
// @name     AutoClicker
// @match        https://www.google.com/*
// @require  https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @grant    GM_openInTab
// ==/UserScript==

var TargetLink = $("a:contains('example')");

if (TargetLink.length)
    GM_openInTab (TargetLink[0].href);

Error 1

Error 1

Error 2

Error 2

like image 521
Exception776 Avatar asked Dec 05 '25 18:12

Exception776


1 Answers

Although the question isn't the most recent one, here's a simple solution without any external dependencies:

// ==UserScript==
// @name            AutoClicker
// @match           https://www.google.com/*
// @grant           GM_openInTab
// ==/UserScript==

for (const a of document.querySelectorAll("a")) {
  if (a.textContent.includes("example")) {
    GM_openInTab(a.href)
  }
}
like image 194
Tad Wohlrapp Avatar answered Dec 10 '25 11:12

Tad Wohlrapp