Created
February 7, 2024 09:32
-
-
Save trumad/2e6ce300357666196b78362e44c2c3c5 to your computer and use it in GitHub Desktop.
Arc Boost - Google Links
This file contains 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
// Original boost: https://arc.net/e/2CADECD1-9839-4057-9EA9-A9988ABC4B92 | |
go(); | |
async function go(){ | |
await wait(1000); | |
addLinks(); | |
} | |
async function addLinks(){ | |
const query = queryParams().q.replace(/\+/g, ' '); | |
// STEP 3: Comment out, or add, your chosen sites here: | |
const wikipediaLink = 'https://en.wikipedia.org/wiki/' + encodeURIComponent(query); | |
addLink('W', 'Wikipedia', wikipediaLink); | |
const redditLink = 'https://www.reddit.com/search/?q=' + encodeURIComponent(query); | |
addLink('👾', 'Reddit', redditLink); | |
const twitterLink = 'https://twitter.com/search?q=' + encodeURIComponent(query); | |
addLink('🐥', 'Twitter', twitterLink); | |
const amazonLink = 'https://www.amazon.com/s?k=' + encodeURIComponent(query); | |
addLink('😳', 'Amazon', amazonLink); | |
// BELOW THIS are helper functions. You can ignore them if you want, or tweak them :) | |
function queryParams() { | |
var query = location.search.substr(1); | |
var result = {}; | |
query.split("&").forEach(function(part) { | |
var item = part.split("="); | |
result[item[0]] = decodeURIComponent(item[1]); | |
}); | |
return result; | |
} | |
function createLink(symbol, name, url) { | |
const a = document.createElement('a'); | |
a.style.color = '#5f6368'; | |
a.style.margin = '0 0.5em'; | |
const icon = document.createElement('span'); | |
icon.innerText = symbol; | |
icon.style.marginRight = '0.5em'; | |
icon.style.fontWeight = 'bold'; | |
a.append(icon); | |
a.append(name); | |
a.setAttribute('href', url); | |
return a; | |
} | |
function addLink(symbol, name, url) { | |
const link = createLink(symbol, name, url); | |
document.querySelector('H1').parentElement.querySelector("a").parentElement.appendChild(link); | |
} | |
} | |
function wait(ms = 1000) { | |
return new Promise((resolve) => { | |
setTimeout(resolve, ms); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment