Skip to content

Instantly share code, notes, and snippets.

@Bluscream
Last active February 20, 2018 04:31
Show Gist options
  • Select an option

  • Save Bluscream/6226a9d9c8828ddc9a8fccc7b14f5024 to your computer and use it in GitHub Desktop.

Select an option

Save Bluscream/6226a9d9c8828ddc9a8fccc7b14f5024 to your computer and use it in GitHub Desktop.
get colum content
function copyToClipboard(text) {
if (window.clipboardData) { // Internet Explorer
window.clipboardData.setData("Text", text);
} else {
unsafeWindow.netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
clipboardHelper.copyString(text);
}
}
function copyTextToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;
textArea.style.width = '2em';
textArea.style.height = '2em';
textArea.style.padding = 0;
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';
textArea.style.background = 'transparent';
textArea.value = text;
document.body.appendChild(textArea);
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
document.body.removeChild(textArea);
}
function getColumn(table_id, col) {
var tab = document.getElementById(table_id);
var n = tab.rows.length;
var i,
s = [],
tr,
td;
// First check that col is not less then 0
if (col < 0) {
return null;
}
for (i = 0; i < n; i++) {
tr = tab.rows[i];
if (tr.cells.length > col) { // Check that cell exists before you try
td = tr.cells[col]; // to access it.
s.push(td.innerText);
} // Here you could say else { return null; } if you want it to fail
// when requested column is out of bounds. It depends.
}
return s;
}
var txt = getColumn('myTable', 0);
console.log(txt);
copyToClipboard(txt);
copyTextToClipboard(txt);
copy(txt);
function getColumn(table_id, col) {
var tab = document.getElementById(table_id);
var n = tab.rows.length;
var i,
s = [],
tr,
td;
// First check that col is not less then 0
if (col < 0) {
return null;
}
for (i = 0; i < n; i++) {
tr = tab.rows[i];
if (tr.cells.length > col) { // Check that cell exists before you try
td = tr.cells[col]; // to access it.
s.push(td.innerText);
} // Here you could say else { return null; } if you want it to fail
// when requested column is out of bounds. It depends.
}
return s;
}
var txt = getColumn('myTable', 0);
console.log(txt);
copy(txt);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment