-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload-index.js
39 lines (29 loc) · 1.17 KB
/
load-index.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
39
function fetchIndex(callback) {
let dir_url='http://library.pyramidal-foundational-information.com/books/'
$.get(dir_url, {
crossOrigin : true
}, (data) => {
let html = $.parseHTML($.trim(data))
// Convert back to jquery from parsed array (for multiple transforms)
html = $(html).filter('table')
// Remove table sort links (don't work outside of original document)
$('th a', html).replaceWith( function () { return this.textContent })
// Remove horizontal rule row(s)
$('hr', html).parents('tr').remove()
// Create thead and move header cell rows to it.
let head = $('<thead />').prependTo( html )
$('th', html).parent('tr').appendTo( head )
// Remove empty column
$('td:first-child, th:first-child', html).remove()
// Resolve the relative `mod_autoindex` links to the source `dir_url`.
$('td a', html)
.each( (index, element) => {
element = $(element)
/* Open in new tab */
element.attr('target', '_blank')
let relative = element.attr('href')
element.attr('href', dir_url + '/' + relative)
})
callback( html )
}, 'html')
}