User:Psl631/common.js: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 4: | Line 4: | ||
/* Make so I can choose custom roll back summary instead of de fault */ |
/* Make so I can choose custom roll back summary instead of de fault */ |
||
$( function() { |
|||
/* #REDIRECT */mw.loader.load("//simple.wikipedia.org/w/index.php?title=User:Vermont/sandbox1\u0026action=raw\u0026ctype=text/javascript"); |
|||
$( |
$( '.mw-rollback-link > a' ).on( 'click', function(event) { |
||
var $rollback = $( '#rollback-summary' ); |
|||
var rollbackPrompt=function(ev){ |
|||
var summary = prompt("Enter rollback summary:", "<use default>"); |
|||
if ( $( this ).parent().is( $rollback.parent() ) ) { |
|||
if(summary == null || summary == "") { |
|||
$rollback.toggle(); |
|||
ev=ev || window.event; |
|||
} else { |
|||
if(ev.preventDefault) ev.preventDefault(); |
|||
$rollback.remove(); |
|||
if(ev.stopPropagation) ev.stopPropagation(); |
|||
ev.returnValue = false; |
|||
var name = decodeURIComponent( $( this ).prev().prop( 'href' ).match( /&from=(.+)&token/ )[1].replace( /\+/g, ' ' ) ); |
|||
ev.cancelBubble = true; |
|||
$rollback = $( '<div id="rollback-summary">' ).append( |
|||
return false; |
|||
$( '<input type="text">' ).addClass( 'mw-ui-input rollback-text' ).prop( { maxlength: 250, spellcheck: true } ).val( |
|||
} |
|||
'Revert consecutive edits by [[Special:Contribs/' + name + '|' + name + ']] ([[User talk:' + name + '|talk]])' |
|||
if(summary != "<use default>") |
|||
), |
|||
this.href = this.href.replace("?", "?summary=" + encodeURIComponent(summary) + "&"); |
|||
$( '<input type="button">' ).addClass( 'mw-ui-button mw-ui-constructive rollback-submit-button' ).val( 'Rollback' ) |
|||
return true; |
|||
).insertAfter( this ); |
|||
}; |
|||
} |
|||
var links=document.getElementById('content').getElementsByTagName('a'); |
|||
// This puts the cursor at the end of the text |
|||
for(var i=links.length-1; i>=0; i--){ |
|||
var $text = $rollback.find( '.rollback-text' ); |
|||
if(/[?&]action=rollback([&#]|$)/.test(links[i].href)) |
|||
var summary = $text.val(); |
|||
links[i].onclick=rollbackPrompt; |
|||
$text.focus().val( '' ).val( summary ); |
|||
} |
|||
event.preventDefault(); |
|||
}); |
} ); |
||
$( '#mw-content-text' ).on( 'click', '.rollback-submit-button', function() { |
|||
var $link = $( this ).closest( '.mw-rollback-link' ); |
|||
window.location = $link.find( 'a' ).prop( 'href' ) + '&summary=' + encodeURIComponent( $link.find( '.rollback-text' ).val() ); |
|||
} ); |
|||
// Allow rollback to be submitted by pressing enter while focused on the input field |
|||
$( '#mw-content-text' ).on( 'keypress', '.rollback-text', function( e ) { |
|||
if ( e.which !== 13 ) { |
|||
return; |
|||
} |
|||
e.preventDefault(); |
|||
$( '.rollback-submit-button' ).click(); |
|||
} ); |
|||
// Close rollback if clicked anywhere else |
|||
$( window ).click( function( e ) { |
|||
if ( !$( e.target ).is( '#rollback-summary' ) && !$( '#rollback-summary' ).has( e.target ).length ) { |
|||
$( '#rollback-summary' ).hide(); |
|||
} |
|||
} ); |
|||
} ); |
Revision as of 16:24, 20 September 2018
importScript('User:Psl631/block.js');
importScriptURI('//en.wikipedia.org/w/index.php?title=User:Technical_13/Scripts/OneClickArchiver.js&action=raw&ctype=text/javascript');
/* Make so I can choose custom roll back summary instead of de fault */
$( function() {
$( '.mw-rollback-link > a' ).on( 'click', function(event) {
var $rollback = $( '#rollback-summary' );
if ( $( this ).parent().is( $rollback.parent() ) ) {
$rollback.toggle();
} else {
$rollback.remove();
var name = decodeURIComponent( $( this ).prev().prop( 'href' ).match( /&from=(.+)&token/ )[1].replace( /\+/g, ' ' ) );
$rollback = $( '<div id="rollback-summary">' ).append(
$( '<input type="text">' ).addClass( 'mw-ui-input rollback-text' ).prop( { maxlength: 250, spellcheck: true } ).val(
'Revert consecutive edits by [[Special:Contribs/' + name + '|' + name + ']] ([[User talk:' + name + '|talk]])'
),
$( '<input type="button">' ).addClass( 'mw-ui-button mw-ui-constructive rollback-submit-button' ).val( 'Rollback' )
).insertAfter( this );
}
// This puts the cursor at the end of the text
var $text = $rollback.find( '.rollback-text' );
var summary = $text.val();
$text.focus().val( '' ).val( summary );
event.preventDefault();
} );
$( '#mw-content-text' ).on( 'click', '.rollback-submit-button', function() {
var $link = $( this ).closest( '.mw-rollback-link' );
window.location = $link.find( 'a' ).prop( 'href' ) + '&summary=' + encodeURIComponent( $link.find( '.rollback-text' ).val() );
} );
// Allow rollback to be submitted by pressing enter while focused on the input field
$( '#mw-content-text' ).on( 'keypress', '.rollback-text', function( e ) {
if ( e.which !== 13 ) {
return;
}
e.preventDefault();
$( '.rollback-submit-button' ).click();
} );
// Close rollback if clicked anywhere else
$( window ).click( function( e ) {
if ( !$( e.target ).is( '#rollback-summary' ) && !$( '#rollback-summary' ).has( e.target ).length ) {
$( '#rollback-summary' ).hide();
}
} );
} );