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 : '') } }) })
function createDocument() { return (new JSDOM('', {runScripts: 'dangerously'})).window.document; }
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)); });
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 }); }) }
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)); }); })
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") } }
topics.forEach(topic => { downloadPage(`https://medium.com/topic/${topic}`, (content) => { const articles = findArticles(new JSDOM(content).window.document); Object.values(articles) .forEach(printArticle); }); });
it('chart -> png | with defined document', function(done) { var params = { outputType: 'png' }; var doc = createWindow().document; var anychart = require('anychart')(doc.defaultView); var chart = anychart.pie([10, 20, 8, 5, 12, 9]); chart.container('container').draw(); params.containerId = 'container'; params.document = doc; app.exportTo(chart, params, function(err, image) { expect(image).to.be.instanceof(Buffer); expect(err).to.be.null; done(); }); });
async _mapAudioUrls(body, data = {}) { let dom try { dom = await this._getJishoDocument(body) } catch (err) { console.error(err.stack || err) } const doc = dom.window.document const audioElements = doc.querySelectorAll('audio') for (let elem of audioElements) { const underscoreIndex = elem.id.lastIndexOf('_') const colonIndex = elem.id.lastIndexOf(':') const id = elem.id.substring(underscoreIndex + 1, colonIndex) const entry = data.find((i) => i.japanese.find((j) => id == j.word)) entry.mp3Url = this._getAudioSourceByType(elem, kMp3Type) entry.oggUrl = this._getAudioSourceByType(elem, kOggType) } }
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; }); });