Scripthub

Lots of scripts to enhance your browsing experience or automate tasks.

Від 25.08.2024. Дивіться остання версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Scripthub
// @description Lots of scripts to enhance your browsing experience or automate tasks.
// @namespace   https://userscripts.org
// @include     *
// @version     1.1.1
// @license     GNU GPLv3
// ==/UserScript==


function showmessagefromscripthub(msg) {
  const message = document.createElement("div");
  message.textContent = msg;
  message.style.position = "fixed";
  message.style.top = "0";
  message.style.right = "0";
  message.style.zIndex = "9999";
  message.style.backgroundColor = "#333";
  message.style.color = "#fff";
  message.style.padding = "10px";
  message.style.opacity = "0";
  message.style.transition = "opacity 0.5s";
  document.body.appendChild(message);
  
  setTimeout(() => {
      message.style.opacity = "1";
  }, 1000);
  setTimeout(() => {
      message.style.opacity = "0";
  }, 4000);
  setTimeout(() => {
      document.body.removeChild(message);
  }, 4600);
}

try {
  if (window.location.hostname === 'userscripts.org') {
    var scr = "https://pooiod7.neocities.org/projects/scripthub/pages" + (window.location.pathname=="/"?"/home":window.location.pathname) + ".js";
    
    var script = document.createElement('script');
    script.src = scr;
    document.body.append(script);
  } else {
    (function() {
      const urlParams = new URLSearchParams(window.location.search);
      const userscripts = urlParams.get('userscripts');
      const cookieName = 'scripthub_scripts';
      const getCookie = (name) => document.cookie.split('; ').find(row => row.startsWith(name + '='));
      const setCookie = (name, value, hours) => {
        const date = new Date();
        date.setTime(date.getTime() + (hours * 60 * 60 * 1000));
        document.cookie = `${name}=${value}; expires=${date.toUTCString()}; path=/`;
      };
      const clearCookie = (name) => {
        document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/`;
      };
      
      if (new URLSearchParams(window.location.search).get('noscripts')) {
        document.addEventListener('keydown', function(event) {
          if (event.ctrlKey && event.key === 'q') {
            event.preventDefault();
            const url = new URL(window.location);
            url.searchParams.delete('noscripts');
            window.location.href = url;
          }
        });
        clearCookie(cookieName);
        return;
      } else if (new URLSearchParams(window.location.search).get('forcescripts')) {
        document.addEventListener('keydown', function(event) {
          if (event.ctrlKey && event.key === 'q') {
            event.preventDefault();
            const url = new URL(window.location);
            url.searchParams.delete('forcescripts');
            window.location.href = url;
          }
        });
        clearCookie(cookieName);
        return;
      }
      
      if (window.location.href.toLowerCase().includes("recaptcha")) {
        const message = document.createElement("div");
        message.textContent = "Scripthub does not work with reCAPTCHA";
        document.body.appendChild(message);
        console.log("Scripthub disabled for reCAPTCHA embed");
        return;
      }
      
      const cookieValue = getCookie(cookieName);
  
      if (cookieValue) {
        const scriptUrls = JSON.parse(decodeURIComponent(cookieValue.split('=')[1]));
        scriptUrls.forEach(url => {
          const script = document.createElement('script');
          script.src = url;
          document.body.appendChild(script);
        });
      }
  
      document.addEventListener('keydown', function(event) {
        if (event.ctrlKey && event.key === 'r') {
          event.preventDefault();
          clearCookie(cookieName);
          window.location.reload();
          // window.location.replace(`https://userscripts.org/?tosite=${encodeURIComponent(window.location.href)}`);
        } else if (event.ctrlKey && event.key === 'q') {
          event.preventDefault();
          let ctrlQPressed = false;
          if (ctrlQPressed) {
            window.location.href = 'https://userscripts.org/';
          } else {
            ctrlQPressed = true;
            setTimeout(() => {
              const url = new URL(window.location);
              url.searchParams.set('noscripts', 'true');
              window.location.href = url;
            }, 300);
          }
        }
      });
  
      if (!cookieValue && userscripts) {
        try {
          const scriptUrls = JSON.parse(userscripts);
          scriptUrls.forEach(url => {
            const script = document.createElement('script');
            script.src = url;
            document.body.appendChild(script);
          });
          setCookie(cookieName, encodeURIComponent(userscripts), 1);
  
          urlParams.delete('userscripts');
          const newUrl = `${window.location.pathname}?${urlParams}`;
          history.replaceState(null, '', newUrl);
        } catch (e) {
          console.error('Error parsing userscripts:', e);
        }
      } else if (!cookieValue) {
        if (window.location.href.startsWith('blob:') || window.location.href === 'about:blank') {
          console.log("Scripts disabled for this page");
          showmessagefromscripthub("Scripts are unavailable for this page");
          return;
        } else {
          if (!window.location.href.includes("forcescripts") && ( window.location.href.includes("replit.dev") || window.location.href.includes("unpkg.com") )) {
            showmessagefromscripthub("Press ctrl + q to enable scripts on this page");
            document.addEventListener('keydown', function(event) {
              if (event.ctrlKey && event.key === 'q') {
                event.preventDefault();
                let ctrlQPressed = false;
                if (ctrlQPressed) {
                  window.location.href = 'https://userscripts.org/';
                } else {
                  ctrlQPressed = true;
                  setTimeout(() => {
                    const url = new URL(window.location);
                    url.searchParams.set('forcescripts', 'true');
                    window.location.replace(`https://userscripts.org/?tosite=${encodeURIComponent(url)}`);
                  }, 300);
                }
              }
            });
            return;
          } else {
            window.location.replace(`https://userscripts.org/?tosite=${encodeURIComponent(window.location.href)}`);
          }
        }
      }
    })();
  }
} catch(err) {
  showmessagefromscripthub("Unable to load userscripts");
}