Skip to content

Instantly share code, notes, and snippets.

@MegaApuTurkUltra
Last active August 2, 2020 18:32
Show Gist options
  • Save MegaApuTurkUltra/f7a97678757e37953296 to your computer and use it in GitHub Desktop.
Save MegaApuTurkUltra/f7a97678757e37953296 to your computer and use it in GitHub Desktop.
Makes CTRL-Enter submit on Scratch comment and forum editors
// ==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