From 30de2412c2020517064c292d69ddd9320549de01 Mon Sep 17 00:00:00 2001 From: Puck Meerburg Date: Fri, 15 Mar 2024 23:03:22 +0000 Subject: [PATCH] meow2 --- script.js | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 script.js diff --git a/script.js b/script.js new file mode 100644 index 0000000..9b30c5c --- /dev/null +++ b/script.js @@ -0,0 +1,78 @@ +(async () => { + const data = await (await fetch('https://git.lix.systems/puck/testfudgethingy/raw/branch/main/database.json')).json(); + + document.querySelector('.code-view').addEventListener('click', (e) => { + let clicky = e.target; + let isLine = false; + if (clicky.classList.contains('code-inner')) { + isLine = true; + } else if (!clicky.parentNode.classList.contains('code-inner')) { + return; + } + + // TODO: non-ASCII support + + let index = 0; + if (isLine) { // mehhhh + index = ((e.clientX - clicky.getBoundingClientRect().x) / clicky.getBoundingClientRect().width) * clicky.textContent.length; + } else { + for (let node of Array.from(clicky.parentNode.children)) { + if (node !== clicky) { + index += node.textContent.length; + } else { + break; + } + } + + index += ((e.clientX - clicky.getBoundingClientRect().x) / clicky.getBoundingClientRect().width) * clicky.textContent.length; + } + + index = Math.floor(index); + + let line = parseInt((isLine ? clicky : clicky.parentNode).parentNode.attributes.rel.nodeValue.substring(1), 10); + let file = window.config.pageData.branchDropdownDataList[0].treePath; + + console.log(`clicked line ${line} char ${index}`); + + let symbol; + + for (let doc of data.documents) { + if (doc.relativePath !== file) { + continue; + } + + console.log('found document'); + + for (let occurrence of doc.occurrences) { + let startLine = occurrence.range[0] + 1; + let startChar = occurrence.range[1]; + let endLine = (occurrence.range.length === 3 ? occurrence.range[0] : occurrence.range[2]) + 1; + let endChar = occurrence.range.length === 3 ? occurrence.range[2] : occurrence.range[3]; + + if (startLine > line || endLine < line) + continue; + + if (startChar > index || endChar < index) + continue; + + symbol = occurrence.symbol; + } + } + + if (!symbol) return; + + for (let doc of data.documents) { + for (let occurrence of doc.occurrences) { + if ((occurrence.symbolRoles & 1) !== 1) + continue; + + if (occurrence.symbol !== symbol) + continue; + + let data = window.config.pageData.branchDropdownDataList[0]; + + window.location = `${data.repoLink}/src/${data.branchNameSubURL}/${doc.relativePath}#L${occurrence.range[0] + 1}`; + } + } + }, { capture: true }); +})();