MobyGames screenshot carousel

Browse screenshots without browser history entries

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        MobyGames screenshot carousel
// @version     1.0
// @description Browse screenshots without browser history entries
// @author      raina
// @license     GPLv3
// @namespace   raina
// @match       https://www.mobygames.com/game/*/*/screenshots/gameShotId,*
// @grant       none
// ==/UserScript==
(function() {

	const wrapper = document.getElementById(`wrapper`);
	let prev, next;


	const flipPage = function(ev) {

		let href = ev.currentTarget.href;

		if (ev.shiftKey || ev.ctrlKey) return true;

		ev.preventDefault();

		if (/#$/.test(href)) return false;

		fetch(href)
		.then(response => response.text())
		.then(content => {

			history.replaceState({}, ``, href);
			content = content.replace(/.*<div id="wrapper"[^\n]*>/s, ``).replace(/<\/div>\s*<div id="footer.*/s, ``);
			wrapper.innerHTML = content;
			rigClicks();

		});
	};


	const rigClicks = function() {

		prev = document.querySelector(`li.previous a`);
		next = document.querySelector(`li.next a`);

		[prev, next].forEach(butt => butt.addEventListener("click", flipPage));

	};


	rigClicks();

	addEventListener("keyup", ev => {

		if ("ArrowLeft" != ev.key && "ArrowRight" != ev.key) return true;

		let click = new MouseEvent("click", {button: 0, cancelable: true});

		if ("ArrowLeft" == ev.key) prev.dispatchEvent(click);
		else next.dispatchEvent(click);

	});

}());