User:Zhuyifei1999/common.js: Difference between revisions

From WikiIndex
Jump to navigation Jump to search
(Add)
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
/*
//$("#wpTextbox1").val("*[[User:" + $("#wpTextbox1").val().match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g).sort().join("]]\n*[[User:") + "]]");
* Change [[MediaWiki:Edittools]] into true buttons.
 
/**
* Add a toolbox link to enable/disable my scripts
  *
  *
  * @source mediawiki.org/wiki/Snippets/Edittools_as_buttons
  * @source: http://www.mediawiki.org/wiki/Snippets/Toggle_user_scripts
  * @revision 3
  * @rev: 1
  */
  */
if (mw.config.get("wgAction") == "delete") {
    $("#wpReason").val("")
}
/**
* withJS
*
* Allow to load custom scripts from the MediaWiki namespace without
* editing [[Special:Mypage/common.js]]
*
* Attribution: [[commons:User:Platonides]], [[commons:User:Lupo]]
*/
var extraJS = mw.util.getParamValue('withJS');
// Leave here for backwards compatibility
(function (extraJS) {
if (!extraJS) {
  return;
}
if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {
  // Disallow some characters in file name
  importScript(extraJS);
} else {
  // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
  $(function () {
  jsMsgAppend(extraJS + ' javascript not allowed to be loaded.', 'error');
  });
}
})(extraJS);
   
   
$( document ).ready( function( $ ) {
        var $sb = $( '#specialchars' ).find( '.specialbasic' ), bl = $sb.length, $sel, ci = 0;
   
   
        if ( bl > 1 ) {
/**
                ci = Number( $.cookie('mw-charinsert') ) || 0;
* withCSS
                if ( ci > bl ) {
*
                        $.cookie( 'mw-charinsert', 0, { expires: 30, path: '/' } );
* Allow to load custom styles from the MediaWiki namespace without
                        ci = 0;
* editing [[Special:Mypage/common.css]]
                }
*
                $sel = $( '<select>' ).change( function(e) {
* Attribution: [[commons:User:Krinkle]]
                        var     $this = $( this ),
*/
                                i = Number( $this.val() ),
var extraCSS = mw.util.getParamValue('withCSS');
                                last = Number( $.cookie('mw-charinsert') ) || 0;
if ( extraCSS ) {
  // Disallow some characters in file name
                        if ( last !== i ) {
  if (extraCSS.match(/^MediaWiki:[^&<>=%#]*\.css$/)) {
                                $sb.eq( last ).css( 'display', 'none' );
    importStylesheet(extraCSS);
                                $sb.eq( i ).css( 'display', 'inline' );
  // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
                                $.cookie( 'mw-charinsert', i, { expires: 30, path: '/' } );
  } else {
                        }
    $(function() {
                });
      jsMsgAppend(extraCSS + ' stylesheet not allowed to be loaded.', 'error');
        }
    });
  }
        $sb.each( function( i ) {
}
                var id = $( this )
                        .css( 'display', i !== ci ? 'none' : 'inline' )
                        .find( 'a' ).replaceWith( function() {
                                var $this = $( this ), onclick = $this.attr( 'onclick' );
                                return $( '<button>', { type: 'button', text: $this.text() } )
                                        .blur()
                                        .click( $.isFunction( onclick ) ? onclick : Function( onclick ) );
                        })
                        .end()
                        .attr( 'id' )
                        .replace( /\.([0-9A-F]{2})/g, '%$1' )
                        .replace( /_/g, ' ' );
                if ( bl > 1 ) {
                        $sel.append(
                                '<option value="' + i + '"' + (i === ci ? ' selected="selected"' : '') + '>'
                                + decodeURIComponent( id )
                                + '</option>'
                        );
                }
        }).end().prepend( $sel );
        ci = null;
});

Latest revision as of 09:50, 29 January 2014

//$("#wpTextbox1").val("*[[User:" + $("#wpTextbox1").val().match(/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/g).sort().join("]]\n*[[User:") + "]]");

/**
 * Add a toolbox link to enable/disable my scripts
 *
 * @source: http://www.mediawiki.org/wiki/Snippets/Toggle_user_scripts
 * @rev: 1
 */

if (mw.config.get("wgAction") == "delete") {
    $("#wpReason").val("")
}

/**
 * withJS
 *
 * Allow to load custom scripts from the MediaWiki namespace without
 * editing [[Special:Mypage/common.js]]
 *
 * Attribution: [[commons:User:Platonides]], [[commons:User:Lupo]]
 */
var extraJS = mw.util.getParamValue('withJS');
// Leave here for backwards compatibility
(function (extraJS) {
 if (!extraJS) {
  return;
 }
 if (extraJS.match(/^MediaWiki:[^&<>=%#]*\.js$/)) {
  // Disallow some characters in file name
  importScript(extraJS);
 } else {
  // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
  $(function () {
   jsMsgAppend(extraJS + ' javascript not allowed to be loaded.', 'error');
  });
 }
})(extraJS);
 
 
/**
 * withCSS
 *
 * Allow to load custom styles from the MediaWiki namespace without
 * editing [[Special:Mypage/common.css]]
 *
 * Attribution: [[commons:User:Krinkle]]
 */
var extraCSS = mw.util.getParamValue('withCSS');
if ( extraCSS ) {
  // Disallow some characters in file name
  if (extraCSS.match(/^MediaWiki:[^&<>=%#]*\.css$/)) {
    importStylesheet(extraCSS);
  // Dont use alert but the jsMsg system. Run jsMsg only once the DOM is ready.
  } else {
    $(function() {
      jsMsgAppend(extraCSS + ' stylesheet not allowed to be loaded.', 'error');
    });
  }
}