Skip to content

Instantly share code, notes, and snippets.

@chuckrincon
Last active March 6, 2020 18:04
Show Gist options
  • Save chuckrincon/162031753bdeaca5f85d46b25b6494b7 to your computer and use it in GitHub Desktop.
Save chuckrincon/162031753bdeaca5f85d46b25b6494b7 to your computer and use it in GitHub Desktop.
javascript:function getKeywords(){var e="",o=document.getElementsByTagName("meta");if(o.length){for(var t=0;t<o.length;t++)"keywords"===o[t].name.toLowerCase()&&(e+=o[t].content.toLowerCase());if(e){let o=e.split(","),t=document.createElement("textarea");t.value=o.sort().join("\n"),document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t),alert(`Se copiaron [${o.length}] keywords del sitio:\n${window.location.origin}`)}else{e.split(",");let o=document.createElement("textarea");o.value=`No se encontraron keywords el sitio:\n${window.location.origin}`,document.body.appendChild(o),o.select(),document.execCommand("copy"),document.body.removeChild(o),alert(`No se encontraron keywords el sitio:\n${window.location.origin}`)}}}getKeywords();
function getKeywords() {
var keywords = "";
var metas = document.getElementsByTagName("meta");
if (metas.length) {
for (var index = 0; index < metas.length; index++) {
if (metas[index].name.toLowerCase() === "keywords") {
keywords += metas[index].content.toLowerCase();
}
}
if (keywords) {
let siteKeywords = keywords.split(",");
let textAreaMock = document.createElement("textarea");
textAreaMock.value = siteKeywords.sort().join("\n");
document.body.appendChild(textAreaMock);
textAreaMock.select();
document.execCommand("copy");
document.body.removeChild(textAreaMock);
alert(
`Se copiaron [${siteKeywords.length}] keywords del sitio:\n${window.location.origin}`
);
} else {
let siteKeywords = keywords.split(",");
let textAreaMock = document.createElement("textarea");
textAreaMock.value = `No se encontraron keywords el sitio:\n${window.location.origin}`;
document.body.appendChild(textAreaMock);
textAreaMock.select();
document.execCommand("copy");
document.body.removeChild(textAreaMock);
alert(`No se encontraron keywords el sitio:\n${window.location.origin}`);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment