User:Katkov Yury/vector.js

// install Wikipedia:User:Cacycle/wikEd in-browser text editor importScriptURI('http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js' + '&action=raw&ctype=text/javascript'); // this example code adds or removes div tags around the selected text function TestHandler(obj) { // select the appropriate text change target (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine) //  focus... is the text under the cursor; ...Word and ...Line extend the target to the start/end of the word or line WikEdGetText(obj, 'selection, cursor'); if (obj.selection.plain != '') { obj.changed = obj.selection; } else { obj.changed = obj.cursor; } // make your changes to the plain target text in obj.changed.plain // remove the previously added formatting if ( /&amp;lt;div&amp;gt;(.*?)&amp;lt;\/div&amp;gt;/i.test(obj.changed.plain) ) { obj.changed.plain = obj.changed.plain.replace(/&amp;lt;div&amp;gt;(.*?)&amp;lt;\/div&amp;gt;/gi, '$1'); } // add the text formatting else { obj.changed.plain = '&amp;lt;div&amp;gt;' + obj.changed.plain + '&amp;lt;/div&amp;gt;'; obj.changed.plain = obj.changed.plain.replace(/(&amp;lt;div&amp;gt;)( *)(.*?)( *)(&amp;lt;\/div&amp;gt;)/, '$2$1$3$5$4'); } // keep the changed text selected obj.changed.keepSel = true; // return to WikEdEditButton to apply changes return; } if (typeof(wikEdUseWikEd) != 'undefined') { WikEdEditButton(null, null, null, TestHandler); }