Skip to content

Commit d8d133e

Browse files
committed
Collapse-in-comment: Extract syntax type from className
And update assets
1 parent 24d6e71 commit d8d133e

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

github-collapse-in-comment.user.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name GitHub Collapse In Comment
3-
// @version 1.0.12
3+
// @version 1.0.13
44
// @description A userscript that adds a header that can toggle long code and quote blocks in comments
55
// @license MIT
66
// @author Rob Garrison
@@ -12,8 +12,8 @@
1212
// @grant GM_getValue
1313
// @grant GM_setValue
1414
// @grant GM_registerMenuCommand
15-
// @require https://greasyfork.org/scripts/28721-mutations/code/mutations.js?version=198500
16-
// @icon https://github.com/fluidicon.png
15+
// @require https://greasyfork.org/scripts/28721-mutations/code/mutations.js?version=234970
16+
// @icon https://assets-cdn.github.com/pinned-octocat.svg
1717
// @updateURL https://raw.githubusercontent.com/Mottie/GitHub-userscripts/master/github-collapse-in-comment.user.js
1818
// @downloadURL https://raw.githubusercontent.com/Mottie/GitHub-userscripts/master/github-collapse-in-comment.user.js
1919
// ==/UserScript==
@@ -29,6 +29,8 @@
2929
// hide code/quotes longer than this number of lines
3030
let minLines = GM_getValue("gcic-max-lines", 10),
3131
startCollapsed = GM_getValue("gcic-start-collapsed", true);
32+
// extract syntax type from class name
33+
const regex = /highlight(?:-[^\s]+)+/;
3234

3335
// syntax highlight class name lookup table
3436
const syntaxClass = {
@@ -85,10 +87,13 @@
8587
highlight-source-fortran-modern
8688
highlight-text-tex
8789
*/
88-
let n = (name || "").replace(
89-
/(highlight[-\s]|(source-)|(text-)|(html-)|(markdown-)|(-modern))/g, ""
90-
);
91-
n = (syntaxClass[n] || n).toUpperCase().trim();
90+
let n = (name || "").match(regex);
91+
if (n && n[0]) {
92+
n = n[0].replace(
93+
/(highlight[-\s]|(source-)|(text-)|(html-)|(markdown-)|(-modern))/g, ""
94+
);
95+
n = (syntaxClass[n] || n).toUpperCase().trim();
96+
}
9297
return `${n || "Block"} (${lines} lines)`;
9398
}
9499

0 commit comments

Comments
 (0)