From d8aeb4d87b8b76d2beccf78ac5be38c8fd34b0e3 Mon Sep 17 00:00:00 2001 From: mrsrec <6236968+mrsrec@users.noreply.github.com> Date: Wed, 7 Aug 2024 23:07:40 +0000 Subject: [PATCH] Add files via upload --- extension.json | 3 ++- i18n/en.json | 2 ++ resources/main.js | 15 +++++++++++---- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/extension.json b/extension.json index d2169b0..9684553 100644 --- a/extension.json +++ b/extension.json @@ -75,7 +75,8 @@ "localBasePath": "resources", "messages": [ "scratch-confirmaccount-click-copy-alert", - "createacct-normalization" + "scratch-confirmaccount-username-disallowed", + "scratch-confirmaccount-username-warning" ], "dependencies": [ "mediawiki.util", diff --git a/i18n/en.json b/i18n/en.json index 88bf541..b7fd114 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -76,6 +76,8 @@ "scratch-confirmaccount-welcome": "Welcome to the wiki!", "scratch-confirmaccount-welcome-summary": "Welcome!", + "scratch-confirmaccount-username-disallowed": "Due to technical restrictions, usernames that start with an underscore, end with an underscore, or have two consecutive underscores in the middle cannot be used. Please use a different account to request. If you do not have any other accounts, please contact an administrator for help.", + "scratch-confirmaccount-username-warning": "Your username will show up as $1. You may change the capitalization of any of the letters, except for the first letter, which must be capitalized and cannot be lowercase.", "scratch-confirmaccount-invalid-username": "The username is invalid. Make sure to type your Scratch username. Due to technical reasons, some usernames which start or end with underscore are not allowed. Please contact an administrator if this is the case for you", "scratch-confirmaccount-user-exists": "The user is already registered.", "scratch-confirmaccount-request-exists": "The request is already received. Please wait for the administrators to handle it.", diff --git a/resources/main.js b/resources/main.js index 9963d54..8b70b37 100644 --- a/resources/main.js +++ b/resources/main.js @@ -57,14 +57,21 @@ $(function () { const elem = document.getElementsByName("scratchusername")[0]; if (!elem) return; - elem.onblur = function() { + elem.onkeyup = function() { var currentname = elem.value || ""; var usernameblock = new OO.ui.infuse(elem.closest('.oo-ui-layout')); // Start with username input field, and go to the entire username container that OOUI will infuse onto var noticebox = []; - if(currentname.length > 0 && currentname[0].match("[a-z]")){// Compare first letter to a regex, to check if it starts with a lowercase letter - noticebox[0] = new mw.message("createacct-normalization", "", currentname[0].toUpperCase() + currentname.slice(1)).text(); - // If it'd change, add a notice with the first letter captialized + if(currentname.length > 0){ + if(currentname.match("^_+|_+$|__+")){ + noticebox[0] = new mw.message("scratch-confirmaccount-username-disallowed").text(); + } + else{ + if(currentname[0].match("[A-Za-z]")){// Compare first letter to a regex, to check if it starts with a lowercase letter + noticebox[0] = new mw.message("scratch-confirmaccount-username-warning", currentname[0].toUpperCase() + currentname.slice(1)).text(); + // If it'd change, add a notice with the first letter captialized + } + } } usernameblock.setNotices(noticebox);// Save out any notices (importantly, this will *remove* a notice if it no longer applies) }