Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save devxan/419ed814d011e8fd67b322fb1883a0cb to your computer and use it in GitHub Desktop.
Save devxan/419ed814d011e8fd67b322fb1883a0cb 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);
@devxan
Copy link
Author

devxan commented Aug 2, 2020

NO WAY, IT WORKS!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment