Skip to content

Instantly share code, notes, and snippets.

@AshKyd
Created July 26, 2019 22:21
Show Gist options
  • Save AshKyd/55f86f2edfd5d835fcab4d7b378b6071 to your computer and use it in GitHub Desktop.
Save AshKyd/55f86f2edfd5d835fcab4d7b378b6071 to your computer and use it in GitHub Desktop.
(function() {
const nets = {
twitter: ['https://twitter.com/*$'],
linkedin: ['https://www.linkedin.com/company/*$', 'linkedin.com/in/*$'],
instagram: ['https://www.instagram.com/*$'],
facebook: ['https://www.facebook.com/*$'],
glassdoor: ['https://www.glassdoor.com/Reviews/*.htm$'],
github: ['https://(www.)?github.com/*$']
}
function findMatch(pattern) {
let newPattern = pattern;
newPattern = newPattern.replace(/\//g, '\\/');
newPattern = newPattern.replace(/\./g, '\\.');
newPattern = newPattern.replace('*', '([^"\/]+)');
newPattern = newPattern.replace('$', '["?#]');
newPattern = new RegExp(newPattern);
console.log('matching', newPattern);
const match = document.body.innerHTML.match(newPattern);
console.log('matched', match);
if (match) return match.pop();
}
const foundItems = Object.entries(nets).map(([key, patterns]) => {
const match = patterns.map(findMatch).find(Boolean);
return [key, match];
});
const socialLinks = Object.fromEntries(foundItems);
console.log(socialLinks);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment