SSS automatic download

Download videos automatically from SSS websites like ssstik.io and ssstwitter.com

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name SSS automatic download
// @namespace https://github.com/anytngv2/sss-automatic-download
// @supportURL https://github.com/anytngv2/sss-automatic-download
// @version 1.1
// @description Download videos automatically from SSS websites like ssstik.io and ssstwitter.com
// @author AnytngV2
// @match https://ssstik.io/*
// @match https://ssstwitter.com/*
// @match https://ssscdn.io/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=ssstik.io
// @license MIT
// @compatible chrome
// @compatible edge
// @compatible firefox
// @compatible waterfox
// @compatible librewolf
// @compatible safari
// @compatible brave
// @grant none
// ==/UserScript==

(function() {
	'use strict';

	const CONFIG = [
		"ssstik",
		"ssstwitter"
	];

	// check if domain is in the config and do custom action
	const domain = window.location.hostname;
	console.log(`[ANTG2] Current domain: ${domain}`);

	// check if domain contains value in config
	if (CONFIG.some(configDomain => domain.includes(configDomain))) {
		console.log(`[ANTG2] Automatic download script is running on ${domain}`);
		// check if domain is ssstik
		if (domain.includes("ssstik")) {
			toast("Automatic download script can be running on this page.", null, 3000);
			ssstik();
		} else if (domain.includes("ssstwitter")) {
			toast("Automatic download script can be running on this page.", null, 3000);
			ssstwitter();
		} else {
			console.error('[ANTG2] Input element not found');
		}
	}

	function ssstwitter() {
		const inputElement = document.querySelector('#main_page_text');
		if (inputElement) {
			inputElement.addEventListener('input', function() {
				console.log('[ANTG2] Input changed:', this.value);

				// if the value is a valid url, click on #submit
				if (this.value && this.value.startsWith('http')) {
					const submitButton = document.querySelector('#submit');
					if (submitButton) {
						submitButton.click();
						console.log('[ANTG2] Submit button clicked');

						const observer = new MutationObserver(function(mutations) {
							mutations.forEach(function(mutation) {
								const downloadButton = document.querySelector('.download_link');
								if (downloadButton) {
									downloadButton.click();
									console.log('[ANTG2] Download button clicked : ' + downloadButton.dataset.directurl);

									// go to url data-directurl
									if(downloadButton.dataset.directurl) {
										window.location.href = downloadButton.dataset.directurl;
										toast('The video is being downloaded, please check your download folder.', "/", 3500);
									} else{
										toast('Err:1, download url not found, please try again.', null, 5000);
									}

									// toast('The video is being downloaded, please check your download folder.', "/", 3500);
									observer.disconnect();
								}
							});
						});
						observer.observe(document.body, { childList: true, subtree: true });
					}
				}
			});
		}
	}

	function ssstik() {
		// add event listener for #main_page_text.form-control.input-lg
		const inputElement = document.querySelector('#main_page_text.form-control.input-lg');
		if (inputElement) {
			inputElement.addEventListener('input', function() {
				console.log('[ANTG2] Input changed:', this.value);

				// if the value is a valid url, click on #submit
				if (this.value && this.value.startsWith('http')) {
					const submitButton = document.querySelector('#submit');
					if (submitButton) {
						submitButton.click();
						console.log('[ANTG2] Submit button clicked');

						// now we wait for the button .dl-button.download_link.without_watermark to appear and click it
						const observer = new MutationObserver(function(mutations) {
							mutations.forEach(function(mutation) {
								const downloadButton = document.querySelector('.dl-button.download_link.without_watermark');
								if (downloadButton) {
									downloadButton.click();
									console.log('[ANTG2] Download button clicked');
									toast('The video is being downloaded, please check your download folder.', "/", 3500);
									observer.disconnect();
								}
							});
						});
						observer.observe(document.body, { childList: true, subtree: true });
					}
				}
			});
		}
	}

	/**
		* Creates a toast notification with the given message and options.
		* @param {string} message - The message to be displayed in the toast.
		* @param {string} [returnAfterToast=null] - The URL to redirect to after the toast has been displayed for the given duration.
		* @param {number} [duration=5000] - The duration to display the toast in milliseconds.
		*/
	function toast(message, returnAfterToast = null, duration = 5000) {
		const toast = document.createElement('div');
		toast.style.cssText = `
			position: fixed;
			bottom: 0;
			right: 0;
			background-color: #1a1a1a;
			color: #fff;
			padding: 15px; 
			border-radius: 5px;
			font-size: 20px;
			margin: 20px;
			z-index: 1000;
		`;
		toast.textContent = message;
		document.body.appendChild(toast);
		setTimeout(() => {
			document.body.removeChild(toast);
		}, duration);
		if (returnAfterToast) {
			setTimeout(() => {
				window.location.href = returnAfterToast;
			}, duration);
		}
	}
})();