Files
2023-01-21 18:42:34 -10:00

32 lines
3.3 KiB
Cheetah

<script>
if (document.location.href.match('https://gitea.nicholaspease.com/(?:(?!user|notifications|explore).)+/(.*)')) {
page_url = document.location.href.split("/")
username = page_url[3]
reponame = page_url[4]
svg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" viewBox="0 0 184 184" width="16" height="16" class="mr-2" style="enable-background:new 0 0 184 184;" xml:space="preserve"> <g> <path style="fill: var(--color-fg-default, #fff)" d="M177.2,48.4c-0.8-1.9-2.9-2.7-4.8-2c-1.3,0.5-2.2,1.8-2.2,3.2c0,0.4,0.1,0.9,0.2,1.3 c16.3,43.3-5.7,91.6-49,107.9c-6,2.2-12.2,3.8-18.5,4.6v-39.1c2.5-0.5,4.9-1.1,7.3-1.9v32.9c41.3-10.1,66.7-51.7,56.6-93 c-5.1-20.9-18.7-38.8-37.6-49.2c-1.8-1-4-0.3-4.9,1.4c0,0-0.1,0.1-0.1,0.1c-0.2,0.5-0.4,1.1-0.4,1.6c0,1.3,0.7,2.5,1.9,3.2 c33.7,18.7,45.9,61.1,27.2,94.8c-7.8,14.2-20.4,25.2-35.4,31.1v-29.1c4.6-1.4,7.8-5.7,7.9-10.6c0-4-2-7.6-5.5-9.6 c2.6-25.1,14.1-18.5,14.1-26.5v-4.7c0-12-27.8-51.1-40.8-52c-0.4,0-0.8,0-1.2,0s-0.8,0-1.2,0c-13,0.9-40.8,40-40.8,52.1v4.6 c0,8,11.4,1.4,14.1,26.5c-3.4,2-5.5,5.7-5.5,9.6c0,4.9,3.2,9.1,7.9,10.6v29.1C30.7,131.2,13,90.8,27.2,54.9 c5.9-15.1,16.9-27.6,31.1-35.5c1.8-1,2.4-3.2,1.4-5c-0.6-1.2-1.9-1.9-3.2-1.9c-0.6,0-1.2,0.2-1.7,0.5C17.5,33.6,4,80.5,24.6,117.7 c10.4,18.9,28.3,32.5,49.2,37.6v-32.9c2.4,0.8,4.8,1.5,7.3,1.9v39.1c-45.9-6.1-78.1-48.2-72-94.1c0.8-6.3,2.4-12.5,4.6-18.4 c0.7-1.8-0.2-3.9-2-4.6c-0.4-0.2-0.9-0.3-1.4-0.3c-1.5,0-2.9,0.9-3.4,2.4C-10.9,95.5,12.9,148,60,165.7c9.1,3.4,18.6,5.3,28.3,5.7 v-46.1c1.3,0.1,3.7,0.1,3.7,0.1s2.4,0,3.7-0.1v46.1c50.2-2.1,89.3-44.5,87.2-94.7C182.5,67,180.6,57.5,177.2,48.4L177.2,48.4z M108.8,100.3c2.9-2.9,7.7-2.9,10.6,0c2.9,2.9,2.9,7.7,0,10.6c-2.9,2.9-7.7,2.9-10.6,0c-1.4-1.4-2.2-3.3-2.2-5.3 C106.6,103.6,107.4,101.7,108.8,100.3L108.8,100.3z M75.2,110.9c-2.9,2.9-7.7,2.9-10.6,0s-2.9-7.7,0-10.6c2.9-2.9,7.7-2.9,10.6,0 c1.4,1.4,2.2,3.3,2.2,5.3C77.4,107.6,76.6,109.5,75.2,110.9z"/> </g> </svg>'
xhr1 = new XMLHttpRequest
xhr1.open("GET","https://gitea.nicholaspease.com/api/v1/repos/" + username + "/" + reponame + "/commits")
xhr1.onreadystatechange = function () {
if (xhr1.readyState === 4) {
data = JSON.parse(xhr1.response)
totalcommits = Object.keys(data).length
console.log(totalcommits)
xhr = new XMLHttpRequest
xhr.open("GET", " https://gitea.nicholaspease.com/api/v1/repos/" + username + "/" + reponame + "/commits?page=" + totalcommits + "&limit=1")
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
data = JSON.parse(xhr.response)
sha = data[0].sha
console.log(sha, username, reponame)
url = 'gitkraken://repolink/'+sha+"?url="+document.location.href+".git"
injection_string = '<a class="item js-clone-url-vsc" href="'+url+'" id="_aria_auto_id_22" role="menuitem" tabindex="-1">'+svg+'Open with GitKraken</a>'
document.querySelector("#_aria_auto_id_18").innerHTML = document.querySelector("#_aria_auto_id_18").innerHTML + injection_string
}
}
xhr.send()
}
}
xhr1.send()
}
</script>