Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"content_scripts": [
{
"js": ["src/content.js"],
"js": ["src/content.js", "src/ascii-table.min.js"],
"css": ["src/content.css"],
"matches": [ "*://*/*", "file://*/*"],
"all_frames": false
Expand Down
1 change: 1 addition & 0 deletions src/ascii-table.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ menu.copyHTML = chrome.contextMenus.create({ "title": "HTML", "par
menu.copyStyled = chrome.contextMenus.create({ "title": "Styled HTML", "parentId": menu.copy, "enabled": false, "contexts": ctx, "onclick": function() { menuClick("copyStyled") }});
menu.copyCSV = chrome.contextMenus.create({ "title": "CSV", "parentId": menu.copy, "enabled": false, "contexts": ctx, "onclick": function() { menuClick("copyCSV") }});
menu.copyText = chrome.contextMenus.create({ "title": "Text-Only", "parentId": menu.copy, "enabled": false, "contexts": ctx, "onclick": function() { menuClick("copyText") }});
menu.copyMysqlTable = chrome.contextMenus.create({ "title": "Copy as Mysql Table result", "parentId": menu.copy, "enabled": false, "contexts": ctx, "onclick": function() { menuClick("copyMysqlTable") }});

// Send a command to tabs.
function sendCommand(cmd, broadcast, fn) {
Expand Down Expand Up @@ -42,6 +43,7 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {

case "copyText":
case "copyHTML":
case "copyMysqlTable":
case "copyStyled":
case "copyCSV":
var t = document.getElementById("___copytables_clipboard___");
Expand Down Expand Up @@ -86,9 +88,8 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
chrome.contextMenus.update(menu.copyStyled, {enabled:s.canCopy});
chrome.contextMenus.update(menu.copyCSV, {enabled:s.canCopy});
chrome.contextMenus.update(menu.copyText, {enabled:s.canCopy});

chrome.contextMenus.update(menu.copyMysqlTable, {enabled:s.canCopy});
sendResponse({});
break;
}
});

34 changes: 28 additions & 6 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Minimal scroll speed (scrolls per second).
var scrollMinSpeed = 30;

// Maximal scroll speed (scrolls per second).
// Maximal scroll speed (scrolls per second).
var scrollMaxSpeed = 150;

// Scroll speed acceleration.
// Scroll speed acceleration.
var scrollAcceleration = 1.01;

// Scroll amount, in pixels.
Expand Down Expand Up @@ -205,7 +205,7 @@

// Options
// ---------------------------

var options = {
modKey: 0
};
Expand Down Expand Up @@ -650,7 +650,6 @@
} else {
ax -= window.scrollX;
ay -= window.scrollY;

}

var rect = [
Expand Down Expand Up @@ -707,6 +706,17 @@
tds.forEach(function(td) { addClass(td, clsSelected) });
};

var arraysEqual = function (arr1, arr2) {
if(arr1.length !== arr2.length)
return false;
for(var i = arr1.length; i--;) {
if(arr1[i].trim() != arr2[i].trim())
return false;
}

return true;
}

// Command helpers
// ---------------------------

Expand All @@ -724,10 +734,22 @@
case "copyHTML":
return selectedHTML(selection.table, false, !anySelected);
case "copyText":
var m = selectedTextMatrix(selection.table, !anySelected);
var m = selectedTextMatrix(selection.table, !anySelected);
return m.map(function(row) {
return rstrip(row.join("\t"));
}).join("\n");
case "copyMysqlTable":
var t = new AsciiTable()

var m = selectedTextMatrix(selection.table, true);
headers = $$("TH", selection.table).map(function(td) { return td.innerText.trim(); });
t.setHeading(headers);

if(arraysEqual(headers, m[0])) {
m.shift();
}

return t.addRowMatrix(m).toString()
case "copyCSV":
var m = selectedTextMatrix(selection.table, !anySelected);
return m.map(function(row) {
Expand Down Expand Up @@ -815,6 +837,7 @@
case "copyRich":
case "copyText":
case "copyHTML":
case "copyMysqlTable":
case "copyStyled":
case "copyCSV":
if(selection)
Expand Down Expand Up @@ -948,4 +971,3 @@


})();

1 change: 1 addition & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<a data-command="copyStyled">Styled</a>
<a data-command="copyCSV">CSV</a>
<a data-command="copyText">Text</a>
<a data-command="copyMysqlTable">Mysql</a>
</p>
<p id="mFind">
<b>Find:</b>
Expand Down
6 changes: 3 additions & 3 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var $ = function(x) { return document.getElementById(x) };

// Send a command to the content.
function sendCommand(cmd, broadcast, fn) {
var qry = broadcast ? {} : {active: true, currentWindow: true};
var qry = broadcast ? {} : {active: true, currentWindow: true};
chrome.tabs.query(qry, function(tabs) {
tabs.forEach(function(tab) {
chrome.tabs.sendMessage(tab.id, {command: cmd}, fn || function(r) {});
Expand All @@ -22,7 +22,7 @@ var updateState = function(state) {
var init = function(state) {

document.addEventListener("click", function(e) {

var cmd = e.target.getAttribute("data-command");
if(!cmd)
return;
Expand All @@ -34,7 +34,7 @@ var init = function(state) {
if(e.target.getAttribute("data-noclose") !== "1")
window.close();
});

});

if(navigator.userAgent.indexOf("Macintosh") > 0) {
Expand Down