Steam Screenshot Scroll

Use mouse wheel to scroll screenshots in Steam

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        	Steam Screenshot Scroll
// @namespace   	iFantz7E.SteamScreenshotScroll
// @description 	Use mouse wheel to scroll screenshots in Steam
// @version     	0.03
// @run-at      	document-start
// @match       	*://store.steampowered.com/app/*
// @match       	*://steamcommunity.com/sharedfiles/filedetails/*
// @icon      		https://store.steampowered.com/favicon.ico
// @grant       	none
// @license			GPL-3.0-only
// @copyright		2018, 7-elephant
// @supportURL		https://steamcommunity.com/id/7-elephant/
// @contributionURL	https://www.paypal.me/iFantz7E
// ==/UserScript==

// License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html

// Since 26 May 2018
// https://greasyfork.org/scripts/368462-steam-screenshot-scroll

// Modify from:
//   https://greasyfork.org/en/scripts/759-steam-scroll/
//   https://steamstore-a.akamaihd.net/public/javascript/gamehighlightplayer.js

// External variable:
//   jQuery, g_player, HighlightPlayer

// Sample:
//   https://store.steampowered.com/app/227300/Euro_Truck_Simulator_2/
//   https://steamcommunity.com/sharedfiles/filedetails/?id=729791016

(function ()
{
	"use strict";
	// jshint multistr:true
	
function attachOnReady(callback)
{
	document.addEventListener("DOMContentLoaded", function (e)
	{
		callback();
	});
}

function main()
{
	setTimeout(function() 
	{
		var ssPlayer = null;
		
		if (typeof g_player !== "undefined")
		{
			ssPlayer = g_player;
		}
		else if (typeof HighlightPlayer !== "undefined")
		{
			HighlightPlayer.prototype.HighlightItem = function(elem, bUserAction)
			{
				// Modify
				if (!ssPlayer)
				{
					ssPlayer = this;
				}
				
				// Original
				{
					var $Elem = $JFromIDOrElement(elem);
					if (this.BIsMovie($Elem))
						this.HighlightMovie(this.GetMovieId($Elem), bUserAction);
					else
						this.HighlightScreenshot(this.GetScreenshotId($Elem));

					var nextItem = this.m_activeItem.next('.highlight_player_item');
					if (nextItem && this.BIsScreenshot(nextItem))
						this.LoadScreenshot(this.GetScreenshotId(nextItem));
				}
			}
			
			// Force set ssPlayer
			jQuery(".highlight_strip_item.focus").click();
		}
			
		var lastScroll = Date.now();
		
		function ssScroll(ev) {
			ev.preventDefault();
			
			if (Date.now() - lastScroll < 250)
			{
				// Prevent too fast scrolling
				return;
			}
			else
			{
				lastScroll = Date.now();
			}
			
			var isScrollDown = (ev.deltaY > 0);
			var siblingProp = isScrollDown ? "next" : "prev";
			
			var eleExpect = jQuery(".highlight_strip_screenshot.focus")
				[siblingProp](".highlight_strip_screenshot")[0];
				
			if (!eleExpect) {
				var elesSs = jQuery(".highlight_strip_screenshot");
				eleExpect = elesSs[isScrollDown ? 0 : elesSs.length - 1];
			}
			
			if (ssPlayer)
			{
				ssPlayer.HighlightItem(eleExpect);
				ssPlayer.ClearInterval();
			}
		}
		
		var eleHolder = jQuery("#highlight_strip")[0];
		if (eleHolder)
		{
			eleHolder.addEventListener("wheel", ssScroll);
		}
		
		if (ssPlayer)
		{
			ssPlayer.ClearInterval();
		}
	}, 1000);
}

attachOnReady(main);

})();

// End