Skip to content

Instantly share code, notes, and snippets.

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 dsottimano/ed03c97a504fcb63b122ad007988aa47 to your computer and use it in GitHub Desktop.
Save dsottimano/ed03c97a504fcb63b122ad007988aa47 to your computer and use it in GitHub Desktop.
seo dev tools
// ==UserScript==
// @name seo
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @include https://*
// @include http://*
// @grant GM_addStyle
// @grant GM_notification
// @grant unsafeWindow
// @grant GM_openInTab
//@noframes
// ==/UserScript==
//don't rerun this script on iframes, keep this line!
//if (window.top != window.self) return
var seo = {}
unsafeWindow.seo = seo;
seo.clipBoardMessage = "The output has been copied to your clipboard and also displayed below:";
seo.info = function () {
console.log('%c 🛠️ SEO Console tools! 🛠️ ', 'background: #222; color: #bada55; font-size:26px;');
console.group("%c 🔎 Extraction Functions", 'color: red; font-size:16px;');
console.log("seo.getAllLinks(): extracts all links from page and copies to clipboard");
console.log("seo.getInternalLinks(): extracts all internal links from page and copies to clipboard");
console.log("seo.getExternalLinks(): extracts all external links from page and copies to clipboard");
console.log("seo.getHreflang(): extracts all hreflang annotations from page and copies to clipboard");
console.groupEnd();
console.group("%c 🔒 Security", 'color: red; font-size:16px;');
console.log("seo.securityTests(): runs sucuri scan in new tab");
console.groupEnd();
console.group("%c 🤖 Google Tests", 'color: red; font-size:16px;');
console.log("seo.googleTests(): runs mobile friendly, SDTT, and rich results mobile tests in new tabs");
console.log("seo.getRankingFactors(): runs Google NLP against word embeddings to return on-page ranking factors in a new tab");
console.groupEnd();
console.group("%c 🍭 CSS Styling", 'color: red; font-size:16px;');
console.log("seo.removeCss(): removes the injected css from the script");
console.log("seo.addCss(): injects css from the script");
console.groupEnd();
console.group("%c 🕵🏾 Google emulation", 'color: red; font-size:16px;');
console.log("seo.bypassGoogleBlock(): opens new tab through translate proxy");
console.groupEnd();
};
//styling functions start //
seo.removeCss = function () {
document.getElementById("seoScriptsMainCss").remove();
}
seo.addCss = ()=>{
let css = `
a[rel~=nofollow] {
background-color: red !important;
color: white !important;
}
`
let head = document.head || document.getElementsByTagName('head')[0]
let seoScriptStyle = document.createElement('style');
seoScriptStyle.setAttribute("id", "seoScriptsMainCss");
head.appendChild(seoScriptStyle);
seoScriptStyle.type = 'text/css';
seoScriptStyle.appendChild(document.createTextNode(css));
}
//styling functions end//
seo.arrayToCSV = function (objArray) {
const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
let str = `${Object.keys(array[0]).map(value => `"${value}"`).join("\t")}` + '\r\n';
return array.reduce((str, next) => {
str += `${Object.values(next).map(value => `"${value}"`).join("\t")}` + '\r\n';
return str;
}, str);
}
//extraction functions start//
seo.getAllLinks = ()=> {
let links = [...$x("//a/@href")].map(x=>x.nodeValue) || [];
if (links.length == 0) return "No links found on this page";
console.info(seo.clipBoardMessage)
copy(links.join("\n"))
return console.table(links);
}
seo.getInternalLinks = ()=> {
let links = [...$x("//a/@href")].map(x=>x.nodeValue) || []
var results = [];
for (var i = 0; i < links.length; i++) {
!links[i].startsWith("http") ? links[i] = new URL(links[i],window.location.protocol + "//" + window.location.hostname) : links[i] = new URL(links[i])
if (links[i].hostname == window.location.hostname) results.push(links[i].href)
}
console.info(seo.clipBoardMessage)
copy(results.join("\n"))
return console.table(results);
}
seo.getExternalLinks = ()=> {
let links = [...$x("//a/@href")].map(x=>x.nodeValue) || []
var results = [];
for (var i = 0; i < links.length; i++) {
!links[i].startsWith("http") ? links[i] = new URL(links[i],window.location.protocol + "//" + window.location.hostname) : links[i] = new URL(links[i])
if (links[i].hostname !== window.location.hostname) results.push(links[i].href)
}
console.info(seo.clipBoardMessage)
copy(results.join("\n"))
return console.table(results);
}
seo.getHreflang = ()=> {
var hreflangObj = [...$x("//link[@rel='alternate']/@hreflang")].map(x=>x.ownerElement)
if (hreflangObj.length < 1) return console.log("no hreflang found");
var results = [];
for (var i = 0; i < hreflangObj.length; i++) {
results.push({
"url" : hreflangObj[i].href,
"hreflang" : hreflangObj[i].hreflang
})
}
console.info(seo.clipBoardMessage)
copy(seo.arrayToCSV(results))
return console.table(results);
}
seo.bypassGoogleBlock = () => {
GM_openInTab("https://translate.google.com/translate?hl=en&sl=es&tl=en&u="+encodeURIComponent(window.location.href), {"loadInBackground": true})
}
seo.googleTests = () => {
GM_openInTab("https://search.google.com/test/mobile-friendly?utm_source=gws&utm_medium=onebox&utm_campaign=suit&url="+encodeURIComponent(window.location.href), {"loadInBackground": true})
GM_openInTab("https://search.google.com/structured-data/testing-tool/u/0/#url="+encodeURIComponent(window.location.href), {"loadInBackground": true})
GM_openInTab("https://search.google.com/test/rich-results?url="+encodeURIComponent(window.location.href), {"loadInBackground": true})
}
seo.securityTests = () => {
GM_openInTab("https://sitecheck.sucuri.net/results/"+window.location.href, {"loadInBackground": true})
}
seo.getRankingFactors = () => {
window.location = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
}
seo.addCss()
seo.info()
@Korb
Copy link

Korb commented Feb 24, 2023

What exactly does this script do?

@dsottimano
Copy link
Author

It was a proof of concept SEO multi tool function from the Chrome dev tools console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment