Open Video Links in New Tabs

Open each video page link in a new tab

  1. // ==UserScript==
  2. // @name Open Video Links in New Tabs
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description Open each video page link in a new tab
  6. // @author 955whynot
  7. // @match https://www.bloomsburyvideolibrary.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. // Wait until the page fully loads
  15. window.addEventListener('load', () => {
  16. // Update this selector to match the links to each video's page
  17. const videoLinkSelector = 'a.search-title';
  18.  
  19. // Function to open a single link with a delay
  20. function openLink(url) {
  21. const newTab = window.open(url, '_blank');
  22. if (newTab) {
  23. newTab.focus(); // Focus on the new tab
  24. console.log(`Opened: ${url}`); // Log the opened URL
  25. } else {
  26. console.log(`Failed to open: ${url}`);
  27. }
  28. }
  29.  
  30. // Function to open all video links in new tabs
  31. async function openVideoLinks() {
  32. const links = document.querySelectorAll(videoLinkSelector);
  33. console.log(`Found ${links.length} links.`); // Log the number of links found
  34.  
  35. if (links.length === 0) {
  36. alert('No video links found on this page.');
  37. return;
  38. }
  39.  
  40. // Confirm to open all links
  41. if (confirm(`Open ${links.length} video links in new tabs?`)) {
  42. const urls = Array.from(links).map(link => {
  43. return 'https://www.bloomsburyvideolibrary.com' + link.getAttribute('href');
  44. });
  45.  
  46. // Open each link with a slight delay
  47. for (let i = 0; i < urls.length; i++) {
  48. openLink(urls[i]);
  49.  
  50. };
  51. }
  52. }
  53.  
  54. // Add a button to manually trigger the script on the page
  55. const button = document.createElement('button');
  56. button.innerText = 'Open All Video Links';
  57. button.style.position = 'fixed';
  58. button.style.bottom = '20px';
  59. button.style.right = '20px';
  60. button.style.padding = '10px';
  61. button.style.backgroundColor = '#4CAF50';
  62. button.style.color = 'lightgreen';
  63. button.style.border = 'none';
  64. button.style.cursor = 'pointer';
  65.  
  66. // When the button is clicked, run the openVideoLinks function
  67. button.addEventListener('click', openVideoLinks);
  68.  
  69. // Append the button to the body of the webpage
  70. document.body.appendChild(button);
  71. });
  72. })();