User:Guywan/Scripts/InsertShortcuts.js: Difference between revisions

Content deleted Content added
m Not so simple
m Bold and italics supported by default.
Line 12:
{
// Setup key handler.
window.addEventListener("keyupkeydown", e =>
{
if(e.altKey && e.key.match(/\d/g))
{
var number = e.key === "0" ? 10 : parseInt(e.key);
if(number === 0) number = 10;
if(!this.inserts[number - 1]) return;
this.insert(number - 1);
}
else if(e.ctrlKey && (e.key == "i" || e.key == "b"))
{
this.insert(e.key);
}
});
Line 37 ⟶ 41:
},
insert: function(numberid)
{
const txtarea = document.getElementById("wpTextbox1");
Line 51 ⟶ 55:
}
var tag;
// Put selected text into the tag. Replace \n's with actual newlines.
if(id == "i") tag = "''_''";
var result = this.inserts[number].replace("_", txtarea.value.substring(start, end)).replace(/\\n/g, "\n");
else if(id == "b") tag = "'''_'''";
else tag = this.inserts[id];
// Put selected text into the tag. Replace \n's with actual newlines.
var result = this.inserts[number]tag.replace("_", txtarea.value.substring(start, end)).replace(/\\n/g, "\n");
// Update txtarea.