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.
 
 
 
 

4.1 KiB

var data = "" var repo_node = document.querySelector("div.repository.file.list")

if (repo_node) { var repo_title = repo_node.getElementsByClassName("repo-title")[0].innerText repo_title = repo_title.replaceAll("\n", " ") repo_title = "# " + repo_title

data += repo_title + "\n"

var fork_flag = repo_node.getElementsByClassName("fork-flag") if (fork_flag.length !== 0) { fork_flag = fork_flag[0] .innerText .replaceAll("\n", "")

data += fork_flag + "\n" }

var repo_stats = repo_node .getElementsByClassName("ui two horizontal center link list")[0] .innerText .replaceAll("\n", " |") .trim()

data += "\n" + repo_stats + "\n"

var code_view = document.querySelector("div.file-view.code-view") if (code_view) { var code_lines = code_view.querySelectorAll("td[rel]") if (code_lines.length = 0) { var code_lines = code_view.querySelectorAll("li[rel]") }

var file_name = document.querySelector("span.ui.breadcrumb.repo-path") var buttons = document.querySelectorAll("a.ui.mini.basic.button") var raw_link buttons.forEach((button) > { if (button.innerText == "Raw") { raw_link = window.electron.abs_href(button.getAttribute("href")) } }) if (file_name) { file_name = file_name.innerText } data += "\n## " + file_name + "\n\n"

if (raw_link) { data += "=> " + raw_link + " Raw\n\n" } var padding data += "```\n" code_lines.forEach((code_line) => { let line_num = code_line.getAttribute("rel").replace(^., "") let line_data = code_line.innerText.replace("\n", "") let padding = String(code_lines.length).length - String(line_num.length) data += line_num + " ".repeat(padding) + "| " + line_data + "\n" }) data += "\n```\n" }

var repo_files_table = document .getElementById("repo-files-table")

if (repo_files_table) { repo_files_table = repo_files_table.getElementsByTagName("tr") for (let i = 0; i < repo_files_table.length; i++) { if (i = 0) { data += "\nLatest commit: \n" } else if (i = 1) { data += "\n\n## Files\n" } let table_element = repo_files_table[i] let file_info = table_element.innerText.trim().replace(\t.*$, "") let file_link = table_element.querySelector("a") if (file_link) { file_link = window.electron.abs_href(file_link.getAttribute("href")) }

data += "=> " + file_link + " " + file_info + "\n" } }

var readme_nodes = repo_node .getElementsByClassName("file-view markdown markdown") if (readme_nodes.length !== 0) { readme_nodes = readme_nodes[0].children data += "\n———-\n"

for (let i = 0; i < readme_nodes.length; i++) { let readme_node = readme_nodes[i] let tag_name = readme_node.tagName if (tag_name.startsWith("H") && tag_name.length = 2) { let header_lvl = tag_name[1] data += "\n" + "#".repeat(header_lvl) + " " + readme_node.innerText } else if (tag_name = "P") { data += readme_node.innerText } else if (tag_name = "UL") { let list_items = readme_node.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" + readme_node.innerText + "```\n" } data += "\n" } } window.electron.send_gemtext(data) } else { window.electron.send_gemtext(window.electron.default_sigil()) }