Livin' On Sweets Fullscreen Toggle

Play in fullscreen because that's what the gods intended to

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Livin' On Sweets Fullscreen Toggle
// @namespace    http://tampermonkey.net/
// @version      2024-10-26
// @description  Play in fullscreen because that's what the gods intended to
// @author       You
// @match        https://bluearchive.nexon.com/events/2024/10/minigame
// @icon         https://static.wikia.nocookie.net/blue-archive/images/b/b3/Event_35_-_Sugar_Rush_Icon_1.png
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
	"use strict";

	let fullscreen = false;

	// poll elements
	function checkElementsLoaded() {
		const nuxtDiv = document.getElementById("__nuxt");
		const gameDiv = document.getElementsByClassName("game")[0];
		const playDiv = document.getElementById("play");

		// init when all elements loaded
		if (nuxtDiv && gameDiv && playDiv) {
			initFullscreenToggle(nuxtDiv, gameDiv, playDiv);
		} else {
			// wait
			setTimeout(checkElementsLoaded, 100);
		}
	}

	// Main function to initialize fullscreen toggle
	function initFullscreenToggle(nuxtDiv, gameDiv, playDiv) {
		console.log("Fullscreen toggle loaded! Press \"P\" to toggle fullscreen");

		function toggleFullscreen() {
			fullscreen = !fullscreen;
			if (fullscreen) onFullscreen();
			else onNotFullscreen();
		}

		// hide all other elements and put the game to focus
		function onFullscreen() {
			document.body.appendChild(playDiv);
			nuxtDiv.style.display = "none";
			playDiv.style.height = "100vh";
		}

		// revert
		function onNotFullscreen() {
			gameDiv.appendChild(playDiv);
			nuxtDiv.style.display = "block";
			playDiv.style.height = "auto";
		}

		// listen for "p" key
		document.addEventListener("keydown", function (event) {
			if (event.key === "p" || event.key === "P") {
				toggleFullscreen();
				console.log("Fullscreen: " + fullscreen);
			}
		});
	}

	checkElementsLoaded();
})();