Gitlab Show Only UnResolved Threads

This script hide commits and resolved threads, no longer scrolling into infinite when reviewing.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Gitlab Show Only UnResolved Threads
// @version      0.2.0
// @description  This script hide commits and resolved threads, no longer scrolling into infinite when reviewing.
// @author       Mujtaba Aldebes
// @license      MIT
// @namespace    https://github.com/SerkZex/
// @icon         https://about.gitlab.com/ico/favicon-192x192.png
// @include      /^https?:\/\/[^/]*gitlab.[^/]+\//
// @require      https://code.jquery.com/jquery-3.5.0.js
// ==/UserScript==
/* globals $ */


const State = Object.freeze({
  HIDDEN: 'HIDE_RESOLVED',
  VISIBLE: 'SHOW_RESOLVED',
});

const ButtonText = Object.freeze({
  [State.HIDDEN]: 'Show all threads',
  [State.VISIBLE]: 'Show only unresolved threads',
});

let current_state = State.VISIBLE;


// This function add a button to the gitlab interface and bind it to an action.
function show_gitlab_button() {
  var zNode = document.createElement ('div');
  zNode.innerHTML = '<button id="show_unresolved_discussions_btn" type="button" class="btn btn-default ml-sm-2">' +ButtonText[current_state]+ '</button>';
  zNode.setAttribute ('id', 'threads_visibility_container');
  zNode.setAttribute ('class', 'line-resolve-all-container full-width-mobile');
  $('.d-flex.flex-wrap.align-items-center.justify-content-lg-end').append(zNode);

  $("#show_unresolved_discussions_btn").bind( "click", function() {
    switch (current_state) {
      case State.VISIBLE:
        current_state = State.HIDDEN;
        // Hides threads in "overview" -tab
        $("#notes-list li:contains(Resolved)").hide()
        $('.timeline-entry.note.system-note.note-wrapper').hide();

        // hides threads in "changes"-tab
        $("#diffs > div.files.d-flex > div.diff-files-holder > div:not(:has(button[data-qa-selector='resolve_discussion_button']))").hide()
        var unresolved_threads = $("#diffs > div.files.d-flex > div.diff-files-holder > div:has(button[data-qa-selector='resolve_discussion_button'])").length
        if(unresolved_threads == 0){
          $("#NoUnResolvedThreadsCss").show()
        } else {
          $("#NoUnResolvedThreadsCss").hide()
        }
        break;
      case State.HIDDEN:
        current_state = State.VISIBLE;
        $("#notes-list li").each(function(){$(this).show()}) // Shows threads in "overview""-tap
        $("#diffs > div.files.d-flex > div.diff-files-holder > div").show() // Shows threads in "changes"-tap
        $("#NoUnResolvedThreadsCss").hide()
        break;
    }
    $('#show_unresolved_discussions_btn').html(ButtonText[current_state]);
  });
};


/* Code Start Here! */
setTimeout(function() {
  const commit_versio = $("span.mr-version-dropdown > a > span").text();
  $("#diffs > div.files.d-flex").prepend(`<div id="NoUnResolvedThreadsCss" style="width: 100%; display: none;"><p style="text-align:center; font-size:200%">There is no unresolved threads in this commit (${commit_versio})</p></div>`)
  show_gitlab_button();
}, 3200)