Last active
October 15, 2016 21:16
-
-
Save Farow/7684bddd54517a3fbfe9 to your computer and use it in GitHub Desktop.
Bing Images Direct
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
// ==UserScript== | |
// @name Bing Images Direct | |
// @namespace https://github.com/Farow/userscripts | |
// @description Removes the preview popup and links lead directly to the images | |
// @include http*://www.bing.com/images/search* | |
// @include http*://www.bing.com/videos/search* | |
// @version 1.0.2 | |
// @grant none | |
// ==/UserScript== | |
/* | |
changelog: | |
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); | |
init(); | |
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) { | |
return; | |
} | |
} | |
var images = wrapper.getElementsByClassName('dg_u'); | |
for (var i = 0; i < images.length; i++) { | |
make_direct(images[i].children[0]); | |
} | |
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++) { | |
make_direct(images[k].children[0]); | |
} | |
} | |
}); | |
} |
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 https://greasyfork.org/en so that we can get automatic updates and fixes if/when you update?
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
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.