Improve Zendesk

Ajoute une balise style à la page

目前為 2024-08-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Improve Zendesk
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Ajoute une balise style à la page
// @author       Morgan
// @match        *://djmdigital.zendesk.com/*
// @grant        GM_addStyle
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    var customCSS = `
.sc-1oduqug-0.jdCBDY {
    margin-top: 30px;
}

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 {
    padding: 5px 60px;
    background-color: limegreen;
    font-size: large;
    color:black
}

iframe#web-messenger-container {
    display: none;
}

.app_view.app-1019154.apps_ticket_sidebar iframe {
    height: 80vh!important;
}


/* Task link */
a.djm-task-link {
    padding: 0px 102px;
    background-color: limegreen;
    font-size: large;
    color: black;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    position:relative;
}

    `;

    GM_addStyle(customCSS);

    setTimeout(function() {
        customFunction()
    }, 500); // SetTimeout avec un délai de 1 seconde
    function customFunction(message) {
        setTimeout(function() {
            // Ajoutez vos appels de fonction ici
            checkUrlAndRunScriptInitializeInputLinks()
            checkUrlAndRunScriptTransformUrlsToLinks()
        }, 500); // SetTimeout avec un délai de 1 seconde
    }

    // Écoute les changements de chemin causés par des actions de navigation
    window.addEventListener('popstate', function() {
        customFunction('Chemin changé: ' + window.location.pathname);
    });

    // Fonction pour surcharger history.pushState et history.replaceState
    function overrideHistoryMethod(methodName) {
        var originalMethod = history[methodName];
        history[methodName] = function(state) {
            if (typeof history['on' + methodName] == "function") {
                history['on' + methodName]({state: state});
            }
            customFunction('Chemin changé par ' + methodName + ': ' + window.location.pathname);
            return originalMethod.apply(history, arguments);
        };
    }

    // Surcharge history.pushState et history.replaceState
    overrideHistoryMethod('pushState');
    overrideHistoryMethod('replaceState');

    // Déclenche les événements personnalisés après surcharge
    window.history.onpushstate = function(e) {
        window.dispatchEvent(new CustomEvent('pushstate', e));
    };
    window.history.onreplacestate = function(e) {
        window.dispatchEvent(new CustomEvent('replacestate', e));
    };

    // Sélectionner tous les éléments 'thead'
    var theads = document.querySelectorAll('thead');
    // Ajouter un event listener sur chaque 'thead'
    theads.forEach(function(thead) {
        thead.addEventListener('click', function(event) {
            // Code à exécuter lorsque l'événement 'click' est déclenché sur un 'thead'
            customFunction('Un thead a été cliqué' + event.target)

        });
    });





    function transformUrlsToLinks() {

        const cells = document.querySelectorAll('.hKkHGP');
        const urlRegex = /(https?:\/\/[^\s]+)/g;

        if (cells.length > 0) {


            cells.forEach((cell, index) => {
                const textContent = cell.textContent;

                if (urlRegex.test(textContent)) {
                    const link = document.createElement('a');
                    link.setAttribute('href', textContent.match(urlRegex)[0]);
                    link.textContent = textContent.match(urlRegex)[0];
                    cell.textContent = '';
                    cell.appendChild(link);
                }
            });
        }
    }


    // Fonction pour vérifier l'URL et exécuter le script si nécessaire
    function checkUrlAndRunScriptTransformUrlsToLinks() {
        if (window.location.pathname.startsWith('/agent/filters/')) {
            transformUrlsToLinks()
        }
    }



    // Fonction qui initialise les liens des inputs
    function initializeInputLinks() {
        var inputElements = document.querySelectorAll('.custom_field_14504424601628 input');

        inputElements.forEach(function(inputElement) {
            // Supprime les anciens liens s'ils existent
            var existingLink = inputElement.parentNode.parentNode.querySelector('.djm-task-link');
            if (existingLink) {
                existingLink.remove();
            }

            // Crée un nouvel élément <a> pour chaque input
            var linkElement = document.createElement('a');
           // linkElement.setAttribute('target', '_blank');
            linkElement.textContent = 'Tâche';
            linkElement.style.display = 'none'; // Cache initialement l'élément de lien
            linkElement.classList.add('djm-task-link');
            inputElement.parentNode.parentNode.insertBefore(linkElement, inputElement.nextSibling);

            // Vérifie la valeur de l'input et met à jour le lien dès la création
            checkForUrl(inputElement, linkElement);

            // Ajoute un écouteur d'événements sur chaque input pour détecter les changements de valeur
            inputElement.addEventListener('input', function() {
                console.log('Événement input détecté.');
                checkForUrl(inputElement, linkElement);
            });
        });
    }

    // Fonction qui vérifie si la valeur de l'input contient une URL et met à jour le lien
    function checkForUrl(inputElement, linkElement) {
        if (inputElement.value.match(/(https?:\/\/[^\s]+)/g)) {
            linkElement.href = inputElement.value;
            linkElement.style.display = 'inline';
        } else {
            linkElement.style.display = 'none';
        }
    }
    // Fonction pour vérifier l'URL et exécuter le script si nécessaire
    function checkUrlAndRunScriptInitializeInputLinks() {
        if (window.location.pathname.startsWith('/agent/tickets/')) {
            initializeInputLinks();
        }
    }


})();