SSS automatic download

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

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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