MediaWiki:DateInserter/code.js

// DateInsert // Pretty simple script to add a button to insert a date to current document using Visual Editor insert drop down (function (mw, $, ve) {   "use strict";    mw.hook("ve.activationComplete").add(function  { $(' Current date ').insertAfter(".oo-ui-tool-name-insertTable"); $(".ve-custom-insertdate").on("click", function {            var surfaceModel = ve.init.target.getSurface.getModel;            var selection = surfaceModel.getSelection;            // If selection is an instance of ve.dm.LinearSelection (as opposed to NullSelection or TableSelection)            // you can get a range (start and end offset) using:            var range = selection.getRange;            // range of text to replace (omit the end parameter to just insert at 'start')            var rangeToRemove = new ve.Range(range.from);            var fragment = surfaceModel.getLinearFragment(rangeToRemove);            var jsonDate = (new Date).toJSON;            var formatedDate = jsonDate.substring(0, 10);            fragment.insertContent(formatedDate);        }); }); })(mediaWiki, jQuery, ve);