From d93f0dc38d8f2f0410f409a3ef1f2e0d3a24ea40 Mon Sep 17 00:00:00 2001 From: mrsrec <6236968+mrsrec@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:54:31 -0800 Subject: [PATCH 1/4] add username warning Warning for people who select a username starting with a lowercase letter --- extension.json | 3 ++- resources/main.js | 19 ++++++++++++++++++- src/SpecialRequestAccount.php | 6 ++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/extension.json b/extension.json index b0df9cf..d2169b0 100644 --- a/extension.json +++ b/extension.json @@ -74,7 +74,8 @@ ], "localBasePath": "resources", "messages": [ - "scratch-confirmaccount-click-copy-alert" + "scratch-confirmaccount-click-copy-alert", + "createacct-normalization" ], "dependencies": [ "mediawiki.util", diff --git a/resources/main.js b/resources/main.js index 42a6556..182fd42 100644 --- a/resources/main.js +++ b/resources/main.js @@ -35,6 +35,7 @@ $(function () { if (!elem) return; elem.onclick = function() { copyToClipboard(document.getElementById("mw-scratch-confirmaccount-verifcode")); + mw.notify( mw.message( 'scratch-confirmaccount-click-copy-alert', { autoHide: true }, {autoHideSeconds: 5}) ); // Use an i18n message to send a notification } }); @@ -48,6 +49,22 @@ function copyToClipboard(temptext) { tempItem.focus(); tempItem.select(); document.execCommand('copy'); - mw.notify( mw.message( 'scratch-confirmaccount-click-copy-alert', { autoHide: true }, {autoHideSeconds: 5}) ); // Use an i18n message to send a notification tempItem.parentElement.removeChild(tempItem); } + + +$(function () { + const elem = document.getElementsByName("scratchusername")[0]; + if (!elem) return; + + elem.onblur = function() { + var currentname = elem.value || ""; + var usernameblock = new OO.ui.infuse(elem.parentElement.parentElement.parentElement.parentElement);// Pain + var noticebox = []; + if(currentname.length > 0 && currentname[0].match("[a-z]")){ + noticebox[0] = new mw.message("createacct-normalization", "", currentname[0].toUpperCase() + currentname.slice(1)).text(); + } + console.log(noticebox); + usernameblock.setNotices(noticebox); + } +}); \ No newline at end of file diff --git a/src/SpecialRequestAccount.php b/src/SpecialRequestAccount.php index ebca7d1..dc46662 100755 --- a/src/SpecialRequestAccount.php +++ b/src/SpecialRequestAccount.php @@ -186,12 +186,14 @@ function usernameAndVerificationArea() { new OOUI\TextInputWidget( [ 'name' => 'scratchusername', 'required' => true, - 'value' => $request->getText('scratchusername') + 'value' => $request->getText('scratchusername'), ] ), [ 'label' => wfMessage('scratch-confirmaccount-scratchusername')->text(), 'align' => 'top', - ] + 'infusable' => true + ], + ), new OOUI\FieldLayout( new OOUI\TextInputWidget( [ From f1ede5e1a04e957c8d1750450800fb6739efba05 Mon Sep 17 00:00:00 2001 From: mrsrec <6236968+mrsrec@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:09:25 -0800 Subject: [PATCH 2/4] Update main.js --- resources/main.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/resources/main.js b/resources/main.js index 182fd42..0438427 100644 --- a/resources/main.js +++ b/resources/main.js @@ -59,12 +59,13 @@ $(function () { elem.onblur = function() { var currentname = elem.value || ""; - var usernameblock = new OO.ui.infuse(elem.parentElement.parentElement.parentElement.parentElement);// Pain + var usernameblock = new OO.ui.infuse(elem.parentElement.parentElement.parentElement.parentElement); + // Start with username input field, and go up 4 levels, to the entire username container that OOUI will infuse onto var noticebox = []; - if(currentname.length > 0 && currentname[0].match("[a-z]")){ + 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 } - console.log(noticebox); - usernameblock.setNotices(noticebox); + usernameblock.setNotices(noticebox);// Save out any notices (importantly, this will *remove* a notice if it no longer applies) } -}); \ No newline at end of file +}); From 84c3fcff1e595270b2e3064bbce6f30763391135 Mon Sep 17 00:00:00 2001 From: mrsrec <6236968+mrsrec@users.noreply.github.com> Date: Sun, 17 Dec 2023 23:05:45 -0800 Subject: [PATCH 3/4] add comma from Kenny2github Co-authored-by: AbyxDev --- src/SpecialRequestAccount.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SpecialRequestAccount.php b/src/SpecialRequestAccount.php index dc46662..4ec4aa7 100755 --- a/src/SpecialRequestAccount.php +++ b/src/SpecialRequestAccount.php @@ -191,7 +191,7 @@ function usernameAndVerificationArea() { [ 'label' => wfMessage('scratch-confirmaccount-scratchusername')->text(), 'align' => 'top', - 'infusable' => true + 'infusable' => true, ], ), From e215fea6cddb778442db6eec0f1049340988ded9 Mon Sep 17 00:00:00 2001 From: mrsrec <6236968+mrsrec@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:50:42 -0500 Subject: [PATCH 4/4] Update main.js --- resources/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/main.js b/resources/main.js index 0438427..9963d54 100644 --- a/resources/main.js +++ b/resources/main.js @@ -59,8 +59,8 @@ $(function () { elem.onblur = function() { var currentname = elem.value || ""; - var usernameblock = new OO.ui.infuse(elem.parentElement.parentElement.parentElement.parentElement); - // Start with username input field, and go up 4 levels, to the entire username container that OOUI will infuse onto + 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();