TGithub

Adds some features on github.com & gitlab.com to integrate it with tecnativa.com

21.06.2023 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name           TGithub
// @author         Alexandre Díaz, Carlos Roca
// @version        1.16
// @grant          none
// @run-at         document-idle
// @namespace      tecnativa
// @icon           https://www.tecnativa.com/web/image/website/1/favicon/
// @include        /^https?:\/\/(?:www\.)?github\.com\/?.*$/
// @include        /^https?:\/\/(?:www\.)?gitlab\.tecnativa\.com\/?.*$/
// @description    Adds some features on github.com & gitlab.com to integrate it with tecnativa.com
// ==/UserScript==

(function (window) {
    "use strict";

    var TGithub = {
        ODOO_SERVER: 'https://www.tecnativa.com',
        COMPANY_NAME: 'Tecnativa',

        REGEX_TEMPLATES: {},

        init: function () {
            this._addRegexTemplate('TT', new RegExp(/\bTT(\d+)/gi), `<a target='_blank' href='${this.ODOO_SERVER}/web#id=$1&model=project.task&view_type=form'>${this.COMPANY_NAME}-Task #$1</a>`);

            this._replaceTask();
            if (this._isLocationHost('github')) {
                this._ghAddNavbarOptions();
            }
        },

        /* CORE FUNCTIONS */
        _isLocationHost: function (host) {
            return document.location.host.toLowerCase().includes(host);
        },
        _addRegexTemplate: function (templateName, regex, html) {
            this.REGEX_TEMPLATES[templateName] = { regex: regex, html: html };
        },
        _executeRegexReplace: function (templateName, text) {
            if (templateName in this.REGEX_TEMPLATES && text.match(this.REGEX_TEMPLATES[templateName].regex)) {
                return text.replace(this.REGEX_TEMPLATES[templateName].regex, this.REGEX_TEMPLATES[templateName].html);
            }
            return false;
        },

        /* COMMON FUNCTIONS */
        _replaceTask: function () {
            const searchAndParse = () => {
                document.querySelectorAll('.comment-body,.note-text,.description,.commit-description').forEach((elm) => {
                    const htmlTemplate = this._executeRegexReplace('TT', elm.innerHTML);
                    if (htmlTemplate) {
                        elm.innerHTML = htmlTemplate;
                    }
                });
            };
            // Mutation Observer
            if (typeof this.observer === 'undefined') {
                let targetNode = undefined;
                if (this._isLocationHost('github')) {
                    targetNode = document.getElementsByTagName('main')[0];
                } else if (this._isLocationHost('gitlab')) {
                    targetNode = document.getElementById('notes-list');
                }
                if (typeof targetNode !== 'undefined') {
                    this.observer = new MutationObserver(searchAndParse);
                    this.observer.observe(targetNode, { childList: true, subtree: true });
                }
            }
            searchAndParse();
        },

        /* GITHUB FUNCTIONS */
        _ghAddNavbarOptions: function () {
            var targetNode = document.querySelector('.AppHeader-globalBar-end') || document.getElementsByTagName('nav')[0];
            if (targetNode) {
                const exampleItem = targetNode.querySelector("a[href^='/pulls']");
                const menuItem = document.createElement("A");
                menuItem.className = exampleItem.className;
                menuItem.style.cssText = exampleItem.style.cssText
                menuItem.textContent = this.COMPANY_NAME;
                menuItem.href = `/pulls?q=is%3Aopen+is%3Apr+archived%3Afalse+involves%3A${this.COMPANY_NAME}`;
                targetNode.insertAdjacentElement('afterbegin', menuItem);
            }
        },
    };

    TGithub.init();

})(window)