Bitrix24 Better <code>

Native Bitrix24 CODE tag is broken and doesnt have hightlighting at all, so it is very hard to share sources in tasks. This script is fixing this issue.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Bitrix24 Better <code>
// @namespace    https://crm.globaldrive.ru/
// @version      2024-02-22-2
// @description  Native Bitrix24 CODE tag is broken and doesnt have hightlighting at all, so it is very hard to share sources in tasks. This script is fixing this issue.
// @author       Dzorogh
// @match        https://crm.globaldrive.ru/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    const addScript = (src) => {
        const e = document.createElement('script');
        e.src = src;
        document.head.appendChild(e);
        return e;
    }

    const addStyle = (src) => {
        const e = document.createElement('link');
        e.rel = "stylesheet";
        e.href = src;
        document.head.appendChild(e);
        return e;
    }

    const css = `
          .forum-code {
            border-radius: 0;
          }
          .forum-code td {
             padding: 0;
           }
        `;

    const languages = [
        'html',
        '1c',
        'apache',
        'bash',
        'css',
        'diff',
        'ini',
        'java',
        'javascript',
        'json',
        'less',
        'markdown',
        'nginx',
        'php',
        'scss',
        'sql',
        'typescript',
        'xml',
        'yaml',
    ];


    (function Init() {
        const selectors = document.querySelectorAll('.forum-code pre');
        for (let selector of selectors) {
            // wrap code in real <code> tag to make work highlightAll
            selector.innerHTML = `<code>${selector.innerHTML}</code>`;
        }

        const mainStyle = addStyle('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css');
        const mainScript = addScript('https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js');

        mainScript.onload = () => {
            languages.forEach((language) => {
                addScript(`https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/${language}.min.js`);
            })

            hljs.highlightAll();

            GM_addStyle(css);
        }
    })()


})();