Created
August 24, 2022 06:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
New version:
https://gist.github.com/JakubMarcinkowski/dbc55176baa98f1c636817c08ef1c493