Skip to content

Instantly share code, notes, and snippets.

@kieronlanning
Created January 14, 2025 23:39
Show Gist options
  • Save kieronlanning/1636f82e7f7fb0abfb5c4ef133051cad to your computer and use it in GitHub Desktop.
Save kieronlanning/1636f82e7f7fb0abfb5c4ef133051cad to your computer and use it in GitHub Desktop.
TamperMonkey script for opening Bing search results in a new tab
// ==UserScript==
// @name Bing Links Open in New Tab
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Makes Bing search results open in a new tab. Why? See here: https://www.reddit.com/r/edge/comments/113gvpf/bing_results_in_edge_browser_redirect_to_bingcom/
// @author Kieron Lanning
// @match https://www.bing.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to set target="_blank" for all result links
function modifyBingLinks() {
// Select all links in Bing search results
const links = document.querySelectorAll('a');
links.forEach(link => {
// Check if the link is part of the search results
if (link.href && link.closest('.b_algo')) {
link.target = '_blank';
}
});
}
// Run the function on page load
window.addEventListener('load', modifyBingLinks);
// Run the function again when the DOM updates (e.g., when new results load dynamically)
const observer = new MutationObserver(modifyBingLinks);
observer.observe(document.body, { childList: true, subtree: true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment