Skip to content

Commit 5b7e18f

Browse files
committed
Issue-add-details: Update selector
1 parent 072aa68 commit 5b7e18f

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

github-issue-add-details.user.js

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name GitHub Issue Add Details
3-
// @version 1.0.10
3+
// @version 1.0.11
44
// @description A userscript that adds a button to insert a details block into comments
55
// @license MIT
66
// @author Rob Garrison
@@ -9,12 +9,14 @@
99
// @run-at document-idle
1010
// @grant none
1111
// @require https://greasyfork.org/scripts/28721-mutations/code/mutations.js?version=952601
12+
// @require https://greasyfork.org/scripts/398877-utils-js/code/utilsjs.js?version=952600
1213
// @require https://greasyfork.org/scripts/28239-rangy-inputs-mod-js/code/rangy-inputs-modjs.js?version=181769
1314
// @icon https://github.githubassets.com/pinned-octocat.svg
1415
// @updateURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-issue-add-details.user.js
1516
// @downloadURL https://raw.githubusercontent.com/Mottie/Github-userscripts/master/github-issue-add-details.user.js
1617
// @supportURL https://github.com/Mottie/GitHub-userscripts/issues
1718
// ==/UserScript==
19+
/* global $ $$ on make */
1820
(() => {
1921
"use strict";
2022

@@ -31,45 +33,48 @@
3133
];
3234

3335
// Add insert details button
34-
function addDetailsButton() {
35-
const button = document.createElement("button");
36-
button.type = "button";
37-
button.className = "ghad-details toolbar-item tooltipped tooltipped-n";
38-
button.setAttribute("aria-label", "Add a details/summary block");
39-
button.setAttribute("tabindex", "-1");
40-
button.innerHTML = icon;
41-
[...document.querySelectorAll(".toolbar-commenting")].forEach(el => {
36+
const addDetailsButton = () => {
37+
const button = make({
38+
el: "button",
39+
className: "ghad-details btn-link toolbar-item btn-octicon no-underline tooltipped tooltipped-n",
40+
attrs: {
41+
"aria-label": "Add a details/summary block",
42+
tabindex: "-1",
43+
type: "button"
44+
},
45+
html: icon
46+
});
47+
$$(".toolbar-commenting").forEach(el => {
4248
if (el && !$(".ghad-details", el)) {
43-
const btn = $("[aria-label*='Add a task list']", el);
49+
const btn = $("md-quote", el);
4450
btn.before(button.cloneNode(true));
4551
}
4652
});
47-
}
53+
};
4854

49-
function addBindings() {
55+
const addBindings = () => {
5056
window.rangyInput.init();
51-
$("body").addEventListener("click", event => {
52-
const target = event.target;
53-
if (target && target.classList.contains("ghad-details")) {
54-
let textarea = target.closest(".previewable-comment-form");
55-
textarea = $(".comment-form-textarea", textarea);
56-
textarea.focus();
57-
window.rangyInput.surroundSelectedText(
58-
textarea,
59-
detailsBlock[0], // prefix
60-
detailsBlock[1] // suffix
61-
);
57+
on($("body"), "click", event => {
58+
const { target } = event;
59+
if (target?.classList.contains("ghad-details")) {
60+
event.preventDefault();
61+
const form = target.closest(".previewable-comment-form");
62+
const textarea = $(".comment-form-textarea", form);
63+
setTimeout(() => {
64+
textarea.focus();
65+
window.rangyInput.surroundSelectedText(
66+
textarea,
67+
detailsBlock[0], // prefix
68+
detailsBlock[1] // suffix
69+
);
70+
}, 100);
6271
return false;
6372
}
6473
});
65-
}
66-
67-
function $(str, el) {
68-
return (el || document).querySelector(str);
69-
}
74+
};
7075

71-
document.addEventListener("ghmo:container", addDetailsButton);
72-
document.addEventListener("ghmo:comments", addDetailsButton);
76+
on(document, "ghmo:container", addDetailsButton);
77+
on(document, "ghmo:comments", addDetailsButton);
7378

7479
addDetailsButton();
7580
addBindings();

0 commit comments

Comments
 (0)