Greasy Fork is available in English.

Twitch - Skip content warnings

Automatically skip content warnings before playing a stream on Twitch

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 or Violentmonkey 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.

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

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         Twitch - Skip content warnings
// @namespace    https://twitch-tools.rootonline.de/
// @version      1.2
// @description  Automatically skip content warnings before playing a stream on Twitch
// @author       @CommanderRoot
// @match        https://www.twitch.tv/*
// @run-at       document-start
// @grant        GM_addStyle
// ==/UserScript==

// Hide overlay warning in the top left when you hover over the stream
GM_addStyle('.disclosure-card{display: none !important;}');

function getCookie(name) {
	const value = '; ' + document.cookie;
	const parts = value.split('; ' + name + '=');
	if (parts.length === 2) return parts.pop().split(';').shift();
}

function getcurrentUserID() {
	const userCookie = getCookie('twilight-user');
	console.log(userCookie);
	if (typeof userCookie !== 'undefined') {
		let user = JSON.parse(decodeURIComponent(userCookie));
		if (typeof user === 'object' && typeof user['id'] !== 'undefined') {
			return user['id'].toString();
		}
	}
}

(function () {
	'use strict';

	const localStorageKey = 'content-classification-labels-acknowledged';
	const acknowledgedDuration = Date.now() + (365 * 24 * 60 * 60 * 1000); // Now + 365 days
	const acknowledgedMaxAge = Date.now() + (1 * 24 * 60 * 60 * 1000); // Now + 1 day

	try {
		// Get current setting
		let currentSetting = window.localStorage.getItem(localStorageKey);
		if (currentSetting !== null) {
			currentSetting = JSON.parse(currentSetting);
		} else {
			currentSetting = {};
		}

		const currentUserID = getcurrentUserID();

		let targetSetting = JSON.parse(JSON.stringify(currentSetting));
		if (typeof targetSetting['loggedIn'] === 'undefined') {
			targetSetting['loggedIn'] = {};
		}
		if (typeof targetSetting['loggedOut'] === 'undefined') {
			targetSetting['loggedOut'] = {
				'DrugsIntoxication': acknowledgedDuration,
				'Gambling': acknowledgedDuration,
				'MatureGame': acknowledgedDuration,
				// "Significant Profanity or Vulgarity" (selectable but doesn't trigger anything atm)
				'SexualThemes': acknowledgedDuration,
				'ViolentGraphic': acknowledgedDuration,
			};
		} else {
			if (typeof targetSetting['loggedOut']['DrugsIntoxication'] === 'undefined' || targetSetting['loggedOut']['DrugsIntoxication'] < acknowledgedMaxAge) {
				targetSetting['loggedOut']['DrugsIntoxication'] = acknowledgedDuration;
			}
			if (typeof targetSetting['loggedOut']['Gambling'] === 'undefined' || targetSetting['loggedOut']['Gambling'] < acknowledgedMaxAge) {
				targetSetting['loggedOut']['Gambling'] = acknowledgedDuration;
			}
			if (typeof targetSetting['loggedOut']['MatureGame'] === 'undefined' || targetSetting['loggedOut']['MatureGame'] < acknowledgedMaxAge) {
				targetSetting['loggedOut']['MatureGame'] = acknowledgedDuration;
			}
			if (typeof targetSetting['loggedOut']['SexualThemes'] === 'undefined' || targetSetting['loggedOut']['SexualThemes'] < acknowledgedMaxAge) {
				targetSetting['loggedOut']['SexualThemes'] = acknowledgedDuration;
			}
			if (typeof targetSetting['loggedOut']['ViolentGraphic'] === 'undefined' || targetSetting['loggedOut']['ViolentGraphic'] < acknowledgedMaxAge) {
				targetSetting['loggedOut']['ViolentGraphic'] = acknowledgedDuration;
			}
		}

		if (typeof currentUserID === 'string' && currentUserID !== '') {
			if (typeof targetSetting['loggedIn'][currentUserID] === 'undefined') {
				targetSetting['loggedIn'][currentUserID] = [];
			}
			if (!targetSetting['loggedIn'][currentUserID].includes('DrugsIntoxication')) {
				targetSetting['loggedIn'][currentUserID].push('DrugsIntoxication');
			}
			if (!targetSetting['loggedIn'][currentUserID].includes('Gambling')) {
				targetSetting['loggedIn'][currentUserID].push('Gambling');
			}
			if (!targetSetting['loggedIn'][currentUserID].includes('MatureGame')) {
				targetSetting['loggedIn'][currentUserID].push('MatureGame');
			}
			if (!targetSetting['loggedIn'][currentUserID].includes('SexualThemes')) {
				targetSetting['loggedIn'][currentUserID].push('SexualThemes');
			}
			if (!targetSetting['loggedIn'][currentUserID].includes('ViolentGraphic')) {
				targetSetting['loggedIn'][currentUserID].push('ViolentGraphic');
			}
		}

		// Set new setting
		window.localStorage.setItem(localStorageKey, JSON.stringify(targetSetting));
	} catch (e) {
		// Browser blocks localStorage access so we can't get or set any setting
		return;
	}

})();