-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcode-blocks-grabber.js
More file actions
32 lines (26 loc) · 901 Bytes
/
Copy pathcode-blocks-grabber.js
File metadata and controls
32 lines (26 loc) · 901 Bytes
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
// Script for grabbing code blocks
// http://unicode.org/charts/index.html#scripts
const texts = document.querySelectorAll('td p');
const options = [];
let isStarted = false;
texts.forEach(item => {
const links = item.querySelectorAll('a');
const space = item.classList.contains('sb') || item.classList.contains('pb')
? '• '
: '';
const groupPrefix = isStarted
? `</optgroup>`
: '';
if (item.classList.contains('sg')
|| (item.classList.contains('mb') && links.length === 0)) {
options.push(`${groupPrefix}<optgroup label="${item.innerText}">`)
isStarted = true;
}
if (links.length > 0)
links.forEach(link => {
if(link.title)
options.push(`<option value="${link.title.replace('-', '..')}">${space}${link.innerText}</option>`)
})
})
options.push('</optgroup>');
console.log(options.join('\n'))