-
-
Save devxan/419ed814d011e8fd67b322fb1883a0cb to your computer and use it in GitHub Desktop.
Makes CTRL-Enter submit on Scratch comment and forum editors
This file contains hidden or 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 Scratch CTRL-Enter | |
// @namespace http://aputurk.tk/ | |
// @version 0.1 | |
// @description Adds keybinds for posting | |
// @author MegaApuTurkUltra | |
// @match https://scratch.mit.edu/* | |
// @grant none | |
// @run-at document-end | |
// ==/UserScript== | |
/* jshint -W097 */ | |
'use strict'; | |
function main(){ | |
[].forEach.call(document.querySelectorAll(".markItUpEditor"), function(el){ | |
el.addEventListener("keydown", function(e){ | |
if(e.which == 13 && (e.ctrlKey || e.metaKey)){ | |
e.target.form.querySelector("button[type=submit]").click(); | |
} | |
}); | |
}); | |
function update() { | |
[].forEach.call(document.querySelectorAll("[name=content]:not([ce-evented])"), function(el){ | |
el.addEventListener("keydown", function(e){ | |
if(e.which == 13 && (e.ctrlKey || e.metaKey)){ | |
e.target.form.querySelector("[data-control=post]").click(); | |
} | |
}); | |
el.setAttribute("ce-evented", ""); | |
}); | |
}; | |
var target = document.querySelector('#comments'); | |
if(target == null) return; | |
target.addEventListener("DOMNodeInserted", update); | |
update(); | |
} | |
var interval = setInterval(function(){ | |
if(document.querySelectorAll){ | |
clearInterval(interval); | |
main(); | |
} | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NO WAY, IT WORKS!