Created
November 4, 2020 19:05
-
-
Save innocenzi/17a15feddf2000489be00fb13cc4eb61 to your computer and use it in GitHub Desktop.
Sort Google search result per domain
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
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