User:SoledadKabocha/betterCancel-vector.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:SoledadKabocha/betterCancel-vector. |
/* This script currently has no effect on VisualEditor
If you want to use this script, simply add the following line to your common.js or skin.js:
importScript('User:SoledadKabocha/betterCancel-vector.js'); // Linkback: [[User:SoledadKabocha/betterCancel-vector.js]]
* (Please keep the comment so I can see how many people use this).
*/
var BetterCancelFuncs = {
reportError:function( errStr ) {
mw.util.jsMessage( errStr );
if ( !window.BetterCancelLogErrors ) return; // or LogErrorsFromBetterCancel?
if ( window.console === undefined || typeof(window.console.error) != 'function' )
throw new Error( errStr );
window.console.error( errStr );
return;
},
modifyCancelLink:function( ) {
var editbox = $( '#wpTextbox1' );
if ( !editbox || editbox.length == 0 ) { BetterCancelFuncs.reportError( 'betterCancel: edit box not found on ' + wgPageName ); return; }
var editboxtext = editbox.val( );
if ( typeof editboxtext != 'string' ) { BetterCancelFuncs.reportError( 'betterCancel: edit box text not found on ' + wgPageName ); return; }
var cancLink = $( '#mw-editform-cancel' );
var origHref = '';
if ( !cancLink || cancLink.length == 0 ) { BetterCancelFuncs.reportError( 'betterCancel: cancel link not found on ' + wgPageName ); return; }
else { origHref = cancLink.attr( 'href' ); }
if ( /^\s*#redirect(:| *)\[\[/i.test( editboxtext ) ) {
if ( origHref ) cancLink.attr( 'href', origHref + ( origHref.indexOf('?') == -1 ? '?' : '&' ) + 'redirect=no' );
}
else if ( window.BetterCancelAddSectionAnchor === true ) {
var isEditingSection = false;
if ( wgAction == 'submit' ) {
var edsumbox = $( '#wpSummary' );
if ( !edsumbox || edsumbox.length == 0 ) { BetterCancelFuncs.reportError( 'betterCancel: edit summary box not found on ' + wgPageName ); return; }
var edsumboxtext = edsumbox.val( );
if ( typeof edsumboxtext != 'string' ) { BetterCancelFuncs.reportError( 'betterCancel: edit summary text not found on ' + wgPageName ); return; }
isEditingSection = /\/\* .+ \*\//.test( edsumboxtext );
}
else {
isEditingSection = ( window.location.search.indexOf( 'section=' ) != -1 );
}
if ( isEditingSection ) {
var headlines = $( '#wikiPreview .mw-headline' );
if ( !headlines || headlines.length == 0 ) return;
var headlineId = headlines.attr( 'id' );
if ( !headlineId ) return;
if ( origHref ) cancLink.attr( 'href', origHref + '#' + headlineId );
}
}
}
};
if ( ( wgAction == 'edit' || wgAction == 'submit' ) ) {
if ( typeof window.BetterCancelDisableVectorWarning != 'boolean' )
window.BetterCancelDisableVectorWarning = true;
if ( window.BetterCancelDisableVectorWarning ) {
var cancLink = $( '#mw-editform-cancel' );
if ( cancLink ) {
cancLink.attr( 'onclick', 'window.onbeforeunload = function (){};' );
}
else {
BetterCancelFuncs.reportError( 'betterCancel: Could not disable unsaved changes warning; cancel link not found while editing ' + wgPageName );
}
}
if ( wgArticleId != 0 ) {
$( document ).ready( BetterCancelFuncs.modifyCancelLink );
}
else if ( window.BetterCancelDisableVectorWarning && window.BetterCancelDisableWarningNewpage ) {
window.onbeforeunload = function (){};
}
}