Benutzer:$traight-$hoota/js/Jomuetool.js

aus Wikipedia, der freien Enzyklopädie

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
(function( $, mw ) {
  if ( typeof mw !== 'object' || (mw.config.get( 'wgAction' ) !== 'edit' && mw.config.get( 'wgAction' ) !== 'submit') ||
    typeof $ !== 'function' ) {
    return;
  }
  if ( !mw.libs ) {
    mw.libs = {};
  }
  mw.libs.jomuetool = {
    tools: [],
    reset: function(){
      this.textbox.value = originalText;
    },
    setup: function(){
      mw.loader.load("//de.wikipedia.org/w/index.php?title=Benutzer:$traight-$hoota/js/Jomuetool/Tools.js&action=raw&ctype=text/javascript"); //[[Benutzer:$traight-$hoota/js/Jomuetool/Tools.js]]
    },
    run: function(){
      if ( window.wikEd && window.wikEd.useWikEd ) {
        wikEd.UpdateTextarea();
      }
      var e = document.forms['editform'].elements;
      this.textbox = e['wpTextbox1'];
      this.summary = e['wpSummary'];
      if ( !this.textbox ) {
        return;
      }

      this.originalText = this.textbox.value

      newText = this.runTools();

      if(newText != this.originalText) {
        this.textbox.value = newText;

        if ( window.wikEd && window.wikEd.useWikEd ) {
          wikEd.UpdateFrame();
        }

        var button = $("#wpDiff");
        if (button !== null) {
          button.click();
        }
      }
    },
    runTools: function(){
      newText = this.originalText;
      $(this.tools).each(function(){
        console.log(this);
        if($.isArray(this)){
          console.log("replacing " + this[0] + " with " + this[1]);
          newText = newText.replace(this[0], this[1]);
        }else if(typeof this == "function"){
          newText = this(newText);
        }
      });
      return newText;
    }
  }

  mw.libs.jomuetool.setup();
})( jQuery, mediaWiki )