Skip to content

Instantly share code, notes, and snippets.

@livibetter
Last active May 1, 2016 01:03
Show Gist options
  • Save livibetter/083a2401817815d6fe94 to your computer and use it in GitHub Desktop.
Save livibetter/083a2401817815d6fe94 to your computer and use it in GitHub Desktop.
GitHub Hide Some Repos (userscript)

GitHub Hide Some Repos

This is a Greasemonkey user script for my personal usage since some settings are hard-coded in the code.

  • Some languages that I don't code
  • Repositories named dotfiles
  • Search results
  • User profile's Repositories tab

This script has been placed in public domain, or via UNLICENSE, if not applicable.

// ==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();
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment