js-tampermonkey-public-scripts/Git_Replace-Default-Create-Gitlab-MD-Text.user.js
Unkas Amanjolov 42b29defae first commit
2024-10-07 10:25:50 +05:00

68 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==UserScript==
// @name Git:Replace-Default-Create-Gitlab-MD-Text
// @namespace http://tampermonkey.net/
// @version 2024-09-12
// @description Скрипт, который модифицирует инструкцию по созданию нового репозитория на странице: добавляет к URL суффикс `.git`, настраивает имя и email пользователя, а также изменяет команды в блоке <pre> для корректного создания и пуша нового репозитория.
// @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';
// Замена содержимого первого элемента <pre>
const pres = emptyWrapper.querySelectorAll('pre');
if (pres.length > 0) {
// Находим элемент <li> с классом "current-user"
const currentUserElement = document.querySelector('li.current-user');
// Инициализируем переменные
let vCurrentUser, vCurrentName;
// Проверяем, найден ли элемент
if (currentUserElement) {
// Получаем элемент <a> внутри <li>
const userLink = currentUserElement.querySelector('a[data-user]');
// Проверяем, найден ли элемент <a>
if (userLink) {
// Извлекаем username и добавляем домен
vCurrentUser = userLink.getAttribute('data-user') + '@skynet.kz';
// Извлекаем полное имя пользователя
vCurrentName = userLink.querySelector('.gl-font-weight-bold').textContent.trim();
}
}
// Заменяем текст первого элемента <pre>
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
</pre>`;
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');
}
});
})();