Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bing Images Direct
// ==UserScript==
// @name Bing Images Direct
// @namespace
// @description Removes the preview popup and links lead directly to the images
// @include http*://*
// @include http*://*
// @version 1.0.2
// @grant none
// ==/UserScript==
2015-08-27 - 1.0.2 - fixed issue when changing image size
2015-08-06 - 1.0.1 - added support for videos
2015-04-20 - 1.0.0 - initial release
var observer = new MutationObserver(image_observer);
function init() {
var wrapper = document.getElementById('dg_c');
if (!wrapper) {
/* we could be inside an iframe, check parent */
wrapper = window.parent._d.getElementById('dg_c');
/* failure */
if (!wrapper) {
var images = wrapper.getElementsByClassName('dg_u');
for (var i = 0; i < images.length; i++) {
observer.observe(wrapper, { childList: true });
function make_direct(image) {
var url;
/* for images */
if (image.hasAttribute('m')) {
url = image.getAttribute('m').match(/imgurl:"([^"]+?)",/)[1];
/* for videos */
else {
url = image.getAttribute('vrhm').match(/"p":"([^"]+?)"/)[1];
image.outerHTML = '<a href="' + url + '">' + image.innerHTML + '</a>';
function image_observer(mutations) {
mutations.forEach(function(mutation) {
for (var i = 0; i < mutation.addedNodes.length; i++) {
var images = mutation.addedNodes[i].getElementsByClassName('dg_u');
for (var k = 0; k < images.length; k++) {

This comment has been minimized.

Copy link

@HardKoreG HardKoreG commented Apr 29, 2015

Hi, I am HardKoreG on Reddit. I requested this script. I found a bug; When I search in images, it works fine, but if I click on a suggested searches below the search bar, the new search results have overlays and don't go to the direct image. Almost like it disables the script. For now, I have to refresh the page to get the script to work. Could you look into this and fix it? Thanks for making the script.


This comment has been minimized.

Copy link

@Decme Decme commented Aug 6, 2015

Works with normal Bing images search, but seems to break if you choose a custom setting in Bing, such as "large" images (first option on the left)

Can you host this on a userscript site such as so that we can get automatic updates and fixes if/when you update?


This comment has been minimized.

Copy link
Owner Author

@Farow Farow commented Aug 27, 2015

I might post this on oujs at some point. But try not to comment here. I get no notifications on new comments and found this entirely by chance. Contact me on reddit instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment