An extensible, general purpose http->gemini mirror with full javascript support, live at gemini://illegaldrugs.net/cgi-bin/hellgate
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

104 lines
4.1 KiB

var data = ""
header = document.querySelector("h2")
if (header) {
data += "# " + header.innerText + "\n\n"
var nav_links = document.querySelectorAll("li.nav-item > a.nav-link")
if (nav_links) {
var valid_links = ["summary", "tree", "source"]
nav_links.forEach((nav_link) => {
if (valid_links.includes(nav_link.innerText)){
let href = nav_link.getAttribute("href")
if (href[0] === "/") {
data += "=> "
+ window.electron.abs_href(href)
+ " "
+ nav_link.innerText
+ "\n"
} else {
data += "=> ?"
+ href
+ " "
+ nav_link.innerText
+ "\n"
}
}
})
}
var code_view = document.querySelector("div.col-md-12.code-view > div.highlight > pre")
if (code_view) {
var header = document.querySelector("div.header-extension").innerText.split(" ")[0]
data += "\n## " + header + "\n\n```\n" + code_view.innerText + "```\n"
}
var tree_list = document.querySelector("div.tree-list")
if (tree_list) {
var header = document.querySelector("div.header-extension").innerText.split(" ")[0]
data += "\n## " + header + "\n\n"
var tree_items = tree_list.children
for (let tree_item of tree_items) {
if (tree_item.className.includes("name")) {
let item_link = tree_item.querySelector("a").getAttribute("href")
data += "=> " + window.electron.abs_href(item_link) + " " + tree_item.innerText + " "
} else if (tree_item.className.includes("size")) {
if (tree_item.innerText !== "") {
data += "(" + tree_item.innerText + ")" + "\n"
} else {
data += "\n"
}
}
}
}
var latest_events = document.querySelectorAll("div.event-list > div.event")
if (latest_events.length !== 0) {
data += "\n## Latest events:\n\n----\n"
latest_events.forEach((event_el) => {
data += event_el.innerText + "\n----\n"
})
}
var clone_links = document.querySelector("div.col-md-8 > dl")
if (clone_links) {
data += "\n## Clone:\n"
data += clone_links.innerText + "\n"
}
var readme_node = document.querySelector("div#readme")
var readme_selector = "div#readme"
if (! readme_node) { readme_node = document.querySelector("div.readme") } // don't ask me ask drew
if (readme_node) {
var markdown_node = readme_node.querySelector("div.markdown")
data += "\n----------\n"
if (markdown_node) {
var readme_elements = markdown_node.children
for (let i = 0; i < readme_elements.length; i++) {
let element = readme_elements[i]
let tag_name = element.tagName
if (tag_name.startsWith("H") && tag_name.length === 2) {
let header_lvl = tag_name[1]
data += "\n"
+ "#".repeat(header_lvl)
+ " "
+ element.innerText.replace("\n", "").replaceAll("#", "")
} else if (tag_name === "P") {
data += element.innerText
} else if (tag_name === "UL") {
let list_items = element.children
for (let j = 0; j < list_items.length ; j++) {
list_item = list_items[j]
data += "\n* " + list_item.innerText.replaceAll("\n", "\n\t - ")
}
} else if (tag_name === "PRE") {
data += "```\n" + element.innerText + "```\n"
}
data += "\n"
}
} else {
data += readme_node.innerText + "\n"
}
}
window.electron.send_gemtext(data)
} else {
window.electron.send_gemtext(window.electron.default_sigil())
}