Google Images Un-target to Open in Same Tab

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

当前为 2016-02-27 提交的版本,查看 最新版本

  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-02-26)
  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. // @version 0.5
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // Add MutationObserver to catch additions
  14. var GIUtOST_MutOb = (window.MutationObserver) ? window.MutationObserver : window.WebKitMutationObserver;
  15. if (GIUtOST_MutOb){
  16. var GIUtOST_chgMon = new GIUtOST_MutOb(function(mutationSet){
  17. mutationSet.forEach(function(mutation){
  18. for (var i=0; i<mutation.addedNodes.length; i++){
  19. if (mutation.addedNodes[i].nodeType == 1){
  20. GIUtOST_checkNode(mutation.addedNodes[i]);
  21. }
  22. }
  23. });
  24. });
  25. // attach chgMon to document.body
  26. var opts = {childList: true, subtree: true};
  27. GIUtOST_chgMon.observe(document.body, opts);
  28. }
  29. var tgts = document.querySelectorAll('.irc_c a[target="_blank"]');
  30. if (tgts.length > 0) GIUtOST_untarget(tgts);
  31.  
  32. // Check added element for visit page/image links
  33. function GIUtOST_checkNode(el){
  34. var tgts = el.querySelectorAll('.irc_c a[target="_blank"]');
  35. if (tgts.length > 0) GIUtOST_untarget(tgts);
  36. }
  37. // Un-target
  38. function GIUtOST_untarget(nlist){
  39. for (var i=0; i<nlist.length; i++) nlist[i].removeAttribute("target");
  40. }