I'm getting into user scripting with tampermonkey and can't get through this error, any help would be appreciated.
I detect keys fine, space key triggers this function who will repeat itself as long as the key remains in the down position. The console writes the output normally for 30 seconds more or less and then there's a TypeError.
As per reputation-restriction, here's a screenshot:
User-Script:
// ==UserScript==
// @name TEST STUFF--------------------
// @namespace
http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @run-at document-start
// @include http://*
// @include https://*
// @grant none
// ==/UserScript==
( function()
{
'use strict';
window.addEventListener ( "keydown", CaptureKeyPress );
window.addEventListener ( "keyup", CaptureKeyPress );
var Hotkeys =
{
perform: 32
};
var HotkeyToggle = false;
function CaptureKeyPress ( a )
{
if ( a.keyCode == Hotkeys.perform )
{
a.preventDefault();
a.stopPropagation();
a.cancelBubble = true;
a.stopImmediatePropagation();
if ( a.type == "keydown" && !HotkeyToggle )
{
console.clear();
HotkeyToggle = true;
perform();
}
if ( a.type == "keyup" && HotkeyToggle )
{
HotkeyToggle = false;
}
}
}
function perform()
{
if(HotkeyToggle == false) // exit
{
return 0
}
//do stuff...
console.info("working...");
if(HotkeyToggle == true) // continue after everything completes
{
setTimeout(() => {
perform()
}, 280);
return 0
}
return 1
}
} ) ();
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)