// ==UserScript== // @name Git:Replace-Default-Create-Gitlab-MD-Text // @namespace http://tampermonkey.net/ // @version 2024-09-12 // @description Скрипт, который модифицирует инструкцию по созданию нового репозитория на странице: добавляет к URL суффикс `.git`, настраивает имя и email пользователя, а также изменяет команды в блоке
 для корректного создания и пуша нового репозитория.
// @author       You
// @match        https://gitlabserver.skynet.kz/*
// @icon         https://about.gitlab.com/nuxt-images/ico/favicon.ico
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.addEventListener('load', function() {
        // Поиск нужного элемента
        const emptyWrapper = document.querySelector(".git-empty.js-git-empty");
        if (emptyWrapper) {
            const createNew = Array.from(emptyWrapper.querySelectorAll('h5'))
                                   .find(h5 => h5.textContent.includes("Create a new repository"));
            if (createNew) {
                // Модификация URL
                const currentURL = window.location.href;
                const newURL = currentURL.endsWith('/') ? currentURL.slice(0, -1) + '.git' : currentURL + '.git';

                // Замена содержимого первого элемента 
                const pres = emptyWrapper.querySelectorAll('pre');
                if (pres.length > 0) {
                    // Находим элемент 
  • с классом "current-user" const currentUserElement = document.querySelector('li.current-user'); // Инициализируем переменные let vCurrentUser, vCurrentName; // Проверяем, найден ли элемент if (currentUserElement) { // Получаем элемент внутри
  • const userLink = currentUserElement.querySelector('a[data-user]'); // Проверяем, найден ли элемент if (userLink) { // Извлекаем username и добавляем домен vCurrentUser = userLink.getAttribute('data-user') + '@skynet.kz'; // Извлекаем полное имя пользователя vCurrentName = userLink.querySelector('.gl-font-weight-bold').textContent.trim(); } } // Заменяем текст первого элемента
                        pres[0].innerHTML = `cd ${newURL.split('/').pop().replace('.git', '')}
    git init
    git config --global user.name "${vCurrentName}"
    git config --global user.email "${vCurrentUser}"
    git checkout -b master
    git add .
    git commit -m "first commit"
    git remote add origin ${newURL}
    git push -u origin master
    
    `; console.log('Updated pre element'); } console.log('Script executed'); } else { console.log('Create new repository section not found'); } console.log('Empty wrapper found'); } else { console.log('Empty wrapper not found'); } }); })();