User:Garzfoth/Scripts/BetterTwinklePrefs.js

// Migrated from https://en.wikipedia.org/wiki/User:Garzfoth/common.js on 2021-05-05

// Notes:

// • For changelogs prior to migration, see https://en.wikipedia.org/w/index.php?title=User:Garzfoth/common.js&action=history

// • This script depends on the non-migrated resource User:Equazcion/HideTwinklePrefs.css

// • TODO: Figure out why I didn't fully integrate https://en.wikipedia.org/w/index.php?title=User:Equazcion/BetterTwinklePrefs.js&diff=779228516&oldid=577854721 and document the reason. I believe it was due to some edge case bugs. Not sure if they're still a factor nowadays though.

// Better Twinkle Preferences

// Originally from: User:Equazcion/BetterTwinklePrefs.js

// Check if Twinkle gadget is enabled, otherwise do nothing (unfortunately won't detect manual installs)

if (mw.user.options.get('gadget-Twinkle') == 1) {

// Replace spaces in username with underscores for comparison to page title

var fixedUn = mw.config.get("wgUserName").replace(/ /g, '_');

// Check if we're on an owned JS or CSS page.

if ((mw.config.get("wgPageName").lastIndexOf('.js') == mw.config.get("wgPageName").length - 3) && (mw.config.get("wgPageName").substring(0, fixedUn.length + 5) == "User:" + fixedUn)){

// Suppress the Twinkle preference notification box, which normally shows up on any owned JS or CSS page.

// (Hiding it via JS doesn't always work, especially while editing a JS or CSS page, so we need to import some CSS to do it)

importStylesheet('User:Equazcion/HideTwinklePrefs.css');

}

// Set URL prefix

var pre = location.protocol + '//' + mw.config.get("wgPageContentLanguage") + '.' + mw.config.get("wgNoticeProject") + '.org' + '/w/index.php?title=';

// Add the Twinkle prefs link in the user links line at page tops, next to the usual Preferences link

$('li#pt-preferences').after('

  • ' + '[TW]
  • ');

    }