User:Theleekycauldron/PortletLinkContributions.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.
let page = mw.config.get('wgPageName');
if (page.slice(0,5)=="User:"&&!page.includes("/")){
  $.when( mw.loader.using('mediawiki.util'), $.ready ).then( function() {
      mw.util.addPortletLink( 'p-namespaces', 'https://en.wikipedia.org/wiki/Special:Contributions/'+page.slice(5), 'Contributions');
  } );
} else if (page.slice(0,10)=="User_talk:"&&!page.includes("/")){
  $.when( mw.loader.using('mediawiki.util'), $.ready ).then( function() {
      mw.util.addPortletLink( 'p-namespaces', 'https://en.wikipedia.org/wiki/Special:Contributions/'+page.slice(10), 'Contributions');
  } );
} else if (page.slice(0,22)=="Special:Contributions/"){
  $.when( mw.loader.using('mediawiki.util'), $.ready ).then( function() {
      mw.util.addPortletLink( 'p-namespaces', 'https://en.wikipedia.org/wiki/User:'+page.slice(22), 'User page');
  } );
  $.when( mw.loader.using('mediawiki.util'), $.ready ).then( function() {
      mw.util.addPortletLink( 'p-namespaces', 'https://en.wikipedia.org/wiki/User_talk:'+page.slice(22), 'Talk');
  } );
}