Greasy Fork is available in English.

解析gitlab 日志

解析内容并以表格形式展示在弹出框中

Från och med 2023-09-20. Se den senaste versionen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         解析gitlab 日志
// @version      1.0
// @description  解析内容并以表格形式展示在弹出框中
// @author       mibo
// @include         *://*gitlab*
// @exclude         *://*commit*
// @grant        GM_getValue
// @grant        GM_setValue
// @license    GPL-3.0-only
// @icon    https://ae01.alicdn.com/kf/Hac1a58055c5047cdb91349e91aa208d5k.jpg
// @namespace 12345git
// @home-url   https://
// @homepageURL  https://

// ==/UserScript==
// 获取当前开关状态,默认为关闭


(function() {
    'use strict';
        var currentURL = window.location.href;

    // 检查URL是否包含"commit"
    if (currentURL.indexOf('commit') === -1) {

    } else {
        console.log("URL中包含'commit',不执行脚本。");
        return
    }

    var  jsonData='';
    // 添加外部 JavaScript 依赖
    var externalJsScript = document.createElement('script');
    externalJsScript.src = 'https://cdn.staticfile.org/layui/2.8.17/layui.js'; // 外部 JavaScript 文件的 URL
    externalJsScript.type = 'text/javascript';
    document.head.appendChild(externalJsScript);

    // 添加外部 CSS 依赖
    var externalCssLink = document.createElement('link');
    externalCssLink.href = 'https://cdn.staticfile.org/layui/2.8.17/css/layui.css'; // 外部 CSS 文件的 URL
    externalCssLink.rel = 'stylesheet';
    document.head.appendChild(externalCssLink);


    var isEnabled = GM_getValue('isEnabled', false);

    // 创建一个开关按钮
    var toggleButton = document.createElement('button');
    toggleButton.innerHTML = isEnabled ? '日志已开启' : '日志已关闭';

    // 添加按钮到页面
    document.body.appendChild(toggleButton);
    toggleButton.style.position = 'fixed';
    toggleButton.style.bottom = '20px'; // 距离底部的距离
    toggleButton.style.right = '20px'; // 距离右边的距离
    toggleButton.style.zIndex = '9999'; // 确保按钮位于页面上其他元素之上

    // 添加按钮的点击事件
    toggleButton.addEventListener('click', function () {
        isEnabled = !isEnabled; // 切换开关状态
        toggleButton.innerHTML = isEnabled ? '日志已开启' : '日志已关闭';
        GM_setValue('isEnabled', isEnabled); // 保存开关状态
    });

    // 如果开关是开启状态,执行你的脚本
    if (isEnabled==false) {
        // 在这里编写你的脚本代码
        // 例如:
        // document.querySelector('body').style.backgroundColor = 'yellow';
        return
    }



    // 替换下面的JSON数据为您提供的数据
    var element = document.getElementById('project_id');
    var elementrepository_ref = document.getElementById('repository_ref').value;

    // 获取元素的原始值
    var originalValue = element.value;

    var protocolAndDomain = window.location.protocol + "//" + window.location.hostname;

    fetch(protocolAndDomain+'/api/v4/projects/'+originalValue+'/repository/commits?ref_name='+elementrepository_ref+'&per_page=150',{ method: 'GET', async: false })
        .then(response => {
        // 检查响应状态码
        if (!response.ok) {
            throw new Error('网络请求错误');
        }
        // 将响应解析为JSON
        return response.json();
    })
        .then(data => {
        // 将JSON数据赋值给jsonData变量

        console.log(data);
        jsonData = data

        function createPopup(jsonData) {
            // 创建表头
            var bf = '<table class="layui-table">  <colgroup>    <col width="70%">    <col width="15%">   <col width="15%">    <col>  </colgroup>';
            var end = '  </tbody></table>';
            var header = '<thead><tr>  <th>日志 ->'+elementrepository_ref+'</th> <th>作者</th> <th>提交时间</th>  </tr></thead>  <tbody>';

            // 创建表格内容

            var rows='';
            for (var i = 0; i < jsonData.length; i++) {
                rows += '<tr>'+'<td><a href="'+jsonData[i].web_url+'" style="color: #1e9fff" >' + jsonData[i].message + '</a></td>' +'<td>' + jsonData[i].author_name + '</td>' +'<td>' + jsonData[i].committed_date.substring(0, 10) + '</td>'+'</tr>';
            };
            var layer = layui.layer;
            var util = layui.util;
            var $ = layui.$;
            layer.open({
                type: 1,
                offset: 'r',
                anim: 'slideLeft', // 从右往左
                area: ['50%', '100%'],
                shade: 0.1,
                shadeClose: true,
                id: 'ID-demo-layer-direction-r',
                content: bf+header+rows+end,
            });
        }

        // 调用函数创建弹出框
        createPopup(jsonData);

    })
        .catch(error => {
        console.error('发生错误:', error);
    });



})();