├── .gitignore ├── lang-icon ├── c.png ├── cpp.png ├── dart.png ├── java.png ├── js.png ├── php.png ├── ruby.png ├── rust.png ├── ts.png ├── csharp.png ├── golang.png ├── kotlin.png ├── python.png ├── shell.png └── swift.png ├── snapshot ├── 1-1.png └── 1-2-1.png ├── README.md ├── filter-by-topic.user.js ├── LICENSE └── index.user.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /lang-icon/c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/c.png -------------------------------------------------------------------------------- /lang-icon/cpp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/cpp.png -------------------------------------------------------------------------------- /lang-icon/dart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/dart.png -------------------------------------------------------------------------------- /lang-icon/java.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/java.png -------------------------------------------------------------------------------- /lang-icon/js.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/js.png -------------------------------------------------------------------------------- /lang-icon/php.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/php.png -------------------------------------------------------------------------------- /lang-icon/ruby.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/ruby.png -------------------------------------------------------------------------------- /lang-icon/rust.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/rust.png -------------------------------------------------------------------------------- /lang-icon/ts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/ts.png -------------------------------------------------------------------------------- /snapshot/1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/snapshot/1-1.png -------------------------------------------------------------------------------- /snapshot/1-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/snapshot/1-2-1.png -------------------------------------------------------------------------------- /lang-icon/csharp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/csharp.png -------------------------------------------------------------------------------- /lang-icon/golang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/golang.png -------------------------------------------------------------------------------- /lang-icon/kotlin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/kotlin.png -------------------------------------------------------------------------------- /lang-icon/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/python.png -------------------------------------------------------------------------------- /lang-icon/shell.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/shell.png -------------------------------------------------------------------------------- /lang-icon/swift.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foamzou/group-by-repo-on-github/HEAD/lang-icon/swift.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # group-by-repo-on-github 2 | This is the script of tampermonkey. Before using it, please make sure you have installed 3 | 4 | When you search code using github, this script can help you group by repo 5 | 6 | ## Install 7 | Click the link to install 8 | 9 | ## Feature 10 | * The script will create a button in the page, will group by repo for the search result when you click the button 11 | 12 | * The new page like the follow snapshot 13 | * Merged Pages: When the search results are paged, the page will be automatically fetched and updated to the current page in real time. If you do not want to continue loading new content, you can click the abort button at any time to terminate the fetch 14 | * List All Repo: The helper block shows all repo and info, such as stars,language 15 | 16 | 17 | ## Thanks 18 | 19 | -------------------------------------------------------------------------------- /filter-by-topic.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Filter by topic 3 | // @namespace https://github.com/foamzou/group-by-repo-on-github/filter-by-topic 4 | // @version 0.1 5 | // @description Add the topic options to filter repp 6 | // @author foamzou 7 | // @match https://github.com/orgs/AfterShip/repositories* 8 | // @grant none 9 | // ==/UserScript== 10 | const TopicList = ["All", "mocha", "maotai", "yorsh"]; // cannot remove the first `All` 11 | 12 | const debug = false; 13 | const l = m => { 14 | debug && console.log(m); 15 | } 16 | const sleep = ms => new Promise(r => setTimeout(r, ms)); 17 | 18 | const TopicOptionBtnId = 'topic-options'; 19 | 20 | // global var 21 | let lastQueryStr = getQuery().queryStr; 22 | let backupHtml = ''; 23 | 24 | async function detectQueryChanged() { 25 | let retryCount = 0; 26 | while (true) { 27 | let q = getQuery(); 28 | if (q.queryStr !== lastQueryStr) { 29 | lastQueryStr = q.queryStr; 30 | return true; 31 | } 32 | if (retryCount > 500) { 33 | return false; 34 | } 35 | retryCount++; 36 | await sleep(20); 37 | } 38 | } 39 | 40 | async function tryInit() { 41 | l('try init') 42 | if (await detectQueryChanged()) { 43 | init(); 44 | } else { 45 | l('no changed'); 46 | } 47 | } 48 | 49 | document.addEventListener('change', async function() { 50 | l('trigger by event listener change') 51 | tryInit(); 52 | }); 53 | 54 | (function(history){ 55 | const pushState = history.pushState; 56 | history.pushState = function(state) { 57 | if (typeof history.onpushstate == "function") { 58 | history.onpushstate({state: state}); 59 | } 60 | const ret = pushState.apply(history, arguments); 61 | l('trigger by history push') 62 | tryInit(); 63 | return ret; 64 | } 65 | })(window.history); 66 | 67 | (function() { 68 | 'use strict'; 69 | init(true); 70 | })(); 71 | 72 | // Firefox和Chrome早期版本中带有前缀 73 | 74 | 75 | var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver 76 | // 选择目标节点 77 | var target = document.getElementById('org-repositories')//document.querySelector('#some-id'); 78 | // 创建观察者对象 79 | var observer = new MutationObserver(function(mutations) { 80 | mutations.forEach(function(mutation) { 81 | l('dom changed') 82 | if (!document.getElementById('topic_All').checked && backupHtml != "" && document.getElementById('org-repositories').innerHTML != backupHtml) { 83 | l('IN 列表中子元素被修改'); 84 | document.getElementById('org-repositories').innerHTML = backupHtml 85 | } 86 | }); 87 | }); 88 | // 配置观察选项: 89 | var config = { attributes: true, childList: true, characterData: true } 90 | // 传入目标节点和观察选项 91 | observer.observe(target, config); 92 | 93 | 94 | async function init(isFirst = false) { 95 | l('start init'); 96 | const q = getQuery(); 97 | if (q.topic && isFirst) { 98 | l('loading') 99 | document.getElementsByClassName('org-repos repo-list')[0].innerHTML = "Loading...." 100 | } 101 | createOrUpdateTopicOption(); 102 | listRepo(q) 103 | } 104 | 105 | async function listRepo(q) { 106 | let sort = ''; 107 | let kw = ''; 108 | let lang = ''; 109 | let page = ''; 110 | if (!q.topic) { 111 | l('no need load repo') 112 | return; 113 | } 114 | 115 | if (q.keyword) { 116 | kw = `${q.keyword}%3A` 117 | } 118 | if (q.lang) { 119 | lang = `&l=${q.lang}` 120 | } 121 | if (q.page) { 122 | page = `&p=${q.page}` 123 | } 124 | if (q.sort == "") { 125 | sort = '&o=desc&s=updated' 126 | } else if (q.sort == "name") { 127 | sort = '&s=' 128 | } else { 129 | sort = '&o=desc&s=stars' 130 | } 131 | const url = `https://github.com/search?q=${kw}org%3A${q.org}+topic%3A${q.topic}&type=Repositories${lang}${sort}${page}`; 132 | 133 | l(url) 134 | 135 | const repoHtmlRes = await fetch(url); 136 | const repoHtmlStr = await repoHtmlRes.text(); 137 | const repoHtmlGroup = repoHtmlStr.match(/