Skip to content

Commit

Permalink
Load up a page's HTML.
Browse files Browse the repository at this point in the history
All this does is grab the HTML from a page via Electron and throw it
into a file.
  • Loading branch information
dougluce committed Jul 7, 2016
0 parents commit b3d8682
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
7 changes: 7 additions & 0 deletions bin/scan
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'})
47 changes: 47 additions & 0 deletions index.js
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)
22 changes: 22 additions & 0 deletions package.json
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"
}
}

0 comments on commit b3d8682

Please sign in to comment.