QOL on the Mobile Web

Just some general quality of (my) life changes. Reddit: Hide auto-mod comments. YouTube: disable end cards.

Versión del día 09/09/2020. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name        QOL on the Mobile Web
// @namespace   Pogmog
// @description Just some general quality of (my) life changes. Reddit: Hide auto-mod comments. YouTube: disable end cards.
// @version     1.1
// @include     https://old.reddit.com/*
// @include     https://www.reddit.com/*
// @include     https://www.youtube.com/*
// @grant       none
// ==/UserScript==

// Options
var reddit_hide_automod_post = true;
var reddit_fit_image = true;
var youtube_disable_endcards = true;

var urlCheck = document.URL;
/*
	If a tweak needs to use the scroll or onLoad events, call them with the following:
		setup_onLoad()
		setup_onScroll()
	...rather than have everything fire the onScroll event, etc.
*/
if (urlCheck.includes("reddit.com/") && reddit_hide_automod_post)
{
	setup_onLoad();
}

function afterLoad()
{
	// If anything needs to happen after page load (did for Reddit stuff before I found a better way).
	if (urlCheck.includes("reddit.com/"))
	{
		if (reddit_hide_automod_post)
		{
			var first_comment = document.getElementsByClassName("comment")[0];
			var element_to_use = first_comment.getElementsByClassName("tagline")[0];
			var author = element_to_use.getElementsByClassName("author")[0];
			if (author.innerHTML == "AutoModerator")
			{
				console.log("First comment is Automod.");
				element_to_use.getElementsByClassName("expand")[0].onclick();
			}
		}
	}
}
function onPageScroll()
{
	// If anything needs to happen on page scroll (did for Reddit stuff before I found a better way).
}

if (urlCheck.includes("reddit.com/"))
{
	if (reddit_fit_image)
	{
		var sheet = document.createElement('style')
		sheet.innerHTML = ".Post.size-compact.m-redesign div:nth-of-type(3) img {object-fit: contain !important;}";
		document.body.appendChild(sheet);
	}
}
else if (urlCheck.includes("youtube.com/watch"))
{
	if (youtube_disable_endcards)
	{
		// Get rid of YouTube's annoying ENDCARDS
		var sheet = document.createElement('style')
		sheet.innerHTML = ".ytp-ce-element {display: none;}";
		document.body.appendChild(sheet);
	}
}

// Setup Function
function setup_onLoad()
{
	// For code that needs to happen post-pageload
	if (window.attachEvent) {window.attachEvent('onload', afterLoad);}
	else if (window.addEventListener) {window.addEventListener('load', afterLoad, false);}
	else {document.addEventListener('load', afterLoad, false);}
}
function setup_onScroll()
{
	// For code that needs to happen on scroll event
	window.addEventListener("scroll", onPageScroll);
}