Skip to content

Instantly share code, notes, and snippets.

@peterlee0127
Created February 1, 2018 03:52
Show Gist options
  • Save peterlee0127/2edd9c0b1e746118aad50b2d65049d4d to your computer and use it in GitHub Desktop.
Save peterlee0127/2edd9c0b1e746118aad50b2d65049d4d to your computer and use it in GitHub Desktop.
Simple check RWD
var phantom = require('phantom');
const fs = require('fs');
const widthTag = 'width=device-width';
const mediaTag = 'media';
//const mediaTag = 'media screen and (';
async function parseSite(url) {
const instance = await phantom.create(['--ignore-ssl-errors=yes']);
const page = await instance.createPage();
page.setting('userAgent',"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1");
await page.on('onResourceRequested', function(requestData,request) {
});
console.log(url);
const status = await page.open(url);
let html = await page.evaluate(function() {
return document;
})
var fwidthTag,fmediaTag = false;
let str = JSON.stringify(html);
if(str.includes(widthTag) ) {
fwidthTag = true;
}
if(str.includes(mediaTag)) {
fmediaTag = true;
}
// Array.prototype.slice.apply(html.styleSheets).forEach(function(styleSheet) {
// if(styleSheet!=null){
//
// for(var i=0;i<styleSheet.rules.length;i++) {
// var cssText = styleSheet.rules[i].cssText
// if(content.includes(widthTag) && content.includes(mediaTag)) {
// found = true;
// }
//
// }
// }
// });
var result = url+' '+fwidthTag+ " "+ fmediaTag+"\n";
await instance.exit();
return result;
};
(async function() {
let siteList = fs.readFileSync('list.txt','utf8').split('\n');
for(var i=0;i<siteList.length;i++){
const url = siteList[i];
let res = await parseSite(url);
fs.appendFileSync('./out.txt',res,'utf8');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment