MobyGames screenshot carousel

Browse screenshots without browser history entries

目前為 2022-04-03 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);

	});

}());