Browse Source

added more gitea sites, improved sigil

master
sose 5 months ago
parent
commit
27a5930854
  1. 112
      sigils/codeberg.org
  2. 112
      sigils/git.tannercollin.com
  3. 29
      sigils/tildegit.org

112
sigils/codeberg.org

@ -0,0 +1,112 @@
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())
}

112
sigils/git.tannercollin.com

@ -0,0 +1,112 @@
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())
}

29
sigils/tildegit.org

@ -1,9 +1,8 @@
var data = ""
var repo_nodes = document.getElementsByClassName("page-content repository file list")
var repo_node = document.querySelector("div.repository.file.list")
if (repo_nodes.length !== 0) {
var repo_node = repo_nodes[0]
if (repo_node) {
var repo_title = repo_node.getElementsByClassName("repo-title")[0].innerText
repo_title = repo_title.replaceAll("\n", " ")
repo_title = "# " + repo_title
@ -27,19 +26,13 @@ if (repo_nodes.length !== 0) {
data += "\n" + repo_stats + "\n"
var latest_commit_info = repo_node
.getElementsByClassName("commit-list")
if (latest_commit_info.length !== 0) {
latest_commit_info = latest_commit_info[0]
.innerText
.replaceAll("\t", "")
.trim()
data += "\nLatest commit:\n" + latest_commit_info + "\n"
}
var code_view = document.querySelector("div.file-view.code-view")
if (code_view) {
var code_lines = code_view.querySelectorAll("td.lines-code")
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
@ -70,8 +63,12 @@ if (repo_nodes.length !== 0) {
if (repo_files_table) {
repo_files_table = repo_files_table.getElementsByTagName("tr")
data += "\n## Files\n\n"
for (let i = 2; i < repo_files_table.length; i++) {
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")

Loading…
Cancel
Save