User:U.ayaao.p/global.js

$(document).ready(function {  var pageTitle = mw.config.get("wgTitle");  var neverShowWarnings = localStorage.getItem("neverShowSpoilWarnings");

// Check if user has chosen to never show these warnings if (!neverShowWarnings) { // Make API request to get information about templates used on the page $.ajax({     url: mw.config.get("wgScriptPath") + "/api.php",      data: {        action: "parse",        page: pageTitle,        format: "json",        prop: "templates",      },      dataType: "json",      type: "GET",      success: function (data) {        // Check if any template starting with "Spoil" is used        var templates = data.parse.templates;        var spoilerTemplateUsed = templates.some(function (template) { return template["*"].startsWith("Template:Spoil"); });

if (spoilerTemplateUsed) { // Display the confirmation dialog with the "Never show these warnings" toggle var confirmationDialog = OO.ui.confirm(           new OO.ui.HtmlSnippet( ' Warning: This article contains spoilers. Do you want to proceed? '           ),            {              title: "Spoiler Warning",              actions: [                {                  action: "accept",                  flags: "primary",                  label: "Continue",                  actionHandler: function  {                    // User clicked 'Continue', do nothing                  },                },                {                  action: "reject",                  label: "Go back",                  actionHandler: function  {                    // User clicked 'Go back', redirect to the main page                    window.location.href = mw.config.get("wgScriptPath");                  },                },                {                  action: "quit",                  label: "Never show these warnings",                  actionHandler: function  {                    // User clicked 'Never show these warnings', remember the preference localStorage.setItem("neverShowSpoilWarnings", true); confirmationDialog.closeWindow; },               },              ],            }          );        }      },      error: function (error) {        console.error("Error fetching template information:", error);      },    }); }

// Development and debugging button to reset the preference var resetButton = $(" "); resetButton.text("Reset Spoiler Warnings Preference"); resetButton.click(function {    localStorage.removeItem("neverShowSpoilWarnings");    alert("Spoiler Warnings Preference Reset!");  }); $("body").append(resetButton); });