Skip to content

Instantly share code, notes, and snippets.

@jaszhix
Last active September 30, 2019 03:57
Show Gist options
  • Save jaszhix/ad9b3970b98feb9527213e3900e36c09 to your computer and use it in GitHub Desktop.
Save jaszhix/ad9b3970b98feb9527213e3900e36c09 to your computer and use it in GitHub Desktop.
Purge Linux Mint from Github
// ==UserScript==
// @name Github Tweaks
// @description
// @namespace github
// @version 1.0.0
// @include http*://*github.com/*
// @run-at document-start
// @grant unsafeWindow
// ==/UserScript==
(function() {
'use strict';
const window = unsafeWindow;
const containerNames = ['news', 'container', 'list-style-none', 'wrapper', 'your-repos-filter'];
const filtered = ['linuxmint', 'icingtaskmanager', 'cinnamenu', 'icingwindowsaver', 'icingmenu', 'mintsources', 'cinnamon', 'muffin', 'linuxmint/cjs', 'jaszhix/cjs', 'CinnVIIStarkMenu', 'Gnocine', 'cinnode', 'jaszhix/nemo', 'jaszhix/xplayer'];
const getAttr = function(el, attr) {
return el.attributes && el.attributes[attr] && el.attributes[attr].value ? el.attributes[attr].value.trim().toLowerCase() : '';
};
const cleanUp = function() {
let linkFound = false;
let links = Array.prototype.slice.call(document.querySelectorAll('a'))
.concat(Array.prototype.slice.call(document.querySelectorAll('span')));
for (let i = 0, len = links.length; i < len; i++) {
let link = links[i];
let match = false;
for (let i = 0, len = filtered.length; i < len; i++) {
let keyword = filtered[i];
if (link.href && link.href.indexOf(keyword) > -1
|| (getAttr(link, 'data-hovercard-url').indexOf(keyword.toLowerCase()) > -1)) {
match = true;
}
}
if (match) {
let parent = link.parentNode;
let iterations = 0;
let shouldBreak = false;
const remove = () => {
parent.parentNode.removeChild(parent);
shouldBreak = true;
linkFound = true;
}
while (true) {
iterations++;
if (!parent || iterations > 6) break;
if (containerNames.indexOf(getAttr(parent.parentNode, 'data-filterable-for')) > -1) {
remove();
break;
}
for (let z = 0, len = containerNames.length; z < len; z++) {
if (!parent.parentNode || !parent.parentNode.classList) {
shouldBreak = true;
break;
}
let classList = Array.prototype.slice.call(parent.parentNode.classList);
for (let x = 0, len = classList.length; x < len; x++) {
if (classList[x].toLowerCase().indexOf(containerNames[z]) > -1) {
remove();
break;
}
}
if (shouldBreak) break;
}
if (shouldBreak) break;
parent = parent.parentNode;
}
}
}
return linkFound;
};
const handleCleanup = () => !cleanUp() ? setTimeout(cleanUp, 1000) : undefined;
window._fetch = fetch;
window.fetch = function(uri, options, ...args) {
return window._fetch(uri, options, ...args).then((response) => {
handleCleanup();
return response;
}).catch((err) => {
handleCleanup();
throw err;
})
};
handleCleanup();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment