I just created a greasemonkey script for you...
try it out:
Code: Select all
// ==UserScript==
// @name inserttab button
// @namespace ahkscriptreplyeditor
// @include https://autohotkey.com/boards/posting.php?mode=reply*
// @version 1
// @grant none
// @author [email protected] (MIT license)
// @description Adds a "tab" button to insert tabs when using the full reply page on ahk forums
// ==/UserScript==
/*
// Author: http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript
// Modified so it's safe across browser windows
function insertAtCursor(myField, myValue) {
var doc = myField.ownerDocument;
//IE support
if (doc.selection) {
myField.focus();
sel = doc.selection.createRange();
sel.text = myValue;
}
//FF, hopefully others
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos) +
myValue + myField.value.substring(endPos, myField.value.length);
}
// fallback to appending it to the field
else {
myField.value += myValue;
}
}
// http://stackoverflow.com/a/512542/883015
function setCaretPosition(elemId, caretPos) {
var elem = document.getElementById(elemId);
if(elem != null) {
if(elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', caretPos);
range.select();
}
else {
if(elem.selectionStart) {
elem.focus();
elem.setSelectionRange(caretPos, caretPos);
}
else
elem.focus();
}
}
}
// http://stackoverflow.com/a/2897229/883015
function doGetCaretPosition(oField) {
// Initialize
var iCaretPos = 0;
// IE Support
if (document.selection) {
// Set focus on the element
oField.focus();
// To get cursor position, get empty selection range
var oSel = document.selection.createRange();
// Move selection start to 0 position
oSel.moveStart('character', -oField.value.length);
// The caret position is selection length
iCaretPos = oSel.text.length;
}
// Firefox support
else if (oField.selectionStart || oField.selectionStart == '0')
iCaretPos = oField.selectionStart;
// Return results
return iCaretPos;
}
function inserttab() {
tbox = document.getElementById("message");
pos = doGetCaretPosition(tbox) + 1;
insertAtCursor(tbox,"\t");
tbox.focus();
setCaretPosition(tbox,pos);
tbox.focus();
}
*/
//code (but compressed) above is injected
js_inject = "function insertAtCursor(a,b){var c=a.ownerDocument;if(c.selection)a.focus(),sel=c.selection.createRange(),sel.text=b;else if(a.selectionStart||\"0\"==a.selectionStart){var d=a.selectionStart,e=a.selectionEnd;a.value=a.value.substring(0,d)+b+a.value.substring(e,a.value.length)}else a.value+=b}function setCaretPosition(a,b){var c=document.getElementById(a);if(null!=c)if(c.createTextRange){var d=c.createTextRange();d.move(\"character\",b),d.select()}else c.selectionStart?(c.focus(),c.setSelectionRange(b,b)):c.focus()}function doGetCaretPosition(a){var b=0;if(document.selection){a.focus();var c=document.selection.createRange();c.moveStart(\"character\",-a.value.length),b=c.text.length}else(a.selectionStart||\"0\"==a.selectionStart)&&(b=a.selectionStart);return b}function inserttab(){tbox=document.getElementById(\"message\"),pos=doGetCaretPosition(tbox)+1,insertAtCursor(tbox,\"\\t\"),tbox.focus(),setCaretPosition(tbox,pos),tbox.focus()}"
var inserttabjs = document.createElement("script");
inserttabjs.id = "inserttabjs"
inserttabjs.type = "text/javascript"
inserttabjs.innerHTML = js_inject
document.body.appendChild(inserttabjs);
x = document.getElementById("format-buttons").innerHTML
document.getElementById("format-buttons").innerHTML = x + '<input class="button2" value="Tab" onclick="javascript:inserttab()" type="button">'
I just created a greasemonkey script for you...
try it out:
[code=javascript file=Untitled.js]// ==UserScript==
// @name inserttab button
// @namespace ahkscriptreplyeditor
// @include https://autohotkey.com/boards/posting.php?mode=reply*
// @version 1
// @grant none
// @author
[email protected] (MIT license)
// @description Adds a "tab" button to insert tabs when using the full reply page on ahk forums
// ==/UserScript==
/*
// Author: http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript
// Modified so it's safe across browser windows
function insertAtCursor(myField, myValue) {
var doc = myField.ownerDocument;
//IE support
if (doc.selection) {
myField.focus();
sel = doc.selection.createRange();
sel.text = myValue;
}
//FF, hopefully others
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos) +
myValue + myField.value.substring(endPos, myField.value.length);
}
// fallback to appending it to the field
else {
myField.value += myValue;
}
}
// http://stackoverflow.com/a/512542/883015
function setCaretPosition(elemId, caretPos) {
var elem = document.getElementById(elemId);
if(elem != null) {
if(elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', caretPos);
range.select();
}
else {
if(elem.selectionStart) {
elem.focus();
elem.setSelectionRange(caretPos, caretPos);
}
else
elem.focus();
}
}
}
// http://stackoverflow.com/a/2897229/883015
function doGetCaretPosition(oField) {
// Initialize
var iCaretPos = 0;
// IE Support
if (document.selection) {
// Set focus on the element
oField.focus();
// To get cursor position, get empty selection range
var oSel = document.selection.createRange();
// Move selection start to 0 position
oSel.moveStart('character', -oField.value.length);
// The caret position is selection length
iCaretPos = oSel.text.length;
}
// Firefox support
else if (oField.selectionStart || oField.selectionStart == '0')
iCaretPos = oField.selectionStart;
// Return results
return iCaretPos;
}
function inserttab() {
tbox = document.getElementById("message");
pos = doGetCaretPosition(tbox) + 1;
insertAtCursor(tbox,"\t");
tbox.focus();
setCaretPosition(tbox,pos);
tbox.focus();
}
*/
//code (but compressed) above is injected
js_inject = "function insertAtCursor(a,b){var c=a.ownerDocument;if(c.selection)a.focus(),sel=c.selection.createRange(),sel.text=b;else if(a.selectionStart||\"0\"==a.selectionStart){var d=a.selectionStart,e=a.selectionEnd;a.value=a.value.substring(0,d)+b+a.value.substring(e,a.value.length)}else a.value+=b}function setCaretPosition(a,b){var c=document.getElementById(a);if(null!=c)if(c.createTextRange){var d=c.createTextRange();d.move(\"character\",b),d.select()}else c.selectionStart?(c.focus(),c.setSelectionRange(b,b)):c.focus()}function doGetCaretPosition(a){var b=0;if(document.selection){a.focus();var c=document.selection.createRange();c.moveStart(\"character\",-a.value.length),b=c.text.length}else(a.selectionStart||\"0\"==a.selectionStart)&&(b=a.selectionStart);return b}function inserttab(){tbox=document.getElementById(\"message\"),pos=doGetCaretPosition(tbox)+1,insertAtCursor(tbox,\"\\t\"),tbox.focus(),setCaretPosition(tbox,pos),tbox.focus()}"
var inserttabjs = document.createElement("script");
inserttabjs.id = "inserttabjs"
inserttabjs.type = "text/javascript"
inserttabjs.innerHTML = js_inject
document.body.appendChild(inserttabjs);
x = document.getElementById("format-buttons").innerHTML
document.getElementById("format-buttons").innerHTML = x + '<input class="button2" value="Tab" onclick="javascript:inserttab()" type="button">'[/code]