Host selecter

Enhanced GUI for aniworld.to and s.to websites, allowing you to effortlessly choose your preferred video host and have it automatically opened. A convenient green button positioned at the bottom right corner of the page will appear, prompting you to click and select your desired host from a user-friendly drop-down menu. Enjoy seamless video streaming with the host of your choice!

La data de 05-07-2023. Vezi ultima versiune.

// ==UserScript==
// @name         Host selecter
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Enhanced GUI for aniworld.to and s.to websites, allowing you to effortlessly choose your preferred video host and have it automatically opened. A convenient green button positioned at the bottom right corner of the page will appear, prompting you to click and select your desired host from a user-friendly drop-down menu. Enjoy seamless video streaming with the host of your choice!
// @author       Budumz
// @license MIT
// @match        https://aniworld.to/*
// @match        https://s.to/serie/stream/*
// @grant        GM_addStyle
// ==/UserScript==

(function () {
    'use strict';

    // Function to create and show the GUI pop-up
    function createGUI() {
        const popupDiv = document.createElement('div');
        popupDiv.innerHTML = `
      <div style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; padding: 20px; border: 1px solid #ccc;">
        <h2>Hoster Selection</h2>
        <label for="hosterSelect">Select a Hoster:</label>
        <select id="hosterSelect">
          <option value="VOE">VOE</option>
          <option value="Doodstream">Doodstream</option>
          <option value="Vidoza">Vidoza</option>
          <option value="Streamtape">Streamtape</option>
        </select>
        <br />
        <h2>Preferred Hoster</h2>
        <label for="preferredHoster">Set your preferred Hoster:</label>
        <select id="preferredHoster">
          <option value="">None</option>
          <option value="VOE">VOE</option>
          <option value="Doodstream">Doodstream</option>
          <option value="Vidoza">Vidoza</option>
          <option value="Streamtape">Streamtape</option>
        </select>
        <br />
        <button id="submitButton">Submit</button>
        <button id="closeButton">Close</button>
      </div>
    `;
      document.body.appendChild(popupDiv);

      // Check if there's a previously selected hoster in localStorage and pre-select it
      const storedHoster = localStorage.getItem('selectedHoster');
      const hosterSelect = document.getElementById('hosterSelect');
      if (storedHoster && Array.from(hosterSelect.options).some(option => option.value === storedHoster)) {
          hosterSelect.value = storedHoster;
      }

      // Check if there's a previously selected preferred hoster in localStorage and pre-select it
      const storedPreferredHoster = localStorage.getItem('preferredHoster');
      const preferredHosterSelect = document.getElementById('preferredHoster');
      if (storedPreferredHoster && Array.from(preferredHosterSelect.options).some(option => option.value === storedPreferredHoster)) {
          preferredHosterSelect.value = storedPreferredHoster;
      }

      // Set up event listener for the submit button
      const submitButton = document.getElementById('submitButton');
      submitButton.addEventListener('click', () => {
          const selectedHoster = hosterSelect.value;
          const preferredHoster = preferredHosterSelect.value;

          // Save the selected hoster and preferred hoster in localStorage
          localStorage.setItem('selectedHoster', selectedHoster);
          localStorage.setItem('preferredHoster', preferredHoster);

          // Find the corresponding hoster link and emulate a click for the preferred hoster
          const hosterLinks = document.querySelectorAll('a.watchEpisode');
          for (const link of hosterLinks) {
              const hosterName = link.querySelector('h4').innerText;
              if (hosterName === preferredHoster) {
                  link.querySelector('.hosterSiteVideoButton').click();
                  break;
              }
          }

          // Close the GUI pop-up after selecting and clicking the hoster
          document.body.removeChild(popupDiv);
      });

      // Set up event listener for the close button
      const closeButton = document.getElementById('closeButton');
      closeButton.addEventListener('click', () => {
          // Close the GUI pop-up without taking any action
          document.body.removeChild(popupDiv);
      });
  }

    // Add a button to the page
    function addGUIButton() {
        const button = document.createElement('button');
        button.innerText = 'Open GUI';
        button.style.position = 'fixed';
        button.style.bottom = '20px';
        button.style.right = '20px';
        button.addEventListener('click', createGUI);
        document.body.appendChild(button);
    }

    // Add the CSS styles
    GM_addStyle(`
    button {
      padding: 10px 20px;
      background-color: #4CAF50;
      color: white;
      border: none;
      cursor: pointer;
      border-radius: 4px;
    }
  `);

    // Add the GUI button to the page
    addGUIButton();

    // Auto-select preferred hoster if available
    const storedPreferredHoster = localStorage.getItem('preferredHoster');
    if (storedPreferredHoster) {
        const hosterLinks = document.querySelectorAll('a.watchEpisode');
        for (const link of hosterLinks) {
            const hosterName = link.querySelector('h4').innerText;
            if (hosterName === storedPreferredHoster) {
                link.querySelector('.hosterSiteVideoButton').click();
                break;
            }
        }
    }
})();