Jira External Links Target _blank

Makes all external links in Jira issues have target="_blank" so that they open in a new tab/window

当前为 2022-04-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Jira External Links Target _blank
  3. // @namespace http://free-side.net/tampermonkey
  4. // @version 0.1
  5. // @description Makes all external links in Jira issues have target="_blank" so that they open in a new tab/window
  6. // @author Paul Wheeler
  7. // @license CC0
  8. // @match https://*.atlassian.net/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=atlassian.net
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. let mutationCount = 0;
  17. const checkForLinks = function(mutationsList, observer) {
  18. mutationCount++;
  19.  
  20. // We could check the mutation list to see if it's relelvant, but... lazy
  21. const descriptionLinks = [...document.getElementsByClassName('ak-renderer-document')].flatMap(e => [...e.getElementsByTagName('a')]);
  22. for (const link of descriptionLinks) {
  23. if (link.target !== '_blank') {
  24. console.log(`[${mutationCount}] Updating target for link ${link.href}`);
  25. link.target = '_blank';
  26. link.addEventListener('click', e => {
  27. // prevent JavaScript event handlers from mucking things up
  28. e.stopPropagation();
  29. return false;
  30. });
  31. }
  32. }
  33. };
  34.  
  35. const observer = new MutationObserver(checkForLinks);
  36. observer.observe(document.body, { attributes: false, childList: true, subtree: true });
  37. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址