SwissCows Un-target Web Result Links to Open in Same Tab

Strip target="_blank" from results links (2020-07-23)

  1. // ==UserScript==
  2. // @name SwissCows Un-target Web Result Links to Open in Same Tab
  3. // @namespace JeffersonScher
  4. // @description Strip target="_blank" from results links (2020-07-23)
  5. // @author Jefferson "jscher2000" Scher
  6. // @copyright Copyright 2020 Jefferson Scher
  7. // @license BSD 3-clause
  8. // @include https://swisscows.com/*
  9. // @version 0.5
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. // Check element for targeted links (and remove target attribute)
  14. function SCUtWRL_checkNode(el){
  15. var tgts = el.querySelectorAll('.web-results a[target="_blank"]');
  16. if (tgts.length > 0){
  17. for (var i=0; i<tgts.length; i++) tgts[i].removeAttribute("target");
  18. }
  19. }
  20. // Add MutationObserver to catch additions
  21. var SCUtWRL_chgMon = new window.MutationObserver(function(mutationSet){
  22. mutationSet.forEach(function(mutation){
  23. for (var i=0; i<mutation.addedNodes.length; i++){
  24. if (mutation.addedNodes[i].nodeType == 1){
  25. SCUtWRL_checkNode(mutation.addedNodes[i]);
  26. }
  27. }
  28. });
  29. });
  30. // attach chgMon to document.body
  31. var opts = {childList: true, subtree: true};
  32. SCUtWRL_chgMon.observe(document.body, opts);
  33. // Check initial results
  34. SCUtWRL_checkNode(document.body);