Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
agent.addListener('next', function (error, agent) {
var htmlPage = agent.body.replace('', '').
replace(//gi, '');
// console.log(htmlPage);
var window = jsdom.jsdom(htmlPage).createWindow();
jsdom.jQueryify(window, 'http://code.jquery.com/jquery-1.4.2.min.js', function (window, jquery) {
var body = jquery('body');
if (phones.length) {
var c1 = body.find('.g-section .g-unit:nth-child(1)');
var c2 = body.find('.g-section .g-unit:nth-child(2)');
var phone = {};
phone.id = agent.url.split(/\//).pop();
phone.name = body.find('h2').text().trim();
phone.description = body.find('.description').text().trim();
phone.availability = c1.find('table:nth-child(1) th:contains("Availability")+td').text().trim().split(/\s*\n\s*/),
phone.battery = {
type: c1.find('table:nth-child(2) th:contains("Type")+td').text(),
talkTime: c1.find('table:nth-child(2) th:contains("Talk time")+td').text(),
standbyTime: c1.find('table:nth-child(2) th:contains("Standby time")+td').text()
};
phone.storage = {
ram: c1.find('table:nth-child(3) th:contains("RAM")+td').text(),
require.paths.unshift('deps/jsdom/lib')
var HTML5 = require('html5'),
Script = process.binding('evals').Script,
util = require('util'),
fs = require('fs'),
jsdom = require('jsdom'),
window = jsdom.createWindow(null, null, {parser: HTML5, document: new jsdom.dom.level1.core.Document()});
window.document.removeChild(window.document.childNodes[0]); // Clear the stub document that jsdom gives us
var parser = new HTML5.Parser({document: window.document});
var inputfile = fs.readFileSync('doc/jquery-example.html');
parser.parse(inputfile);
jsdom.jQueryify(window, 'deps/jquery/dist/jquery.js', function(window, jquery) {
Script.runInNewContext('jQuery("p").append("<b>Hi!</b>")', window);
sys.puts(window.document.innerHTML);
});
// jsdom doesn't yet support createElementNS, so just fake it up
window.document.createElementNS = function(ns, tagName) {
var elem = window.document.createElement(tagName);
elem.getBBox = function() {
return {
x: elem.offsetLeft,
y: elem.offsetTop,
width: elem.offsetWidth,
height: elem.offsetHeight
};
};
return elem;
};
// Load scripts
jsdom.jQueryify(window, 'http://code.jquery.com/jquery-1.4.2.min.js', function(w,jq) {
var filename = 'file:///' + __dirname + '/highcharts/highcharts.src.js';
script.src = filename;
script.onload = function() {
callback(window);
}
window.document.body.appendChild(script);
});
}
Filter.prototype.jQueryify = function(doc, callback) {
var window = null;
try {
window = doc.parentWindow;
window = window || doc.createWindow();
if(window === null) {
throw '';
}
}
catch(e) {
return callback('unable to create jsdom window');
}
try {
jsdom.jQueryify(window, this.jquery_url, function(w, jquery) { // TODO: whats w?
log.debug('callback from jsdom.jQueryify()')
// log.debug('test jquery context: '+jquery('title').html())
return callback(null, jquery);
});
}
catch(e) {
return callback('unable to jqueryify');
}
}
request(requestOptions, function (err, response, body) {
if (undefined != body && null != body){
body = body.replace(/<(\/?)script/g, '<$1nobreakage');
}
setTimeout(runNextFetch, timeSpacing);
if (err) {
stop |= (callback(err, null, null) === false);
}
if (stop) {
return;
}
if (response && response.statusCode == 200) {
var window = jsdom.jsdom().createWindow();
jsdom.jQueryify(window,'./deps/jquery-1.6.1.min.js', function(win, $) {
// The html may not contain a body tag!
var jb = $(body).find('body');
if (jb.length > 0) {
$('head').append($(body).find('head').html());
$('body').append(jb.html());
} else {
$('body').append(body);
}
stop |= (callback(null, $, requestOptions) === false);
});
} else {
stop |= (callback(new Error('Request to '+requestOptions['uri']+' ended with status code: '+(typeof response !== 'undefined' ? response.statusCode : 'unknown')),
null, null) === false);
}
});
})
// jsdom doesn't yet support createElementNS, so just fake it up
window.document.createElementNS = function(ns, tagName) {
var elem = doc.createElement(tagName);
elem.getBBox = function() {
return {
x: elem.offsetLeft,
y: elem.offsetTop,
width: elem.offsetWidth,
height: elem.offsetHeight
};
};
return elem;
};
// Load scripts
jsdom.jQueryify(window, function() {
script.src = 'file://' + __dirname + '/highcharts/highcharts.src.js';
script.onload = function() {
if (this.readyState === 'complete') {
fn(window);
}
}
});
}
, function (err, window) {
if (err) return cb(err);
jsdom.jQueryify(window, "https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js", function (window, $) {
if (!$) return cb("$ was not defined");
var $root = $("body > ol.toc").first()
, tree = []
;
walkTree($, $root, tree);
cb(null, tree, sec, secDir);
}
);
});
}
self.index.featurepic = self.featurepic;
self.index.dyk = self.dyk;
self.index.itn = self.itn;
self.index.otd = self.otd;
self.titles = _(self.index).chain().flatten().unique().value();
self.articles = _(self.titles).map(function (title) {
return self.article(title);
});
if (cbReady) {
cbReady();
}
}
jsdom.jQueryify(this.window, jqueryPath, function () {
self.window.$(onready);
});
}
function _foo() {
var window = jsdom.jsdom(null, null, {parser: HTML5}).createWindow()
var parser = new HTML5.Parser({document: window.document});
parser.parse(html);
jsdom.jQueryify(window, require.resolve("./jquery.min.js"), function(window, jquery) {
cb(jquery, window, null);
});
return;
}
done: function(errors, window) {
jsdom.jQueryify(window, 'http://code.jquery.com/jquery-1.4.2.min.js' , function() {
window.$('meta[property^=og]').each(function(i, tem) {
og.push([ tem.getAttribute('property'), tem.getAttribute('content')]);
});
fn(og);
});
}
});