My Merge Requests Gitlab

Show Link to opened Merge Requests, auto click swipe on MR with pics

目前為 2019-05-03 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// https://github.com/hannsen/userscripts
// @name         My Merge Requests Gitlab
// @namespace    http://tampermonkey.net/
// @version      2.3
// @description  Show Link to opened Merge Requests, auto click swipe on MR with pics
// @author       hannsen
// @match        https://git04.quodata.de/*
// @require      https://code.jquery.com/jquery-3.1.1.min.js
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
(function() {
    'use strict';

    //    var swipe = 0;
    //    function scrollFunction() {
    //        if(!swipe)
    //            swipe = $('li.swipe');
    //
    //        for(var i = 0; i < swipe.length; i++){
    //            if(isScrolledIntoView(swipe[i])){
    //                swipe[i].click();
    //                return;
    //            }
    //        }
    //    }
    //
    //    function isScrolledIntoView(elem) {
    //        var docViewTop = $(window).scrollTop();
    //        var docViewBottom = docViewTop + $(window).height();
    //        var elemTop = $(elem).offset().top;
    //        var elemBottom = elemTop + $(elem).height();
    //        return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
    //    }
    //
    //    
    //

    // Set ur own clone url prefix with GM_setValue("git_url_prefix", "username:token");
    var git_url_prefix = GM_getValue("git_url_prefix");
    var $http_clone = $('input[name="http_project_clone"]');
    if(git_url_prefix && $http_clone.val()){
        var clone_url = $http_clone.val();
        clone_url = clone_url.replace("https://", "https://" + git_url_prefix + "@");
        $http_clone.val(clone_url);
    }

    function colorCollapsed(){
        $("div.diff-collapsed").css('background-color', 'red');
    }

    if(window.location.href.indexOf("merge_requests") > 0){
        window.onscroll = colorCollapsed;
    }


    var last_mr_count = GM_getValue("open_mr_count") || 0;

    var $merge_button = $($(".user-counter:eq( 1 )").prop('outerHTML'));
    var new_href = $merge_button.children().attr('href').replace('assignee_username', 'scope=all&state=opened&author_username');
    $merge_button.children().attr('href', new_href);
    $merge_button.find('span').toggleClass('gitlab-own-merge-requests merge-requests-count issues-count')
        .removeClass('hidden');
    $merge_button.find('span').html(last_mr_count);
    $($merge_button.prop('outerHTML')).insertBefore(".user-counter:eq( 2 )");

    $.ajax({
            url: new_href,
        })
        .done(function(data) {
            var open_mr_count = $(data).find('a#state-opened > span.badge').html();
            $('.gitlab-own-merge-requests').html(open_mr_count);
            GM_setValue("open_mr_count", open_mr_count);
        });

    // Grey out issues with pending Merge Request
    if(document.location.href.indexOf('dashboard/issues?assignee_username=') !== -1){
        $('li.issue:has(.issuable-mr)').css('opacity', 0.4);
    }

})();