User:0Michael105/Sofix2.js

/* Various fixes I ripped off of Sophiedp - thank you Sophie @author https://dev.fandom.com/wiki/User:Sophiedp */

/* Remove autofill delete reason */ if (mw.config.get('wgAction') === 'delete') { $('#wpReason').removeAttr('value'); }

/* Add links to the toolbar */ mw.loader.using('mediawiki.util').then( => {   const toolbar = $('#WikiaBar .tools > :first-child');

/* Add MW page list link */ $('', {       append: $('', { text: 'NewPages', href: mw.util.getUrl('Special:NewPages', {               namespace: 'all'            }) }),       insertAfter: toolbar    }); });

/* Hide achivements from Special:AllPages */ mw.loader.using('mediawiki.util').then( => {   if ( mw.config.get('wgCanonicalSpecialPageName') !== 'Allpages' || mw.util.getParamValue('namespace') !== '8' || !$('.mw-allpages-chunk a[title^="MediaWiki:Achievements-"]').length ) {       return;    }

const elements = $('li:has(a[title^="MediaWiki:Achievements-"])'); let hidden = true;

elements.hide;

$('.page-header__page-subtitle').append(       $(' ', { click: function { if (hidden) { elements.show; $(this).text('Hide Achievements'); } else { elements.hide; $(this).text('Show Achievements'); }               hidden = !hidden; },           css: { 'margin-left': '5px' },           text: 'Show Achievements' })   ); });

/* Redirect to contribs page if user "doesn't exist" */ mw.loader.using('mediawiki.util').then( => {   if ( mw.config.get('wgAction') === 'view' && mw.config.get('wgNamespaceNumber') === 2 && mw.config.get('wgArticleId') === 0 && !mw.config.get('wgTitle').includes('/') ) {       location.href = mw.util.getUrl(`Special:Contributions/${mw.config.get('wgTitle')}`);    } });

/* Link to /d profile since UserProfileActivity doesn't show deleted /d posts */ $( => {   const userID = mw.config.get('profileUserId');    if (!userID || userID === '0') {        return;    }

const interval = setInterval( => {       if (!$('#userProfileApp .user-identity-stats').length) {            return;        }        clearInterval(interval);

$('#userProfileApp .user-identity-stats li:has(a[href$="?tab=posts"]) a').attr('href', `${mw.config.get('wgScriptPath')}/f/u/${userID}`); }, 100); });

/* Change history timestamps */ $( => {   if (mw.config.get('wgCanonicalSpecialPageName') !== 'Contributions' && mw.config.get('wgAction') !== 'history') {        return;    }

$('.mw-changeslist-date').text(function (_, txt) {       const time = txt.match(/^\d\d:\d\d/)[0];        const formatter = new Intl.DateTimeFormat('en-US', { timeStyle: 'short', dateStyle: 'medium' });       return formatter.format(new Date(`${txt.slice(7)} ${time}`));    }); });

