-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscordLineNumbers.user.js
38 lines (35 loc) · 1.53 KB
/
DiscordLineNumbers.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// ==UserScript==
// @name DiscordLineNumbers
// @namespace https://files.noodlebox.moe/
// @downloadURL https://files.noodlebox.moe/userscripts/DiscordLineNumbers.user.js
// @version 1.1.1
// @description Add line numbers to code blocks
// @author noodlebox
// @require https://code.jquery.com/jquery-3.1.1.min.js
// @match *://*.discordapp.com/channels/*
// @match *://*.discordapp.com/invite/*
// @match *://*.discordapp.com/login
// @run-at document-idle
// @grant none
// ==/UserScript==
(function ($) {
"use strict";
// Helper function for finding all elements matching selector affected by a mutation
function mutationFind(mutation, selector) {
var target = $(mutation.target), addedNodes = $(mutation.addedNodes);
var mutated = target.add(addedNodes).filter(selector);
var descendants = addedNodes.find(selector);
var ancestors = target.parents(selector);
return mutated.add(descendants).add(ancestors);
}
// Watch for new code blocks
new MutationObserver(function (mutations, observer) {
mutations.forEach(function (mutation) {
mutationFind(mutation, ".hljs").not(":has(ol)")
.each(function () {
this.innerHTML = this.innerHTML.split("\n").map(line => "<li>"+line+"</li>").join("");
})
.wrapInner($("<ol>").addClass("kawaii-linenumbers"));
});
}).observe(document, { childList:true, subtree:true });
})(jQuery.noConflict(true));