Welcome to Wargaming.net Wiki!

User:XXN:na/wl.js

Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences
function wikilinker() {
  var text = document.getElementById('wpTextbox1');
selectedText = text.value.substring(text.selectionStart, text.selectionEnd);
modifiedText = text.value.substring(text.selectionStart, text.selectionEnd).replace(/, /g, ']], [[' );

// https://burnignorance.com/php-programming-tips/how-to-use-a-variable-in-replace-function-of-javascript/
// I want to replace a variable with a variable – but as a rule in replace function we have to pass a regular exprssion
// so we cannot write string.replace(var1, var2);
// we have to convert the var1 to a regular expression

var sRegExInput = new RegExp(selectedText, "g");
text1 = text.value.replace(selectedText, modifiedText);
$("#wpTextbox1").val(text1);	
}

//firstHeading
//wikiEditor-ui-toolbar
document.getElementById('firstHeading').innerHTML+='<table><tr>\
<td align="center" colspan="2">     \
<button type="button" onClick="wikilinker()">Wikify selected text</button>\
</td></tr></table>';