Google Images Un-target to Open in Same Tab

Strip target="_blank" from links so View image and View page replace the results (2016-06-09)

  1. // ==UserScript==
  2. // @name Google Images Un-target to Open in Same Tab
  3. // @namespace JeffersonScher
  4. // @description Strip target="_blank" from links so View image and View page replace the results (2016-06-09)
  5. // @author Jefferson "jscher2000" Scher
  6. // @copyright Copyright 2016 Jefferson Scher
  7. // @license BSD 3-clause
  8. // @include https://www.google.*/search*tbm=isch*
  9. // @include https://www.google.*/imgres?imgurl=*
  10. // @version 0.6
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. // Add MutationObserver to catch additions
  15. var GIUtOST_MutOb = (window.MutationObserver) ? window.MutationObserver : window.WebKitMutationObserver;
  16. if (GIUtOST_MutOb){
  17. var GIUtOST_chgMon = new GIUtOST_MutOb(function(mutationSet){
  18. mutationSet.forEach(function(mutation){
  19. for (var i=0; i<mutation.addedNodes.length; i++){
  20. if (mutation.addedNodes[i].nodeType == 1){
  21. GIUtOST_checkNode(mutation.addedNodes[i]);
  22. }
  23. }
  24. });
  25. });
  26. // attach chgMon to document.body
  27. var opts = {childList: true, subtree: true};
  28. GIUtOST_chgMon.observe(document.body, opts);
  29. }
  30. var tgts = document.querySelectorAll('.irc_c a[target="_blank"]');
  31. if (tgts.length > 0) GIUtOST_untarget(tgts);
  32.  
  33. // Check added element for visit page/image links
  34. function GIUtOST_checkNode(el){
  35. var tgts = el.querySelectorAll('.irc_c a[target="_blank"]');
  36. if (tgts.length > 0) GIUtOST_untarget(tgts);
  37. }
  38. // Un-target
  39. function GIUtOST_untarget(nlist){
  40. for (var i=0; i<nlist.length; i++) nlist[i].removeAttribute("target");
  41. }