From f281219b17c6085a77d7ee3060a675a517e2c2e3 Mon Sep 17 00:00:00 2001 From: szialajoscosplay <70654182+k3rielit@users.noreply.github.com> Date: Sat, 6 Aug 2022 02:25:57 +0200 Subject: [PATCH] added github --- github/README.md | 13 +++++++++++ github/lists.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 github/README.md create mode 100644 github/lists.js diff --git a/github/README.md b/github/README.md new file mode 100644 index 0000000..d2cf1cd --- /dev/null +++ b/github/README.md @@ -0,0 +1,13 @@ +# GitHub +### How to use: +- Copy the [entire script](https://github.com/k3rielit/scripts/raw/main/github/lists.js) +- Go to any [GitHub](https://github.com) page +- Paste it into the console +- Change the `uid` (first line) to a GitHub account name +- Press `Enter` +### How to search if a list includes an item ([idea](https://github.com/orgs/community/discussions/28515)) +- Run the script as written above +- Run the `isItemOnList(item, list)` command in the console + - Case sensitive, expects the list's id (for ex. `asd-asd`, not `asD/* ASD`) + - `item` works with the URL and the title too +- If it's on the list, it returns `true`, otherwise `false` \ No newline at end of file diff --git a/github/lists.js b/github/lists.js new file mode 100644 index 0000000..31760d3 --- /dev/null +++ b/github/lists.js @@ -0,0 +1,60 @@ +const uid = 'k3rielit'; +let starred = []; +let lists = {}; +let listCount = 0; +if (!Array.prototype.last){ + Array.prototype.last = function(){ + return this[this.length - 1]; + }; +}; + +getStarredRepos(`https://github.com/${uid}?tab=stars`); +function getStarredRepos(url) { + fetch(url).then(raw => raw.text()).then(data => { + const page = new DOMParser().parseFromString(data, 'text/html'); + starred = starred.concat([...page.querySelectorAll('#user-starred-repos > div > div > div > div.d-inline-block.mb-1 > h3 > a')].map(m => m.href)); + const nextPage = page.querySelector("#user-starred-repos > div > div > div.paginate-container > div > :nth-child(2)"); + if(nextPage && nextPage.href) getStarredRepos(nextPage.href); + else { + [...page.querySelectorAll("#profile-lists-container > * a")].map(m => m.href).forEach(e => { + lists[e.split('/').last()] = []; + getReposFromList(e); + }); + if(Object.keys(lists).length==0) finalize(); + } + }); +} + +function getReposFromList(url) { + fetch(url).then(raw => raw.text()).then(data => { + const page = new DOMParser().parseFromString(data, 'text/html'); + [...page.querySelectorAll("#user-list-repositories > div > div.d-inline-block.mb-1 > h3 > a")].map(m => m.href).forEach(item => { + lists[url.split('/').last()].push(item); + starred.splice(starred.indexOf(item),1); + }); + listCount++; + if(listCount==Object.keys(lists).length) finalize(); + }); +} + +function finalize() { + const container = document.querySelector("body > div.application-main"); + container.style.textAlign = 'center'; + let content = ''; + for (const key in lists) { + content += `

${key} (${lists[key].length})

`; + for (let i = 0; i < lists[key].length; i += 5) { + content += `${lists[key].slice(i, i + 5).map(m => ``).join()}`; + } + content += '
${m.split('/').last()}

'; + } + content += `

unlisted (${starred.length})

`; + for (let i = 0; i < starred.length; i += 5) { + content += `${starred.slice(i, i + 5).map(m => ``).join(' '.repeat(5))}`; + } + container.innerHTML = content+'
${m.split('/').last()}
'; +} + +function isItemOnList(item, list) { + return lists[list].filter(f => f==item || f==item.split('/').last()).length>0; +} \ No newline at end of file