User:ClickerClock/scripts/QuickSign.js

// //Shortcuts $(document).ready(function { "use strict";  // boilerplate   function getSurroundings {      // Get the text cursor      var cursor = jQuery("#wpTextbox1")[0].selectionStart;      var cursorEnd = jQuery("#wpTextbox1")[0].selectionEnd;      // Gets the first string      var first = document.getElementById("wpTextbox1").value.substring(0, cursor);      //Gets the second string      var second = document.getElementById("wpTextbox1").value.substring(cursor);      var a = {};      a.cursor = cursor;      a.cursorEnd = cursorEnd;      a.first = first;      a.second = second;      return a;   }

function insertString(insert, x) { if ('execCommand' in document) { document.execCommand("insertText", false, insert); } }

function isTalk { if (mw.config.get("wgCanonicalNamespace").slice(-4).toLowerCase == "talk" || mw.config.get("wgCanonicalNamespace") == "Forum" || mw.config.get("wgCanonicalNamespace") == "Project" || mw.config.get("wgCanonicalNamespace") == "Debate" || mw.config.get("wgCanonicalNamespace") == "Thread") { return true; } else { return false; } }

// Insert Sign name var insertSign = "—";

var i = isTalk? addSign:null; //if false return null function addSign { $("body").on("keypress", "#wpTextbox1", function(e) {     if (String.fromCharCode(e.which) === "~") {         var x = getSurroundings;         //Inserts variable between cursor         insertString(insertSign, x);         //set cursor back         this.setSelectionRange(x.cursor + 5, x.cursorEnd + 4);      }   }); }

}); //