/* Fix issues with MW's log/history entries */ mw.loader.using('mediawiki.util').then( => {   if (!$('#mw-content-text .mw-changeslist-links').length) {        return;    }

$('#mw-content-text .mw-changeslist-links > span:first-child').before('(');   $('#mw-content-text .mw-changeslist-links > span:last-child').after(')'); $('#mw-content-text .mw-changeslist-links > span:not(:first-child)').before(' | '); $('#mw-content-text .mw-changeslist-links ~ .mw-diff-bytes, #mw-content-text .mw-changeslist-links ~ .comment.comment--without-parentheses, #mw-content-text .mw-changeslist-links ~ .mw-uctop, #mw-content-text .mw-changeslist-links ~ .mw-tag-markers').html(function (_, content) {       return `(${content})`;    }); $('#mw-content-text .mw-changeslist-links ~ .mw-changeslist-separator').text('. .'); mw.util.addCSS(`       #mw-content-text .mw-changeslist-links:before,        #mw-content-text .mw-changeslist-links:after,        #mw-content-text .mw-changeslist-links span:before,        #mw-content-text .mw-changeslist-links ~ .mw-diff-bytes:before,        #mw-content-text .mw-changeslist-links ~ .mw-diff-bytes:after,        #mw-content-text .mw-changeslist-links ~ .comment.comment--without-parentheses:before,        #mw-content-text .mw-changeslist-links ~ .comment.comment--without-parentheses:after,        #mw-content-text .mw-changeslist-links ~ .mw-changeslist-separator:before,        #mw-content-text .mw-changeslist-links ~ .mw-uctop:before,        #mw-content-text .mw-changeslist-links ~ .mw-uctop:after,        #mw-content-text .mw-changeslist-links ~ .mw-tag-markers:before,        #mw-content-text .mw-changeslist-links ~ .mw-tag-markers:after {            display: none;        } `);   if (!$('#mw-content-text .mw-changeslist-links').parent.find('.mw-changeslist-date').length) {        $('#mw-content-text .mw-changeslist-links').parent.html(function (_, content) { const matches = content.match(/^ ?((\d\d:\d\d), \w+ \d?\d, \d\d\d\d)/); const formatter = new Intl.DateTimeFormat('en-US', {               timeStyle: 'short',                dateStyle: 'medium'            }); const timestamp = formatter.format(new Date(`${matches[1].slice(7)} ${matches[2]}`)); return content.replace(new RegExp(`^ ?${matches[1]}`), timestamp); });   } });

/* My version of a user info script */ mw.loader.using(['mediawiki.util', 'mediawiki.api']).then( => {   const user = mw.config.get('profileUserName');    if (!user) {        return;    }

const buildAnon = => { $(' ', {           appendTo: $('.user-identity-stats'),            append: [                $(' ', { append: $('', {                       text: 'Bullseye',                        href: `https://bullseye.toolforge.org/ip/${user}`                    }) })           ]        });    };

const buildUser = => { const colors = { green: 'var(--theme-success-color--secondary)', red: 'var(--theme-alert-color--secondary)' };       //API query params from UserAndIPTools new mw.Api.get({           action: 'query',            list: 'users',            ususers: user,            usprop: 'groups',            formatversion: 2        }).done(data => {            if (data.error) {                return console.error(data.error);            }            if (data.query.users[0].missing) {                return;            }            const ug = data.query.users[0].groups;            $(' ', { appendTo: $('.user-identity-stats'), append: [ $(' ', {                       text: 'auto',                        css: {                            color: (ug.includes('autoconfirmed') ? colors.green : colors.red)                       }                    }), $(' ', {                       text: 'email',                        css: {                            color: (ug.includes('emailconfirmed') ? colors.green : colors.red)                       }                    }) ]           });        });    };

const interval = setInterval( => {       if (!$('#userProfileApp .user-identity-stats').length) {            return;        }        clearInterval(interval);

mw.util.addCSS(`           .user-identity-stats > span {                margin-left: 10px;                padding-left: 10px;                border-left: 1px solid var(--theme-border-color);            }            .user-identity-stats > span > span:not(:first-child)::before {                padding-left: 7px;                padding-right: 7px;                content: '\u00B7';                color: var(--theme-page-text-color);            }        `);

if (mw.util.isIPAddress(user)) { buildAnon; } else { buildUser; }   }, 100); });

/* Force seeing deleted messages/comments/replies */ $( => {   if (!document.cookie.includes('fandom_feeds_hide_deleted=false')) {        document.cookie = `fandom_feeds_hide_deleted=false;path=/;domain=fandom.com;max-age=${60 * 60 * 24 * 7}`;        location.reload;    }    if (!document.cookie.includes('article-comments-hide-deleted=false')) {        document.cookie = `article-comments-hide-deleted=false;path=/;domain=fandom.com;max-age=${60 * 60 * 24 * 7}`;        location.reload;    } });