Fix New-Window Links (Remove target Attribute)

Remove the target attribute from the links matching the given string.

目前为 2020-06-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Fix New-Window Links (Remove target Attribute)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Remove the target attribute from the links matching the given string.
  6. // @author Gavin Borg
  7. // @match https://guru/Search.aspx?*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. var linkQueryStrings = ["#divHubbleRecLinks .rec-links a[target=_blank]"];
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. fixLinks();
  17. })();
  18.  
  19. function fixLinks() {
  20. for(var i = 0; i < linkQueryStrings.length; i++) {
  21. fixLinksWithQuery(linkQueryStrings[i]);
  22. }
  23. }
  24.  
  25. function fixLinksWithQuery(queryString) {
  26. if (document.querySelector(queryString)) { // Make sure the links we want to fix exist, in case they show up via AJAX a little later than page load.
  27. document.querySelectorAll(queryString).forEach(link => link.removeAttribute("target"));
  28. } else {
  29. setTimeout(fixLinksWithQuery.bind(null, queryString), 0);
  30. }
  31. }