Scripthub

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

目前為 2024-08-24 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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

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.toString();
        }
      });
      clearCookie(cookieName);
      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.toString();
          }, 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.toString()}`;
        history.replaceState(null, '', newUrl);
      } catch (e) {
        console.error('Error parsing userscripts:', e);
      }
    } else if (!cookieValue) {
      window.location.replace(`https://userscripts.org/?tosite=${encodeURIComponent(window.location.href)}`);
    }
  })();
}