Skip to content

Instantly share code, notes, and snippets.

@Farow
Last active October 15, 2016 21:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Farow/7684bddd54517a3fbfe9 to your computer and use it in GitHub Desktop.
Save Farow/7684bddd54517a3fbfe9 to your computer and use it in GitHub Desktop.
Bing Images Direct
// ==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]);
}
}
});
}
@Farow
Copy link
Author

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