User:Polygnotus/Scripts/WarnWhenEditingUserpages.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// User script to warn when editing a userpage instead of talkpage

// <nowiki>
(function() {
    if (mw.config.get('wgNamespaceNumber') === 2 && mw.config.get('wgAction') === 'edit') {
        var pageName = mw.config.get('wgTitle');
        var currentUser = mw.config.get('wgUserName');
        var pageOwner = pageName.split('/')[0]; // Get the owner of the user page

        if (pageOwner !== currentUser) {
            var warningMessage = `
                <div style="background-color: yellow; border: 2px solid red; padding: 10px; margin: 10px 0;">
                    <strong>Warning:</strong> You are about to edit a user page that is not yours. 
                    It is recommended to edit the <a href="/wiki/User_talk:${pageOwner}" title="User talk:${pageOwner}">user's talk page</a> instead.
                </div>
            `;

            $('#editform').prepend(warningMessage);
            alert("You are about to edit a user page that is not yours. Consider editing the user's talk page instead.");
        }
    }
})();
// </nowiki>