Skip to content

Instantly share code, notes, and snippets.

@heape
Created April 21, 2020 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heape/f839fe7f733a9310a7d54febe7a382f3 to your computer and use it in GitHub Desktop.
Save heape/f839fe7f733a9310a7d54febe7a382f3 to your computer and use it in GitHub Desktop.
-3923-24390-fmpaefa
var all = document.getElementsByTagName("*");
var dummy = document.body.appendChild(document.createElement('div')); // block
var style = window.getComputedStyle(dummy);
for(let i = 0; i < style.length; i++)
pageObj.DOM.default.style[style[i]] = style.getPropertyValue(style[i]);
for (let i = 0; i < all.length; i++) {
if(all[i].tagName === 'HEAD' || all[i].parentElement == document.head) {
// console.log('skipped');
continue;
}
if(all[i].clientWidth == 0 || all[i].clientHeight == 0) {
continue;
}
var style = window.getComputedStyle(all[i]);
if(style.getPropertyValue('display') == 'none') {
continue;
}
var outerHTML = all[i].outerHTML.replace(all[i].innerHTML, '');
var innerText = '';
if(all[i].innerHTML == all[i].innerText) {
outerHTML = all[i].outerHTML;
innerText = all[i].innerHTML;
} else {
outerHTML = all[i].outerHTML.replace(all[i].innerHTML, '');
innerText = all[i].innerText;
}
if(innerText === undefined) {
innerText = '';
}
var elementObj = {
properties: {
tagName: all[i].tagName, // タグネーム
outerHTML: outerHTML, // HTML
innerText: innerText, // テキスト (textContent)
},
style: {},
};
for(let j = 0; j < style.length; j++) {
if(pageObj.DOM.default.style[style[j]] != style.getPropertyValue(style[j])) {
elementObj.style[style[j]] = style.getPropertyValue(style[j]);
}
}
pageObj.DOM.elements.push(elementObj);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment