Mozilla Add-ons Filter

By JoeSimmons Last update Nov 19, 2008 — Installed 4,373 times.

There are 15 previous versions of this script.

// ==UserScript==
// @name           Mozilla Add-ons Filter
// @namespace      http://userscripts.org/users/23652
// @description    Lets you hide add-ons you don't want to see
// @include        https://addons.mozilla.org/*/firefox/browse/*
// @include        https://addons.mozilla.org/*/firefox/search?q=*
// @include        https://addons.mozilla.org/*/firefox/
// @copyright      JoeSimmons
// @version        1.3
// ==/UserScript==

GM_addStyle(".filter {font-size:9pt;color:#000;font-weight:bold;font-family:verdana arial;}");

// XPath but the array returned is a normal array[x]
function $x(p, context) {
  if (!context) context = document;
  var i, arr = [], xpr = document.evaluate(p,context,null,6,null);
  for (i = 0; item = xpr.snapshotItem(i); i++) {arr.push(item);}
  if(arr.length==1) {return arr[0];} else {return arr;}
}

function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}

// Toggle add-on
function toggle(id) {
var n,N,q;
if(id!=='') {
N = $x("//a[contains(@href,'/firefox/addon/')]");
for(q=0; q<N.length; q++) {
n=N[q];
if(n.href.match(/\d+/)[0].indexOf(id)!==-1) {
n=n.parentNode.parentNode.parentNode;
n.style.display=(n.style.display == "none")?"":"none";
}
}
return true;
}
else {return false;}
}

function addID(id) {
var IDs = GM_getValue('ids','');
if(IDs.indexOf(id)==-1) {GM_setValue('ids',(IDs!=='')?IDs+','+id:id);}
}

var i, a, id, xP, x, xp = $x("//a[contains(@href, '/firefox/addon/')]");

var ids = GM_getValue('ids','0,0');
var hide_these = (ids!=='')?ids.split(','):'0,0';

function reset() {
GM_setValue('ids','');
if(confirm('Reload page to apply new filter?')) {window.location.reload();}
}

function unhideid() {
var fID;
var id = prompt('ID Number:').replace(/[^\d]/g, '');
var IDs = GM_getValue('ids','');
if(!!~IDs.indexOf(id)) {
IDs = IDs.replace(id,'');
if(/^\d+,$/.test(IDs)) {IDs=IDs.replace(/,/g,'');}
GM_setValue('ids',IDs);
document.body.innerHTML='';
window.location.reload();
}
}

function main() {
for(i=0; i<xp.length; i++) {
xP=xp[i];
if(xP.href.indexOf('#reviews')==-1) {

for(x=0; x<hide_these.length; x++) {
id=hide_these[x];
if(!!~xP.href.indexOf('/firefox/addon/'+id)) {xP.parentNode.parentNode.parentNode.style.display='none';}
}

a=document.createElement('a');
a.setAttribute('class', 'filter');
a.href='javascript:void(0);';
a.setAttribute('id', xP.href.match(/\d+/)[0]);
a.appendChild(document.createTextNode('Filter'));
a.addEventListener('click', function(e){addID(e.target.getAttribute('id'));e.target.style.display='none';this.parentNode.parentNode.parentNode.style.display='none';}, false);

if(xP.parentNode.tagName.toLowerCase()=='h3') {
xP.appendChild(document.createElement('br'));
insertAfter(a, xP);
}
}
}
}

GM_registerMenuCommand('Reset Filter', reset);
GM_registerMenuCommand('Un-hide id', unhideid);
main();