Skip to content

Instantly share code, notes, and snippets.

@dclamage
Last active November 12, 2021 07:50
Show Gist options
  • Save dclamage/f3c0cad6bb9977b2324a0b2364c5439f to your computer and use it in GitHub Desktop.
Save dclamage/f3c0cad6bb9977b2324a0b2364c5439f to your computer and use it in GitHub Desktop.
Allows pasting into cosmetic text (including unicode).
// ==UserScript==
// @name Fpuzzles-Paste
// @namespace http://tampermonkey.net/
// @version 1.3
// @description Allows pasting into cosmetic text (including unicode).
// @author Rangsk
// @match https://*.f-puzzles.com/*
// @match https://f-puzzles.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
const doShim = function() {
'use strict';
window.addEventListener('paste', function(event) {
if (!popup &&
toolCosmetics.includes(currentTool) &&
!disableInputs &&
!testPaused()) {
event.preventDefault();
const text = (event.clipboardData || window.clipboardData).getData('text/plain');
if (text && text.length > 0) {
for (var i = 0; i < text.length; i++) {
const c = text.charAt(i);
const cUpper = c.toUpperCase();
if (!cosmeticTypableCharacters.includes(cUpper)) {
cosmeticTypableCharacters.push(cUpper);
}
const prevControlling = controlling;
controlling = false;
typeCosmetic(text.charAt(i));
controlling = prevControlling;
}
}
}
});
const prevOnKeyDown = document.onkeydown;
document.onkeydown = function(event) {
// Don't let 'v' change modes.
if (event.key !== 'v' ||
popup ||
!toolCosmetics.includes(currentTool) ||
disableInputs ||
testPaused() ||
!event.ctrlKey ||
event.altKey ||
event.metaKey) {
prevOnKeyDown(event);
}
}
}
let intervalId = setInterval(() => {
if (!document.onkeydown) {
return;
}
clearInterval(intervalId);
doShim();
}, 16);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment