|
// ==UserScript== |
|
// @name GitHub Hide Some Repos |
|
// @namespace http://localhost/github-hide-some-repos |
|
// @include https://github.com/search?* |
|
// @include https://github.com/*?tab=* |
|
// @include /https:\/\/github\.com\/[-_a-z0-9]+$/ |
|
// @version 0.1.2 |
|
// @grant none |
|
// ==/UserScript== |
|
// License Public Domain, or via UNLICENSE, if not applicable |
|
// Gist https://gist.github.com/livibetter/083a2401817815d6fe94 |
|
|
|
let SHOW_LANGS = 'Awk, C, C++, Go, Haskell, Lua, Perl, Perl6, Python, Shell, VimL, '; |
|
let HIDE_COMMS_LANGS = 'C#, CSharp, HTML, Java, JavaScript'; |
|
let HIDE_COMMS_FRMTS = 'AsciiDoc, HTML'; |
|
let HIDE_COMMS_SOFTS = '.NET, bitbox, Django, Docker, Drupal, GNOME, (Löve|L[oö]ve2D), (My)?SQL, Node.js, SDL, Sublime, XFCE\d?'; |
|
let HIDE_COMMS_HARDS = 'Arduino, LED, Raspberry(Pi)?'; |
|
let HIDE_COMMS_MISCS = 'ConsoleApplication\\d+'; |
|
let HIDE_COMMS = 'Heroku, Hearthstone, Twitter' + ',' + |
|
HIDE_COMMS_FRMTS + ',' + |
|
HIDE_COMMS_LANGS + ',' + |
|
HIDE_COMMS_SOFTS + ',' + |
|
HIDE_COMMS_HARDS + ',' + |
|
HIDE_COMMS_MISCS; |
|
// HIDE_NAMES and HIDE_DESCS will be converted into regular expression, |
|
// for word boundry and ignored cases. |
|
let HIDE_NAMES = 'dotfiles' + ', ' + HIDE_COMMS; |
|
let HIDE_DESCS = HIDE_COMMS; |
|
|
|
let SHOW_LANGS = SHOW_LANGS.split(',').map(String.trim); |
|
let HIDE_NAMES = HIDE_NAMES.split(',').map(String.trim); |
|
let HIDE_DESCS = HIDE_DESCS.split(',').map(String.trim); |
|
|
|
let RF_DEBUG_MORE = false; |
|
|
|
function __make_regexp(list) |
|
{ |
|
return [ |
|
for (c of list) |
|
new RegExp( |
|
(/^\W/.test(c) ? '' : '\\b') + |
|
c + |
|
(/\W$/.test(c) ? '' : '\\b'), |
|
'i' |
|
) |
|
]; |
|
} |
|
|
|
HIDE_NAMES = __make_regexp(HIDE_NAMES); |
|
HIDE_DESCS = __make_regexp(HIDE_DESCS); |
|
|
|
function __ghsr_check(item) |
|
{ |
|
let name = item.querySelector('h3 > a').text.trim(); |
|
// profile page |
|
let lang = item.querySelector('.repo-list-stats > span[itemprop="programmingLanguage"]'); |
|
if (!lang) |
|
{ |
|
// search results |
|
lang = item.querySelector('.repo-list-stats').childNodes[0]; |
|
} |
|
lang = lang.textContent.trim(); |
|
|
|
if (name.indexOf('/') != -1) |
|
{ |
|
name = name.split('/')[1]; |
|
} |
|
|
|
if (SHOW_LANGS.indexOf(lang) == -1) |
|
{ |
|
item.style.display = 'none'; |
|
console.debug('hide %s (%s)', name, lang); |
|
return; |
|
} |
|
|
|
for (let hname of HIDE_NAMES) |
|
{ |
|
if (!hname.test(name)) |
|
{ |
|
continue; |
|
} |
|
item.style.display = 'none'; |
|
console.debug('hide %s %s', name, hname); |
|
return; |
|
} |
|
|
|
let desc = item.querySelector('p.repo-list-description'); |
|
if (!desc) |
|
{ |
|
return; |
|
} |
|
desc = desc.textContent.trim(); |
|
|
|
for (let hdesc of HIDE_DESCS) |
|
{ |
|
if (!hdesc.test(desc)) |
|
{ |
|
continue; |
|
} |
|
item.style.display = 'none'; |
|
console.debug('hide %s: %s %s', name, desc, hdesc); |
|
return; |
|
} |
|
} |
|
|
|
function __ghsr_hide_repos() |
|
{ |
|
console.debug('__ghsr_hide_repos called'); |
|
|
|
Array.from(document.querySelectorAll('.repo-list-item:not([style*="display"])')).forEach(__ghsr_check); |
|
} |
|
|
|
function __ghsr_callback(items) |
|
{ |
|
console.debug('__ghsr_callback called'); |
|
|
|
for (let item of items) |
|
{ |
|
let t = item.target; |
|
if (RF_DEBUG_MORE) |
|
{ |
|
if (t.tagName != 'TIME' |
|
&& t.className != 'participation-graph') |
|
{ |
|
console.debug(item.type, t, t.id) |
|
} |
|
} |
|
|
|
switch (item.type) |
|
{ |
|
case 'attributes': // Profile repositories |
|
__ghsr_hide_repos(); |
|
break; |
|
case 'childList': |
|
// Search result |
|
if (t.id == 'js-pjax-container') |
|
{ |
|
console.debug('calling __ghsr_hide_repos'); |
|
__ghsr_hide_repos(); |
|
} |
|
break; |
|
} |
|
} |
|
} |
|
|
|
function ghsr() |
|
{ |
|
console.debug('ghsr called'); |
|
|
|
__ghsr_hide_repos(); |
|
|
|
new MutationObserver(__ghsr_callback).observe( |
|
document.querySelector('#js-pjax-container'), |
|
{ |
|
attributeFilter: ['style'], |
|
attributes: true, |
|
childList: true, |
|
subtree: true |
|
} |
|
); |
|
} |
|
|
|
ghsr(); |