Created
April 21, 2020 02:52
-
-
Save heape/f839fe7f733a9310a7d54febe7a382f3 to your computer and use it in GitHub Desktop.
-3923-24390-fmpaefa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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