Cobmais - Util

Auxiliar Testes e Debugs

  1. // ==UserScript==
  2. // @name Cobmais - Util
  3. // @namespace http://app.cobmais.com.br/
  4. // @version 1.0.14
  5. // @description Auxiliar Testes e Debugs
  6. // @author Rodrigo Mescua
  7. // @match http*://*.cobmais.com.br/*/telecobranca*
  8. // @match http*://localhost:*/telecobranca*
  9. // @match http*://172.36.1.4/*/telecobranca*
  10. // @match http*://192.36.1.4/*/telecobranca*
  11. // @match http*://app-hml-cobmais.brazilsouth.cloudapp.azure.com/*/telecobranca*
  12. // @icon https://raw.githubusercontent.com/romesc/cobmais-utils/master/favicon.ico
  13. // @require http://code.jquery.com/jquery-3.4.1.min.js
  14. // @require https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js
  15. // @grant GM_addStyle
  16. // @grant GM_setClipboard
  17. // ==/UserScript==
  18. this.$ = this.jQuery = jQuery.noConflict(true) // eslint-disable-line no-undef
  19. waitForKeyElements ("div.ev-item-inclusao", evcFunction);
  20. waitForKeyElements ("div.ct-item", conFunction);
  21. waitForKeyElements (".ct-sel-neg", negFunction);
  22. waitForKeyElements ("span.btneventofinal", testeCopy);
  23. waitForKeyElements ("span.btncontratofinal", testeConCopy);
  24. waitForKeyElements ("span.btnnegociacaofinal", testeNegCopy);
  25.  
  26. function evcFunction (jNode) {
  27. var eventos = document.querySelectorAll('div.ev-item-inclusao');
  28. var teste = '';
  29. for ( var i = 0; i < eventos.length; i++ ) {
  30. if (eventos[i].style.display === "none") {
  31. continue;
  32. }
  33.  
  34. var idEvento = eventos[i].parentElement.parentElement.id.replace('ev-item-','');
  35. teste = ' <span id="btnEv' + idEvento + '" title="Clique para Copiar o ID Evento" class="btn btnevento badge badge-primary" style="cursor: pointer;" data-clipboard-text="' + idEvento + '">' + idEvento + '</span>';
  36. if (i == eventos.length - 1) {
  37. teste = ' <span id="btnEv' + idEvento + '" title="Clique para Copiar o ID Evento" class="btn btnevento btneventofinal badge badge-primary" style="cursor: pointer;" data-clipboard-text="' + idEvento + '">' + idEvento + '</span>';
  38. }
  39. if (eventos[i].innerHTML.indexOf(teste) == -1){
  40. eventos[i].insertAdjacentHTML('beforeEnd',teste);
  41. }
  42. }
  43. }
  44.  
  45. function conFunction (jNode) {
  46. var contratos = document.querySelectorAll('span.ct-item-clique');
  47. var teste = '';
  48. for ( var j = 0; j < contratos.length; j++ ) {
  49. var idContrato = contratos[j].parentElement.dataset.ctt;
  50. teste = '\t<span id="btnCt' + idContrato + '" title="Clique para Copiar o ID Contrato" class="btn btncontrato badge badge-primary" style="cursor: pointer;" data-clipboard-text="' + idContrato + '">' + idContrato + '</span>';
  51. if (j == contratos.length - 1) {
  52. teste = '\t<span id="btnCt' + idContrato + '" title="Clique para Copiar o ID Contrato" class="btn btncontrato btncontratofinal badge badge-primary" style="cursor: pointer;" data-clipboard-text="' + idContrato + '">' + idContrato + '</span>';
  53. }
  54. if (contratos[j].innerHTML.indexOf(teste) == -1){
  55. contratos[j].innerHTML = contratos[j].innerHTML.concat(teste);
  56. }
  57. }
  58. }
  59.  
  60. function testeCopy (teste) {
  61. var btns1 = document.querySelectorAll('span.btnevento');
  62. var clipboard = new ClipboardJS(btns1);
  63.  
  64. clipboard.on('success', function(e) {
  65. toastr.success('ID Evento copiado para a Área de Transferência');
  66. });
  67. }
  68.  
  69. function testeConCopy (teste) {
  70. var btns2 = document.querySelectorAll('span.btncontrato');
  71. var clipboard = new ClipboardJS(btns2);
  72.  
  73. clipboard.on('success', function(e) {
  74. toastr.success('ID Contrato copiado para a Área de Transferência');
  75. });
  76. }
  77.  
  78. function negFunction (jNode) {
  79. var negs = document.querySelectorAll('.ct-neg');
  80. var teste = '';
  81.  
  82. for (var j = 0; j < negs.length; j++ ) {
  83.  
  84. if (negs[j].lastElementChild.classList.contains("btnnegociacao")){
  85. negs[j].lastElementChild.remove();
  86. }
  87.  
  88. var idNeg = negs[j].lastElementChild.firstElementChild.id.replace('ppvNegociacao', '');
  89.  
  90. teste = '\t<span id="btnCopiarNeg' + idNeg + '" title="Clique para copiar o ID da Negociação selecionada" class="btn btnnegociacao badge badge-primary" style="cursor: pointer;">Copiar ID Neg</span>';
  91.  
  92. if (negs[j].innerHTML.indexOf(teste) == -1){
  93. negs[j].insertAdjacentHTML('beforeEnd', teste);
  94. }
  95.  
  96. document.getElementById("btnCopiarNeg" + idNeg).addEventListener (
  97. "click", testeNegCopy, false
  98. );
  99. }
  100. }
  101.  
  102. function testeNegCopy (teste) {
  103. var $combo = document.getElementById("selNegociacao" + teste.target.id.replace('btnCopiarNeg',''));
  104.  
  105. GM_setClipboard($combo.value);
  106. toastr.success('ID Negociação copiado para a Área de Transferência');
  107. }
  108.  
  109. /*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
  110. that detects and handles AJAXed content.
  111. Usage example:
  112. waitForKeyElements (
  113. "div.comments"
  114. , commentCallbackFunction
  115. );
  116. //--- Page-specific function to do what we want when the node is found.
  117. function commentCallbackFunction (jNode) {
  118. jNode.text ("This comment changed by waitForKeyElements().");
  119. }
  120. IMPORTANT: This function requires your script to have loaded jQuery.
  121. */
  122. function waitForKeyElements (selectorTxt, actionFunction, bWaitOnce, iframeSelector) {
  123. var targetNodes, btargetsFound;
  124.  
  125. if (typeof iframeSelector == "undefined") {
  126. targetNodes = $(selectorTxt);
  127. }
  128. else {
  129. targetNodes = $(iframeSelector).contents().find(selectorTxt);
  130. }
  131.  
  132. if (targetNodes && targetNodes.length > 0) {
  133. btargetsFound = true;
  134. /*--- Found target node(s). Go through each and act if they
  135. are new.
  136. */
  137. targetNodes.each ( function () {
  138. var jThis = $(this);
  139. var alreadyFound = jThis.data ('alreadyFound') || false;
  140.  
  141. if (!alreadyFound) {
  142. //--- Call the payload function.
  143. var cancelFound = actionFunction (jThis);
  144. if (cancelFound)
  145. btargetsFound = false;
  146. else
  147. jThis.data ('alreadyFound', true);
  148. }
  149. } );
  150. }
  151. else {
  152. btargetsFound = false;
  153. }
  154.  
  155. //--- Get the timer-control variable for this selector.
  156. var controlObj = waitForKeyElements.controlObj || {};
  157. var controlKey = selectorTxt.replace (/[^\w]/g, "_");
  158. var timeControl = controlObj [controlKey];
  159.  
  160. //--- Now set or clear the timer as appropriate.
  161. if (btargetsFound && bWaitOnce && timeControl) {
  162. //--- The only condition where we need to clear the timer.
  163. clearInterval (timeControl);
  164. delete controlObj [controlKey]
  165. }
  166. else {
  167. //--- Set a timer, if needed.
  168. if ( ! timeControl) {
  169. timeControl = setInterval ( function () {
  170. waitForKeyElements ( selectorTxt,
  171. actionFunction,
  172. bWaitOnce,
  173. iframeSelector
  174. );
  175. },
  176. 300
  177. );
  178. controlObj [controlKey] = timeControl;
  179. }
  180. }
  181. waitForKeyElements.controlObj = controlObj;
  182. }