// ==UserScript== // @name GitHub Issue Add Details // @version 1.0.12 // @description A userscript that adds a button to insert a details block into comments // @license MIT // @author Rob Garrison // @namespace https://github.com/Mottie // @match https://github.com/* // @run-at document-idle // @grant none // @require https://greasyfork.org/scripts/28721-mutations/code/mutations.js?version=1108163 // @require https://greasyfork.org/scripts/398877-utils-js/code/utilsjs.js?version=1079637 // @require https://greasyfork.org/scripts/28239-rangy-inputs-mod-js/code/rangy-inputs-modjs.js?version=181769 // @icon https://github.githubassets.com/pinned-octocat.svg // @updateURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-issue-add-details.user.js // @downloadURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-issue-add-details.user.js // @supportURL https://github.com/Mottie/GitHub-userscripts/issues // ==/UserScript== /* global $ $$ on make */ (() => { "use strict"; const icon = ` `, detailsBlock = [ // start details block "
\nTitle\n\n\n", // selected content/caret will be placed here "\n
\n" ]; // Add insert details button const addDetailsButton = () => { const button = make({ el: "button", className: "ghad-details btn-link toolbar-item btn-octicon no-underline tooltipped tooltipped-n", attrs: { "aria-label": "Add a details/summary block", tabindex: "-1", type: "button" }, html: icon }); $$(".toolbar-commenting").forEach(el => { if (el && !$(".ghad-details", el)) { const btn = $("md-quote", el); btn.before(button.cloneNode(true)); } }); }; const addBindings = () => { window.rangyInput.init(); on($("body"), "click", event => { const { target } = event; if (target?.classList.contains("ghad-details")) { event.preventDefault(); const form = target.closest(".previewable-comment-form"); const textarea = $(".comment-form-textarea", form); setTimeout(() => { textarea.focus(); window.rangyInput.surroundSelectedText( textarea, detailsBlock[0], // prefix detailsBlock[1] // suffix ); }, 100); return false; } }); }; on(document, "ghmo:container, ghmo:comments", addDetailsButton); addDetailsButton(); addBindings(); })();