'Tampermonkey tab button (->) doesn't skip to the next hyperlink
i was setting up a Tampermonkey script and i was trying it out, I was also trying to use the tab button (->) but if I press it, it doesn't skip to the next hyperlink, instead it puts some spaces into my text. Can someone help me? I would be very greatful.
// ==UserScript==
// @name Edit any Website
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match *://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function () {
'use strict';
// javascript:document.body.contentEditable = 'true' ;
document.designMode = 'on';
document.querySelectorAll('a').forEach((a) => {
a.addEventListener('click', (e) => {
location = e.currentTarget.href;
})
})
})();
var inputs = $(':input').keypress(function(e){
if (e.which == 9) {
e.preventDefault();
var nextInput = inputs.get(inputs.index(this) + 1);
if (nextInput) {
nextInput.focus();
}
}
});
$(function () {
$('textarea').keydown(function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 9) {
e.preventDefault();
var start = $(this).get(0).selectionStart;
var end = $(this).get(0).selectionEnd;
// set textarea value to: text before caret + tab + text after caret
spaces = "\t"
$(this).val($(this).val().substring(0, start)
+ spaces
+ $(this).val().substring(end));
// put caret at right position again
$(this).get(0).selectionStart =
$(this).get(0).selectionEnd = start + 1;
}
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
