GitLab - Default Add Comment

Makes "Add comment now" the default action in GitLab and remove the Start a Review

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         GitLab - Default Add Comment
// @namespace    https://github.com/yourname
// @version      1.0
// @description  Makes "Add comment now" the default action in GitLab and remove the Start a Review
// @author       Squiter
// @match        https://gitlab.com/*
// @icon         https://gitlab.com/favicon.ico
// @license      MIT
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  // ---------- CONFIG ----------
  const START_REVIEW_SELECTOR = '[data-testid="start-review-button"]';
  const COMMENT_NOW_SELECTOR  = '[data-testid="comment-now-button"]';
  const TEXTAREA_SELECTOR     = 'textarea[data-testid="reply-field"]';

  // ---------- HELPERS ----------

  function hideStartReview() {
    document.querySelectorAll(START_REVIEW_SELECTOR).forEach(btn => {
      btn.style.display = 'none';
    });
  }

  function getCommentButton() {
    return document.querySelector(COMMENT_NOW_SELECTOR);
  }

  function shouldSubmit(e) {
    // Enter = submit
    // Shift+Enter = newline (keep normal behavior)
    return e.key === "Enter" && !e.shiftKey;
  }

  function attachEnterHandler(textarea) {
    if (textarea.dataset.enterHandlerAttached) return;
    textarea.dataset.enterHandlerAttached = "true";

    textarea.addEventListener("keydown", (e) => {
      if (!shouldSubmit(e)) return;

      const btn = getCommentButton();
      if (!btn || btn.disabled) return;

      e.preventDefault();
      e.stopPropagation();

      btn.click();
    });
  }

  function init() {
    hideStartReview();

    document.querySelectorAll(TEXTAREA_SELECTOR)
      .forEach(attachEnterHandler);
  }

  // ---------- OBSERVER ----------
  // GitLab rerenders often (Vue), so we watch DOM changes

  const observer = new MutationObserver(() => {
    init();
  });

  observer.observe(document.body, {
    childList: true,
    subtree: true
  });

  // initial run
  init();
})();