open link in new window - Trello

Open the link in card description from new window.

  1. // ==UserScript==
  2. // @name open link in new window - Trello
  3. // @namespace
  4. // @version 0.2.1
  5. // @license MPL-2.0
  6. // @description Open the link in card description from new window.
  7. // @author c4r
  8. // @match https://*trello.com/b/*
  9. // @match https://*trello.com/c/*
  10. // @match https://*trello.com/*
  11. // @include https://*trello.com/b/*
  12. // @include https://*trello.com/c/*
  13. // @include https://*trello.com*
  14. // @require https://code.jquery.com/jquery-latest.js
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20.  
  21.  
  22. /*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
  23. that detects and handles AJAXed content.
  24. auther : BrockA
  25. homepage : https://gist.github.com/BrockA/2625891#file-waitforkeyelements-js
  26. Usage example:
  27.  
  28. waitForKeyElements (
  29. "div.comments"
  30. , commentCallbackFunction
  31. );
  32.  
  33. //--- Page-specific function to do what we want when the node is found.
  34. function commentCallbackFunction (jNode) {
  35. jNode.text ("This comment changed by waitForKeyElements().");
  36. }
  37.  
  38. IMPORTANT: This function requires your script to have loaded jQuery.
  39. */
  40. function waitForKeyElements (
  41. selectorTxt, /* Required: The jQuery selector string that
  42. specifies the desired element(s).
  43. */
  44. actionFunction, /* Required: The code to run when elements are
  45. found. It is passed a jNode to the matched
  46. element.
  47. */
  48. bWaitOnce, /* Optional: If false, will continue to scan for
  49. new elements even after the first match is
  50. found.
  51. */
  52. iframeSelector /* Optional: If set, identifies the iframe to
  53. search.
  54. */
  55. ) {
  56. var targetNodes, btargetsFound;
  57.  
  58. if (typeof iframeSelector == "undefined")
  59. targetNodes = $(selectorTxt);
  60. else
  61. targetNodes = $(iframeSelector).contents ()
  62. .find (selectorTxt);
  63.  
  64. if (targetNodes && targetNodes.length > 0) {
  65. btargetsFound = true;
  66. /*--- Found target node(s). Go through each and act if they
  67. are new.
  68. */
  69. targetNodes.each ( function () {
  70. var jThis = $(this);
  71. var alreadyFound = jThis.data ('alreadyFound') || false;
  72.  
  73. if (!alreadyFound) {
  74. //--- Call the payload function.
  75. var cancelFound = actionFunction (jThis);
  76. if (cancelFound)
  77. btargetsFound = false;
  78. else
  79. jThis.data ('alreadyFound', true);
  80. }
  81. } );
  82. }
  83. else {
  84. btargetsFound = false;
  85. }
  86.  
  87. //--- Get the timer-control variable for this selector.
  88. var controlObj = waitForKeyElements.controlObj || {};
  89. var controlKey = selectorTxt.replace (/[^\w]/g, "_");
  90. var timeControl = controlObj [controlKey];
  91.  
  92. //--- Now set or clear the timer as appropriate.
  93. if (btargetsFound && bWaitOnce && timeControl) {
  94. //--- The only condition where we need to clear the timer.
  95. clearInterval (timeControl);
  96. delete controlObj [controlKey]
  97. }
  98. else {
  99. //--- Set a timer, if needed.
  100. if ( ! timeControl) {
  101. timeControl = setInterval ( function () {
  102. waitForKeyElements ( selectorTxt,
  103. actionFunction,
  104. bWaitOnce,
  105. iframeSelector
  106. );
  107. },
  108. 300
  109. );
  110. controlObj [controlKey] = timeControl;
  111. }
  112. }
  113. waitForKeyElements.controlObj = controlObj;
  114. }
  115.  
  116.  
  117. function addTarget() {
  118.  
  119. let objContent = $("div.description-content > div.current");
  120.  
  121. // console.log(objContent);
  122. if (objContent.length != 0) {
  123. let objUrl = $(objContent).find( "a[href^='http']" );
  124. $(objUrl).each(function(index, element){
  125. $(element).attr("target",$(element).attr("href"));
  126. });
  127. }
  128. }
  129.  
  130.  
  131.  
  132. $( document ).ready(() =>{
  133.  
  134. addTarget();
  135.  
  136. waitForKeyElements ("div.window-wrapper.js-tab-parent > div.card-detail-window", addTarget);
  137. });
  138.  
  139. })();

QingJ © 2025

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