User:Alexis Jazz/FUC.js

// Original script by Incnis Mrsi (https://meta.wikimedia.org/wiki/User:Incnis_Mrsi/Gebruiker.js) // Forked to be Fixing Ur Ciatations (FUC for short) by Alexis Jazz (https://commons.wikimedia.org/wiki/File:Needs_moar_citations.jpg) // With rename template removal added, FUC may now also stand for "Fixing Ur Crap" // Add "importScript('User:Alexis Jazz/FUC.js');" (without quotes) to your common.js to enable

ns = mw.config.get( 'wgNamespaceNumber' );

switch ( ns ) { case 0: var buttonlabel = 'Fixing Ur Citations'; break; case 6: var buttonlabel = 'Remove rename template'; var buttonlabel2 = 'Decline per WP:FMNN'; break; }

var BulletListNoSpace = /\*\[/g; var BulletListSpace = "* [";

//Will NOT match links in a bulleted list like those in "External links" sections var UnFilledInlineRef = /([^*] )\[http([^ \]]*)( *)([^\]]*)\]([\.]*)/g; var FilledInlineRef = "$1$4$5 ";

var UnFilledArchiveRef = /<[Rr]ef>\[https:\/\/web.archive.org\/web\/([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9]*)\/([^ \]]*)( *)([^\]]*)\]<\/[Rr]ef>/g; var FilledArchiveRef = " ";

var UnFilledRef = /<[Rr]ef>\[([^ \]]*)( *)([^\]]*)\]<\/[Rr]ef>/g; var FilledRef = " ";

var UrlFieldNoProtocol = /\|url=([^:\|]*)\|/g; var UrlFieldProtocol = "|url=http://$1|";

var RenameTemplate = /\{\{(?:rename media|rename image|image move|rename-image|media rename|renamemedia|rename file)\s*\|.*?\}\}(?:\n)?/i;

function FUC { var wpTextbox1 = document.editform.wpTextbox1; var text = wpTextbox1.value; var wpSummary = document.editform.wpSummary;

switch ( ns ) { case 0: wpTextbox1.value = text.replace(BulletListNoSpace,BulletListSpace).replace(UnFilledInlineRef,FilledInlineRef).replace(UnFilledArchiveRef,FilledArchiveRef).replace(UnFilledRef,FilledRef).replace(UrlFieldNoProtocol,UrlFieldProtocol); wpSummary.value = 'Fixing Ur Ciatations'; break; case 6: wpTextbox1.value = text.replace(RenameTemplate,''); wpSummary.value = 'Removing template; rename done'; break; } }

function DECLINEREQUEST { var wpTextbox1 = document.editform.wpTextbox1; var text = wpTextbox1.value; var wpSummary = document.editform.wpSummary;

wpTextbox1.value = text.replace(RenameTemplate,''); wpSummary.value = 'Rename request declined per WP:FMNN, if you disagree please contact another file mover'; }

var Gbtn; mw.loader.using( 'oojs-ui-core' ).done( function {    Gbtn = new OO.ui.ButtonWidget( { id: 'FUC', label: buttonlabel, } );   Gbtn.on( 'click', FUC); } );

$( document ).ready( function {	$( '#wpSummaryLabel' ).append(Gbtn.$element); } );

switch ( ns ) { case 6: var Gbtn2; mw.loader.using( 'oojs-ui-core' ).done( function {    Gbtn2 = new OO.ui.ButtonWidget( { id: 'Gbtn2', label: buttonlabel2, } );   Gbtn2.on( 'click', DECLINEREQUEST); } );

$( document ).ready( function {	$( '#wpSummaryLabel' ).append(Gbtn2.$element); } ); }