Skip to content

Instantly share code, notes, and snippets.

@stevecheckoway
Created July 16, 2021 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevecheckoway/ac8a2ed2840e3804b69a69b318efd805 to your computer and use it in GitHub Desktop.
Save stevecheckoway/ac8a2ed2840e3804b69a69b318efd805 to your computer and use it in GitHub Desktop.
Tampermonkey script to copy the selection in f-puzzles.com
// ==UserScript==
// @name Copy selection
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Copy the value of selected cells
// @author Stephen Checkoway
// @match https://*.f-puzzles.com/*
// @match https://f-puzzles.com/*
// @icon https://www.google.com/s2/favicons?domain=f-puzzles.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
const doShim = function() {
const prevOnKeyDown = document.onkeydown;
document.onkeydown = function(event) {
if (event.key != 'c' || !(event.ctrlKey || event.metaKey)) {
prevOnKeyDown(event);
return;
}
let output = "";
for (let idx = 0; idx < window.selection.length; ++idx) {
output += window.selection[idx].value;
}
navigator.clipboard.writeText(output);
event.preventDefault();
}
}
if (window.grid) {
doShim();
} else {
document.addEventListener('DOMContentLoaded', (event) => {
doShim();
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment