-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All this does is grab the HTML from a page via Electron and throw it into a file.
- Loading branch information
0 parents
commit b3d8682
Showing
4 changed files
with
77 additions
and
0 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 @@ | ||
node_modules/ |
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,7 @@ | ||
#!/usr/bin/env node | ||
'use strict' | ||
const electronPath = require('electron-prebuilt') | ||
const childProcess = require('child_process') | ||
var args = process.argv.slice(2) | ||
args.unshift(__dirname + '/../') | ||
childProcess.spawn(electronPath, args, {stdio: 'inherit'}) |
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,47 @@ | ||
'use strict' | ||
const {app, BrowserWindow} = require('electron') | ||
const yargs = require('yargs') | ||
const temp = require('temp') | ||
const path = require('path') | ||
|
||
process.on('uncaughtException', function (err) { | ||
console.error(err) | ||
app.quit() | ||
}) | ||
|
||
var win, filename, url | ||
|
||
function onReady () { | ||
const options = { frame: false, height: 768, width: 1024, x: 0, y: 0, show: false } | ||
win = new BrowserWindow(options) | ||
win.webContents.once('did-stop-loading', grabPage) | ||
win.loadURL(url) | ||
} | ||
|
||
function grabPage () { | ||
temp.track() | ||
const dir = temp.mkdirSync('scanner') | ||
filename = path.join(dir, 'page.html') | ||
console.log(`Saving to ${filename}`) | ||
win.webContents.savePage(filename, 'HTMLOnly', scanPage) | ||
} | ||
|
||
function scanPage (error) { | ||
// Do the scan here, HTML source is in filename | ||
app.quit() | ||
if (error) { | ||
console.error(error) | ||
process.exit(-1) | ||
} | ||
} | ||
|
||
const argv = yargs | ||
.usage('Usage: $0 URL') | ||
.demand(1) | ||
.strict() | ||
.version() | ||
.help('h') | ||
.argv | ||
|
||
url = argv._[0] | ||
app.once('ready', onReady) |
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,22 @@ | ||
{ | ||
"name": "scanner", | ||
"version": "0.0.1", | ||
"description": "Advise on what's adblocking you.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"bin": { | ||
"scan": "./bin/scan" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"mocha": "^2.5.3" | ||
}, | ||
"dependencies": { | ||
"electron-prebuilt": "^1.2.6", | ||
"temp": "^0.8.3", | ||
"yargs": "^4.7.1" | ||
} | ||
} |