fs.writeFile('./dist/preview.html', dom.window.document.querySelector("html").innerHTML, (err) => { if (err) throw err; console.log(chalk.whiteBright.bgBlack.bold(" Created [HTML] Preview File !! ")); });
function extract(data) { data.forEach(function (item) { let extension = path.extname(item); if (extension === ".svg") { let fileName = item.replace(/-([a-z])/g, function (i) { return i[1].toUpperCase(); }); let fileData = fs.readFileSync("./icons/" + item).toString(); let dom = new JSDOM(fileData); let svgDefs = dom.window.document.querySelector("defs"); if(svgDefs != undefined){ dom.window.document.querySelector("svg").removeChild(svgDefs); } let svgStyle= dom.window.document.querySelector("style"); if(svgStyle != undefined){ dom.window.document.querySelector("svg").removeChild(svgStyle); } let svgTitle = dom.window.document.querySelector("title"); if(svgTitle != undefined){ dom.window.document.querySelector("svg").removeChild(svgTitle); } let fileDataCore = dom.window.document.querySelector("svg").innerHTML.replace(/\n/g, ""); svgObject[fileName.slice(0, -4)] = fileDataCore; } }); }
context('without any meta tags', function() { before(function() { global.document = new JSDOM(HTML_WITHOUT_META).window.document; options = parser.parse(); }); it('expected to return empty object', function() { expect(options).to.be.empty; }); });
ipc.on('inviteUrl', function (event, steamid) { request('https://steamcommunity.com/profiles/' + steamid, function (err, resp, body) { if (!err && resp.statusCode === 200) { let dom = new JSDOM(body, { runScripts: "outside-only" }) let joinBtn = dom.window.document.querySelector('.profile_in_game_joingame a'); event.sender.send('inviteUrl', (joinBtn !== null) ? joinBtn.href : '') } }) })
toBuffer (mime = 'image/png') { return this.toBlob(mime) .then(blob => new Promise((resolve, reject) => { const reader = new this.window.FileReader() reader.onload = function (){ const buffer = new Buffer(reader.result) resolve(buffer) } reader.readAsArrayBuffer(blob) })) .catch(console.error) }
downloadPage('https://medium.com/topic/javascript', (content) => { const document = new JSDOM(content).window.document; Array.from(document.querySelectorAll('a')) .map((el) => el.text) .filter(s => s.trim() != '') .forEach((s) => console.log(s)); });
// if DOMParser is not defined then assign jsdom DOMParser(); (function(global) { var jsdom = require('jsdom'), dom = new jsdom.JSDOM(''); global.DOMParser = dom.window.DOMParser; })(global);
http.get(page, (response) => { if (response.statusCode != 200) { console.error(`Error while fetching page ${page}: ${response.statusCode}`); console.error(`Status message: ${response.statusMessage}`); return; } let content = ''; response.on('data', (chunk) => content += chunk.toString()); response.on('close', () => { console.log('Download finished.'); const document = new JSDOM(content).window.document; writeCSV(extractProducts(document)); }); })
topics.forEach(topic => { downloadPage(`https://medium.com/topic/${topic}`, (content) => { const articles = findArticles(new JSDOM(content).window.document); Object.values(articles) .forEach(printArticle); }); });
static handleMediafire($, url) { request.get(url, { headers: { "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0", } }, function (error, response, body) { var dom = new JSDOM.JSDOM(body); // var link = dom.window.document.querySelector("a[aria-label*='Download file']").href var fileName = dom.window.document.querySelector("div.filename").textContent.trim() $.sendMessage("Download: [" + fileName + "](" + link + ")", { parse_mode: "markdown", reply_to_message_id: $.message.messageId }); }) }
const parseBookmarkContent = (raw) => { try { const doc = new JSDOM(raw); const reader = new Readability(doc.window.document); const parsed = reader.parse(); return parsed } catch (error) { throw new Error("Parsing bookmark failed") } }
downloadPage('https://medium.com/topic/javascript', (content) => { const document = new JSDOM(content).window.document; Array.from(document.querySelectorAll('a')) .map((el) => url.parse(el.href).pathname) .forEach((u) => console.log(u)); });
export function setupJsdom() { const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`); global.document = dom.window.document global.window = dom.window global.navigator = window.navigator }
context('without smartbanner meta tags', function() { before(function() { global.document = new JSDOM(HTML_WITHOUT_SMARTBANNER_META).window.document; options = parser.parse(); }); it('expected to return empty object', function() { expect(options).to.be.empty; }); });