Open desired links in new tabs

in Ideas and script requests
Subscribe to Open desired links in new tabs 7 posts, 3 voices



Integrator Scriptwright
FirefoxWindows

I'm looking for a simple link what opens every links on a page what contains a specific part.

For exaple, the scripts open every link what contains http://apps.facebook.com/*

Maybe a Start button at the bottom or the top of the screen should be fine, to start executre the script.

How can it done?

 
devnull69 Scriptwright
FirefoxWindows

Like that:

// insert button at the bottom
var theButton = document.createElement('input');
theButton.type = 'button';
theButton.value = 'Start script';
document.body.appendChild(theButton);
theButton.addEventListener('click', function() {
   var theLinks = document.links;
   for(i=0; i<theLinks.length; i++) {
      if(theLinks[i].href.indexOf('http://apps.facebook.com') != -1)
         GM_openInTab(theLinks[i].href);
   }
}, false);

 
Integrator Scriptwright
FirefoxWindows

Thank you very much.

 
Integrator Scriptwright
FirefoxWindows

Can you help me 2 more things?

1. I would like that the script should not open the same link twice. Ex.: If in the page there is a the same link twice, the script opens it twice in different tabs.

2. Is there any way to modify the script to exclude pages? For example if the link contains "id=", than the script won't opens it.

 
devnull69 Scriptwright
FirefoxWindows

To exclude links that contain one specific string part:

// insert button at the bottom
var theButton = document.createElement('input');
var excludes = 'id=';
theButton.type = 'button';
theButton.value = 'Start script';
document.body.appendChild(theButton);
theButton.addEventListener('click', function() {
   var theLinks = document.links;
   for(i=0; i<theLinks.length; i++) {
      if(theLinks[i].href.indexOf('http://apps.facebook.com') != -1 && theLinks[i].href.indexOf(excludes) == -1)
         GM_openInTab(theLinks[i].href);
   }
}, false);

 
Integrator Scriptwright
FirefoxWindows

Thank you very much again.
Any idea for the first point? To prevent the script to open the same link twice?

 
Couchy Scriptwright
ChromeWindows

var excludes = 'id=';
var openedLinks = {};
// insert button at the bottom
var theButton = document.createElement('input');
theButton.type = 'button';
theButton.value = 'Start script';
document.body.appendChild(theButton);
theButton.addEventListener('click', function() {
   var theLinks = document.links;
   var currentURL = "";
   for(var i = 0; i < theLinks.length; i++) {
      currentURL = theLinks[i].href;
      if(currentURL.indexOf('http://apps.facebook.com') != -1 && currentURL.indexOf(excludes) == -1 && openedLinks[currentURL] != true) {
         openedLinks[currentURL] = true;
         GM_openInTab(theLinks[i].href);
      }
   }
}, false);