-
-
Save nxn/2be49b49d5f527f870da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name dw.tabs | |
// @namespace http://nxn.io/ | |
// @version 0.1 | |
// @description enter something awful | |
// @match http://*.doomworld.com/vb/* | |
// @copyright 2012+, Nixon | |
// ==/UserScript== | |
(function() { | |
var root = window; | |
if (typeof unsafeWindow === 'object') { | |
root = unsafeWindow; | |
} | |
var m = root.document.querySelector('textarea[name=message]') | |
, f = root.document.querySelector('form[name=vbform]') | |
, tab = ' ' | |
, tab_v = '[tab]' | |
if (!m) return; | |
m.addEventListener( | |
'keydown', | |
function(e) { | |
if (e.keyCode !== 9) return; | |
var cursorPos = this.selectionStart | |
, start = this.value.substring(0, cursorPos) | |
, end = this.value.substring(cursorPos); | |
this.value = start + tab_v + end; | |
this.setSelectionRange(cursorPos + tab_v.length, cursorPos + tab_v.length); | |
e.preventDefault(); | |
} | |
); | |
m.value = m.value.replace(new RegExp(tab, 'gim'), tab_v); | |
if (!f) return; | |
f.addEventListener( | |
'submit', | |
function(e) { | |
m.value = m.value.replace(/\[tab\]/gim, tab) | |
} | |
); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment