SSS automatic download

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

Vous devrez installer une extension telle que Tampermonkey, Greasemonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Violentmonkey pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey ou Userscripts pour installer ce script.

Vous devrez installer une extension telle que Tampermonkey pour installer ce script.

Vous devrez installer une extension de gestionnaire de script utilisateur pour installer ce script.

(J'ai déjà un gestionnaire de scripts utilisateur, laissez-moi l'installer !)

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension telle que Stylus pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

Vous devrez installer une extension du gestionnaire de style pour utilisateur pour installer ce style.

(J'ai déjà un gestionnaire de style utilisateur, laissez-moi l'installer!)

// ==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);
		}
	}
})();