Redmine: Add notes directly at the bottom

Make it easy to add notes without the need to click a button.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το 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         Redmine: Add notes directly at the bottom
// @namespace    im.outv.redmine.addnotes.redmine
// @version      2024.1
// @description  Make it easy to add notes without the need to click a button.
// @author       Outvi V
// @license      MIT
// @match        https://www.redmine.org/issues/*
// @grant        none
// ==/UserScript==

const HIDE_CLASS_NAME = 'addnotes-hide'

function addCss(css) {
  var block = document.createElement('style')
  block.innerText = css
  document.head.appendChild(block)
  return block
}

function isToShow(fieldset) {
    // As of Redmine 6.0.2
    if (['add_notes', 'add_attachments'].includes(fieldset.id)) {
        return true;
    }

    // redmine.org
    if (["Notes", "Files"].includes(fieldset.querySelector("legend")?.innerText)) {
        fieldset.classList.remove("addnotes-hide")
        return true;
    }

    return false;
}

;(function () {
  'use strict'

  const hiddenCss = addCss(`
    .${HIDE_CLASS_NAME} { display: none; }
    `)

  const dUpdate = document.querySelector('#update')
  dUpdate.style = ''

  const dEditAreas = [...dUpdate.querySelectorAll('form div.box > fieldset')]

  for (const fieldset of dEditAreas) {
    if (!isToShow(fieldset)) {
      fieldset.classList.add(HIDE_CLASS_NAME)
    }
  }

  const _showAndScrollTo = window.showAndScrollTo
  window.showAndScrollTo = function (id, focus, ...args) {
    if (id === 'update' && focus === 'issue_notes') {
      hiddenCss.innerText = ''
    }
    _showAndScrollTo(id, focus, ...args)
  }
})()