Skip to content

Instantly share code, notes, and snippets.

@JakubMarcinkowski
Created August 24, 2022 06:13
Show Gist options
  • Save JakubMarcinkowski/17556651b07329b7753974cc222be672 to your computer and use it in GitHub Desktop.
Save JakubMarcinkowski/17556651b07329b7753974cc222be672 to your computer and use it in GitHub Desktop.
Userscript for Tampermonkey (maybe for other managers too). It just copy a table to clipboard. Pasteable into spreadsheets.
// ==UserScript==
// @name Table copier
// @version 0.1
// @description Copy a table to clipboard. Pasteable into spreadsheets.
// @author Jakub Marcinkowski <kuba.marcinkowski on g mail>
// @match http*://*/*
// @grant GM_registerMenuCommand
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
function copyTable() {
const tables = document.querySelectorAll('table');
let table = null;
switch (tables.length) {
case 0:
alert(`There are no HTML tables.`);
break;
case 1:
table = tables[0];
default:
if (table === null) {
const choice = parseInt(prompt(`There are ${tables.length} tables, which one to copy?`));
if (choice >= 1 && choice <= tables.length) {
table = tables[choice - 1];
} else {
alert(`Number is out of range, please try again.`);
copyTable();
return;
}
}
GM_setClipboard(table.outerHTML, 'html');
alert(`Table is propably copied. Now paste it into spreadsheet.`);
}
}
GM_registerMenuCommand('Copy table for spreadsheet', copyTable);
})();
@JakubMarcinkowski
Copy link
Author

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