Skip to content

Commit

Permalink
version 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
gebrkn committed Apr 6, 2017
1 parent 0ecb05e commit 97cb104
Show file tree
Hide file tree
Showing 58 changed files with 4,020 additions and 1,243 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
.DS_Store
node_modules
app
npm-debug.log
*.zip
._*
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Georg Barikin
Copyright (c) 2014~present Georg Barikin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 21 additions & 15 deletions README.md
Expand Up @@ -7,27 +7,33 @@ Chrome extension to select and copy table cells.

[Install from Chrome Web Store](https://chrome.google.com/webstore/detail/copytables/ekdpkppgmlalfkphpibadldikjimijon)

* Press <kbd>Alt</kbd> and click to select cells.
* <kbd>Alt</kbd> + double click selects a column.
* <kbd>Alt</kbd> + <kbd>Ctrl</kbd> + double click selects a row.
* Copy selection (or the whole table) as rich text (for Word)
* Hold <kbd>Alt</kbd> and drag to select cells.
* Hold <kbd>Alt-Click</kbd> and drag to select columns.
* Copy selection (or the whole table) as seen on the screen (for Word)
* Copy as CSV or tab-delimited text (for Excel).
* Copy as HTML (for your website).
* Copy as CSV.
* Copy as tab-delimited text.

###New in version 0.2

* CSV export.
* Better HTML export.
* Better support for weird table backgrounds (thanks [apptaro](https://github.com/apptaro)).
* Overall speed improvement.
###New in version 0.5

###New in version 0.3

* Styled HTML export.
* Configurable hotkeys for cell, column, row and table selection.
* Capture mode: select with simple click and drag.
* Full support of framed documents.
* Popup information about selected cells.
* Swap (transpose) copy.

###New in version 0.4

* New popup menu.
* Table search function.
* Configurable hotkey (Ctrl/Alt).

###New in version 0.3

* Styled HTML export.

###New in version 0.2

* CSV export.
* Better HTML export.
* Better support for weird table backgrounds (thanks [apptaro](https://github.com/apptaro)).
* Overall speed improvement.
87 changes: 87 additions & 0 deletions convert-logs.js
@@ -0,0 +1,87 @@
/// In dev, rewrite console.logs to something more readable when logged to stdout
/// In production, get rid of them

function __dbg() {
var nl = '\n',
buf = [nl];

function type(x) {
try {
return Object.prototype.toString.call(x).replace('[object ', '').replace(']', '');
} catch (e) {
return '';
}
}

function props(x, depth) {
var r = Array.isArray(x) ? [] : {};
try {
Object.keys(x).forEach(function(k) {
r[k] = inspect(x[k], depth + 1);
});
return r;
} catch(e) {
return 'error';
}
}

function inspect(x, depth) {
if (depth > 5)
return '...';
if (typeof x !== 'object' || x === null)
return x;
var t = type(x),
p = props(x, depth);
if(t === 'Object' || t === 'Array')
return p;
var r = {};
r[t] = p;
return r;
}

buf.push(location ? location.href : '??');

[].forEach.call(arguments, function (arg) {
var t = inspect(arg, 0);
t = JSON.stringify(t, 0, 4);
buf = buf.concat((t || '').split(nl));
});

return buf.map(function (x) {
return x + nl;
});
}


function handleLogging(content, path, isDev) {

var dbg = String(__dbg);
var out = [];

if (isDev) {
out.push(dbg.replace(/\s+/g, ' '));
}

content.split('\n').forEach(function (line, lnum) {
var ref = path + ':' + (lnum + 1);
var m = line.match(/(.*?)console\.log\((.*)\)(.*)/);

if (m) {
if (isDev) {
out.push(`${m[1]}__dbg("${ref}",${m[2]}).forEach(console.log.bind(console))${m[3]}`);
}
} else {
if (isDev && line.match(/function/)) {
out.push(` // ${ref}`);
}
out.push(line);
}
});

return out.join('\n');
}


module.exports = function (content) {
return handleLogging(content, this.resourcePath, this.query == '?dev')
}
80 changes: 80 additions & 0 deletions gulpfile.js
@@ -0,0 +1,80 @@
'use strict';

var
cp = require('child_process'),
del = require('del'),
gulp = require('gulp'),
named = require('vinyl-named'),
pug = require('gulp-pug'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
webpack = require('webpack-stream'),
uglify = require('gulp-uglify'),
util = require('gulp-util')
;

const DEST = './app';
const TEST_URL = 'http://localhost:9876/all';
const IS_DEV = process.env.NODE_ENV === 'dev';

const webpackConfig = {
devtool: null,
module: {
preLoaders: [
{
test: /\.js$/,
loader: __dirname + '/convert-logs?' + (IS_DEV ? 'dev' : '')
}
]
}
};

gulp.task('js', function () {
return gulp.src('./src/*.js')
.pipe(named())
.pipe(webpack(webpackConfig))
.pipe(IS_DEV ? util.noop() : uglify())
.pipe(gulp.dest(DEST))
;
});

gulp.task('sass', function () {
return gulp.src('./src/*.sass')
.pipe(sass())
.pipe(gulp.dest(DEST))
;
});

gulp.task('pug', function () {
return gulp.src('./src/*.pug')
.pipe(pug())
.pipe(gulp.dest(DEST))
;
});

gulp.task('copy', function () {
return gulp.src('./src/*.{png,css,json,svg}')
.pipe(gulp.dest(DEST))
;
});

gulp.task('clean', function () {
return del.sync(DEST);
});

gulp.task('make', ['clean', 'pug', 'sass', 'copy', 'js']);

// npm run watch 'http://...'
var reloadUrl = process.argv[4] || TEST_URL;

gulp.task('reload', ['make'], function () {
cp.execSync('osascript -l JavaScript ./reload-chrome.js "' + reloadUrl + '"');
});

gulp.task('watch', ['reload'], function () {
return gulp.watch('./src/**/*', ['reload']);
});

gulp.task('deploy', ['make'], function () {
cp.execSync('rm -f ./copytables.zip && zip -j ./copytables.zip ./app/*');
});
44 changes: 0 additions & 44 deletions manifest.json

This file was deleted.

37 changes: 37 additions & 0 deletions package.json
@@ -0,0 +1,37 @@
{
"name": "copytables",
"version": "0.5.0",
"description": "Chrome extension to select and copy table cells.",
"scripts": {
"chrome": "'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' --enable-logging=stderr --v=1 2>&1 | grep CONSOLE",
"dev": "NODE_ENV=dev gulp make",
"watch": "NODE_ENV=dev gulp watch --url",
"dev-server": "node ./test/server/index.js",
"production": "NODE_ENV=production gulp make",
"deploy": "NODE_ENV=production gulp deploy"
},
"repository": {
"type": "git",
"url": "git+https://github.com/gebrkn/copytables.git"
},
"author": "Georg Barikin",
"license": "MIT",
"bugs": {
"url": "https://github.com/gebrkn/copytables/issues"
},
"homepage": "https://github.com/gebrkn/copytables#readme",
"devDependencies": {
"del": "^2.2.2",
"express": "^4.15.2",
"glob": "^7.1.1",
"gulp": "^3.9.1",
"gulp-pug": "^3.3.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-uglify": "^2.1.0",
"gulp-util": "^3.0.8",
"mustache": "^2.3.0",
"vinyl-named": "^1.1.0",
"webpack-stream": "^3.2.0"
}
}
72 changes: 72 additions & 0 deletions reload-chrome.js
@@ -0,0 +1,72 @@
/// Reload the extensions page and the the given url.
/// run me as `osascript -l JavaScript reload-chrome.js 'http://whatever`

function run(argv) {
var app = Application('Google Chrome'),
extUrl = 'chrome://extensions/',
ctxUrl = argv;

function each(a, fn) {
for (var i = 0; i < a.length; i++)
fn(a[i], i);
}

function find(a, fn) {
for (var i = 0; i < a.length; i++)
if (fn(a[i], i))
return a[i];
return null;
}

function enumTabs() {
var wts = [];

each(app.windows, function (win) {
each(win.tabs, function (tab, i) {
wts.push([win, tab, i])
});
});

return wts.filter(function (wt) {
return !wt[0].title().match(/^Developer Tools/);
});
}

function reload() {
var wts = enumTabs();

var ctxWt = find(wts, function (wt) {
return wt[1].url() == ctxUrl;
});

var extWt = find(wts, function (wt) {
return wt[1].url() == extUrl;
});

if (!ctxWt) {
console.log('no tab found for ' + ctxUrl);
var w = app.Window().make();
ctxWt = [w, w.tabs[0], 0];
w.tabs[0].url = ctxUrl;
}

if (!extWt) {
console.log('no tab found for ' + extUrl);
var w = app.Window().make();
extWt = [w, w.tabs[0], 0];
w.tabs[0].url = extUrl;
}

while(extWt[1].loading());
while(ctxWt[1].loading());

extWt[1].reload();
while(extWt[1].loading());

ctxWt[1].reload();
ctxWt[0].activeTabIndex = ctxWt[2] + 1;
}

app.activate();
reload();
}

0 comments on commit 97cb104

Please sign in to comment.