Improve Zendesk

Ajoute une balise style à la page

当前为 2024-08-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Improve Zendesk
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Ajoute une balise style à la page
  6. // @author Morgan
  7. // @match *://djmdigital.zendesk.com/*
  8. // @grant GM_addStyle
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var customCSS = `
  16. .sc-1oduqug-0.jdCBDY {
  17. margin-top: 30px;
  18. }
  19.  
  20. button.sc-n5wku7-0.htHdVo.StyledButton-sc-qe3ace-0.iTTOJs, .play-next button, button.sc-137q24h-0.fBxYYr.StyledButton-sc-qe3ace-0.iHPrzf,button.sc-isqijc-0.bCgRtB.StyledButton-sc-qe3ace-0.cBBpso {
  21. padding: 5px 60px;
  22. background-color: limegreen;
  23. font-size: large;
  24. color:black
  25. }
  26.  
  27. iframe#web-messenger-container {
  28. display: none;
  29. }
  30.  
  31. .app_view.app-1019154.apps_ticket_sidebar iframe {
  32. height: 80vh!important;
  33. }
  34.  
  35.  
  36. /* Task link */
  37. a.djm-task-link {
  38. padding: 0px 102px;
  39. background-color: limegreen;
  40. font-size: large;
  41. color: black;
  42. border: 1px solid transparent;
  43. border-radius: 4px;
  44. cursor: pointer;
  45. position:relative;
  46. }
  47.  
  48. `;
  49.  
  50. GM_addStyle(customCSS);
  51.  
  52. setTimeout(function() {
  53. customFunction()
  54. }, 500); // SetTimeout avec un délai de 1 seconde
  55. function customFunction(message) {
  56. setTimeout(function() {
  57. // Ajoutez vos appels de fonction ici
  58. checkUrlAndRunScriptInitializeInputLinks()
  59. checkUrlAndRunScriptTransformUrlsToLinks()
  60. }, 500); // SetTimeout avec un délai de 1 seconde
  61. }
  62.  
  63. // Écoute les changements de chemin causés par des actions de navigation
  64. window.addEventListener('popstate', function() {
  65. customFunction('Chemin changé: ' + window.location.pathname);
  66. });
  67.  
  68. // Fonction pour surcharger history.pushState et history.replaceState
  69. function overrideHistoryMethod(methodName) {
  70. var originalMethod = history[methodName];
  71. history[methodName] = function(state) {
  72. if (typeof history['on' + methodName] == "function") {
  73. history['on' + methodName]({state: state});
  74. }
  75. customFunction('Chemin changé par ' + methodName + ': ' + window.location.pathname);
  76. return originalMethod.apply(history, arguments);
  77. };
  78. }
  79.  
  80. // Surcharge history.pushState et history.replaceState
  81. overrideHistoryMethod('pushState');
  82. overrideHistoryMethod('replaceState');
  83.  
  84. // Déclenche les événements personnalisés après surcharge
  85. window.history.onpushstate = function(e) {
  86. window.dispatchEvent(new CustomEvent('pushstate', e));
  87. };
  88. window.history.onreplacestate = function(e) {
  89. window.dispatchEvent(new CustomEvent('replacestate', e));
  90. };
  91.  
  92. // Sélectionner tous les éléments 'thead'
  93. var theads = document.querySelectorAll('thead');
  94. // Ajouter un event listener sur chaque 'thead'
  95. theads.forEach(function(thead) {
  96. thead.addEventListener('click', function(event) {
  97. // Code à exécuter lorsque l'événement 'click' est déclenché sur un 'thead'
  98. customFunction('Un thead a été cliqué' + event.target)
  99.  
  100. });
  101. });
  102.  
  103.  
  104.  
  105.  
  106.  
  107. function transformUrlsToLinks() {
  108.  
  109. const cells = document.querySelectorAll('.hKkHGP');
  110. const urlRegex = /(https?:\/\/[^\s]+)/g;
  111.  
  112. if (cells.length > 0) {
  113.  
  114.  
  115. cells.forEach((cell, index) => {
  116. const textContent = cell.textContent;
  117.  
  118. if (urlRegex.test(textContent)) {
  119. const link = document.createElement('a');
  120. link.setAttribute('href', textContent.match(urlRegex)[0]);
  121. link.textContent = textContent.match(urlRegex)[0];
  122. cell.textContent = '';
  123. cell.appendChild(link);
  124. }
  125. });
  126. }
  127. }
  128.  
  129.  
  130. // Fonction pour vérifier l'URL et exécuter le script si nécessaire
  131. function checkUrlAndRunScriptTransformUrlsToLinks() {
  132. if (window.location.pathname.startsWith('/agent/filters/')) {
  133. transformUrlsToLinks()
  134. }
  135. }
  136.  
  137.  
  138.  
  139. // Fonction qui initialise les liens des inputs
  140. function initializeInputLinks() {
  141. var inputElements = document.querySelectorAll('.custom_field_14504424601628 input');
  142.  
  143. inputElements.forEach(function(inputElement) {
  144. // Supprime les anciens liens s'ils existent
  145. var existingLink = inputElement.parentNode.parentNode.querySelector('.djm-task-link');
  146. if (existingLink) {
  147. existingLink.remove();
  148. }
  149.  
  150. // Crée un nouvel élément <a> pour chaque input
  151. var linkElement = document.createElement('a');
  152. // linkElement.setAttribute('target', '_blank');
  153. linkElement.textContent = 'Tâche';
  154. linkElement.style.display = 'none'; // Cache initialement l'élément de lien
  155. linkElement.classList.add('djm-task-link');
  156. inputElement.parentNode.parentNode.insertBefore(linkElement, inputElement.nextSibling);
  157.  
  158. // Vérifie la valeur de l'input et met à jour le lien dès la création
  159. checkForUrl(inputElement, linkElement);
  160.  
  161. // Ajoute un écouteur d'événements sur chaque input pour détecter les changements de valeur
  162. inputElement.addEventListener('input', function() {
  163. console.log('Événement input détecté.');
  164. checkForUrl(inputElement, linkElement);
  165. });
  166. });
  167. }
  168.  
  169. // Fonction qui vérifie si la valeur de l'input contient une URL et met à jour le lien
  170. function checkForUrl(inputElement, linkElement) {
  171. if (inputElement.value.match(/(https?:\/\/[^\s]+)/g)) {
  172. linkElement.href = inputElement.value;
  173. linkElement.style.display = 'inline';
  174. } else {
  175. linkElement.style.display = 'none';
  176. }
  177. }
  178. // Fonction pour vérifier l'URL et exécuter le script si nécessaire
  179. function checkUrlAndRunScriptInitializeInputLinks() {
  180. if (window.location.pathname.startsWith('/agent/tickets/')) {
  181. initializeInputLinks();
  182. }
  183. }
  184.  
  185.  
  186. })();