Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
4,020 additions
and
1,243 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.DS_Store | ||
node_modules | ||
app | ||
npm-debug.log | ||
*.zip | ||
._* |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/*'); | ||
}); |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
Oops, something went wrong.