Created
September 11, 2019 15:03
-
-
Save sajjadmd/da67aed579a15fe72c757f85562f88b1 to your computer and use it in GitHub Desktop.
SEO HTML Meta Elements, shows you on the DevTools console a summary of important HTML elements.
This file contains hidden or 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
| (function() { | |
| clear(); | |
| const elements = [ | |
| "title", | |
| "meta-description", | |
| "meta-robots", | |
| "h1", | |
| "h2", | |
| "h3", | |
| "h4", | |
| "h5", | |
| "h6", | |
| "i", | |
| "b", | |
| "strong", | |
| "em", | |
| "p", | |
| "img", | |
| "video", | |
| "iframe", | |
| ]; | |
| elements.map((e) => { | |
| const E = e.toUpperCase(); | |
| let selector = e; | |
| if (e === "meta-description") { | |
| selector = "meta[name='description']"; | |
| } else if (e === "canonical") { | |
| selector = "link[rel='canonical']"; | |
| } else if (e === "meta-robots") { | |
| selector = "meta[name='robots']"; | |
| } | |
| const found = document.querySelectorAll(selector); | |
| console.log(`%c${E}: Found ${found.length}`, "color:blue;font-size:14px;border-top:1px solid blue;"); | |
| if (found.length > 0) { | |
| found.forEach((f) => { | |
| let text = ""; | |
| if (e === "meta-description" || e === "meta-robots") { | |
| text = f.getAttribute("content"); | |
| } else if (e === "canonical") { | |
| text = f.getAttribute("href"); | |
| } else if (e === "img") { | |
| text = f.getAttribute("alt"); | |
| } else { | |
| text = f.textContent; | |
| } | |
| if (text === "") { | |
| text = "[ EMPTY ]"; | |
| } | |
| if (["iframe", "video"].includes(e)) { | |
| // ignore | |
| } else if (!["p"].includes(e)) { | |
| console.log(`%c${text}\n%c${text && text.length ? text.length : 0}`, "font-size:12px", "color:green;font-size:13px"); | |
| } else { | |
| console.log(`%c${E}: %c${text && text.length ? text.length : 0}`, "font-size:12px", "color:green;font-size:13px"); | |
| } | |
| console.log(f); | |
| }); | |
| } | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment