Skip to content

Instantly share code, notes, and snippets.

@innocenzi
Created November 4, 2020 19:05
Show Gist options
  • Save innocenzi/17a15feddf2000489be00fb13cc4eb61 to your computer and use it in GitHub Desktop.
Save innocenzi/17a15feddf2000489be00fb13cc4eb61 to your computer and use it in GitHub Desktop.
Sort Google search result per domain
const priority = ['mozilla.org'];
const blocklist = ['w3schools'];
const resultNode = document.getElementById('rso');
// Sort results
const sorted = [...resultNode.children]
.filter((child) => {
const href = child.querySelectorAll('a')?.[0]?.href;
return !blocklist.some(domain => href?.includes(domain));
})
.sort((childA, childB) => {
const href = childA.querySelectorAll('a')?.[0]?.href;
return priority.some(domain => href?.includes(domain))
? -1
: 1;
})
// Clear content
resultNode.innerHTML = '';
// Add results back in
sorted.forEach(result => resultNode.appendChild(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment