// ==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) {
// Находим элемент
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');
}
});
})();