Discussions » Creation Requests

Make 'userscripts.org Bullshit Filter' userscript work for GreasyFork too

§
Posted: 10/08/2015
Edited: 10/08/2015

Make 'userscripts.org Bullshit Filter' userscript work for GreasyFork too

It's about this great script userscripts.org Bullshit Filter by @kuehlschrank.

It filtered (optionally) any/all of these 4 categories (when browsing userscripts):

  • Games: scripts for browser games like Kingdoms of Camelot, Mafia Wars and Ikariam
  • Social Networks: scripts for general purpose social networking sites like Facebook, studiVZ and VKontakte
  • Non-ASCII: scripts that use non-English characters in description (accents, umlauts, cyrillic letters, ...)
  • Clutter: obvious spam, titles like "asdasdasd", description = title, title < 6 characters, "just a test".

It would be awesome if it worked for GreasyFork too!


PS. The missing image from the script's USO page (link) -open it in new tab-.

§
Posted: 10/08/2015
Edited: 24/08/2015

Update: I just tweaked it a bit (i.e. changed the elements forquerySelector and querySelectorAll and the style ) and now it works.
The filters list appears just below the #script-list-option-groups (i.e. on the right).
Update 8/25: Now each filter appears below the other (and added Twitter to 'Social Networks' regex).

// ==UserScript==
// @name         GreasyFork Bullshit Filter
// @author       kuehlschrank
// @description  Hides scripts for popular browser games and social networks as well as scripts that use "foreign" characters in descriptions*
// @version      1
// @icon         https://s3.amazonaws.com/uso_ss/icon/97145/large.png
// @grant        none
// @include      https://greasyfork.org/*/scripts*
// ==/UserScript==
(function() {
    var filters = {
        'Games': /AntiGame|Astro\s*Empires|^\s*Attack|^\s*Battle|BiteFight|Blood\s*Wars|Bots4|Brawler|\bBvS\b|Business\s*Tycoon|Castle\s*Age|City\s*Ville|Comunio|Conquer\s*Club|CosmoPulse|Dark\s*Orbit|Dead\s*Frontier|\bDOA\b|Dossergame|Dragons\s*of\s*Atlantis|Dugout|\bDS[a-z]+\n|Empire\s*Board|eRep(ublik)?|Epic.*War|ExoPlanet|Falcon Tools|Feuerwache|Farming|FarmVille|Fightinfo|Frontier\s*Ville|Ghost\s*Trapper|Gladiatus|Goalline|Gondal|Grepolis|Hobopolis|\bhwm(\b|_)|Ikariam|\bIT2\b|Jellyneo|Kapi\s*Hospital|Kings\s*Age|Kingdoms?\s*of|knastv(ö|oe)gel|Knight\s*Fight|\b(Power)?KoC(Atta?ck)?\b|\bKOL\b|Kongregate|Last\s*Emperor|Legends?\s*of|Light\s*Rising|Lockerz|\bLoU\b|Mafia\s*(Wars|Mofo)|Menelgame|Mob\s*Wars|Mouse\s*Hunt|Molehill\s*Empire|NeoQuest|MyFreeFarm|Neopets|Nemexia|\bOGame\b|Pardus|Pennergame|Pigskin\s*Empire|PlayerScripts|Popmundo|Po?we?r\s*(Bot|Tools)|PsicoTSI|Ravenwood|Schulterglatze|SpaceWars|\bSW_[a-z]+\n|\bSnP\b|The\s*Crims|The\s*West|Travian|Treasure\s*Isl(and|e)|Tribal\s*Wars|TW.?PRO|Vampire\s*Wars|War\s*of\s*Ninja|West\s*Wars|\bWoD\b|World\s*of\s*Dungeons|wtf\s*battles|Wurzelimperium/i,
        'Social Networks': /Face\s*book|Google(\+| Plus)|\bHabbo|Kaskus|\bLepra|Leprosorium|MySpace|meinVZ|odnoklassniki|Одноклассники|Orkut|sch(ue|ü)ler(VZ|\.cc)?|studiVZ|Unfriend|Valenth|vkontakte|ВКонтакте|Qzone|Twitter/i,
        'Non-ASCII':/[^\x00-\x80\s]+/i,
        'Clutter':/^\s*(.{1,3})\1+\n|^\s*(.+?)\n+\2\n*$|^\s*.{1,5}\n|do\s*n('|o)?t (install|download)|nicht installieren|just(\s*a)?\s*test|^\s*.{0,4}test.{0,4}\n|\ntest(ing)?\s*|^\s*(\{@|Smolka|Hacks)|\[\d{4,5}\]|free\s*download/i
    };
    if(typeof GM_getValue == 'undefined' || (typeof GM_getValue.toString == 'function' && GM_getValue.toString().indexOf('not supported') > -1)) {
        GM_getValue = my_GM_getValue;
        GM_setValue = my_GM_setValue;
    }
    insertStyle();
    insertStatus();
    filterScripts();
    insertSwitches();

    // TO ADD A NEWLINE AT THE END OF EACH FILTER
    if (document.querySelector('.filter-status').parentNode.childNodes[5].childNodes[0].innerHTML == 'Games' ) {
        var flag = 5; }
    else {flag = 9};
    for (i=0; i<4; i++){
        document.querySelector('.filter-status').parentNode.childNodes[flag].childNodes[i].innerHTML += '<br>';        
    }


    function insertStyle() {
        var style = document.createElement('style');
        // style.textContent = 'article.filtered { background-color:yellow; !important; } .filter-status { margin-left: 6px; } .filter-switches { display:none; } *:hover > .filter-switches { display:inline; } .filter-switches a { text-decoration:none !important; color:inherit; cursor:pointer; } .filter-switches a { margin-left: 8px; padding: 0 4px; } a.filter-on { background-color:#ffcccc; color:#333333 } a.filter-off { background-color:#ccffcc; color:#333333 }  ';
        style.textContent = 'article.filtered { display:none; !important; } .filter-status { margin-left: 6px; } .filter-switches { display:none; } *:hover > .filter-switches { display:inline; } .filter-switches a { text-decoration:none !important; color:inherit; cursor:pointer; } .filter-switches a { margin-left: 8px; padding: 0 4px; } a.filter-on { background-color:#ffcccc; color:#333333 } a.filter-off { background-color:#ccffcc; color:#333333 }  ';
        style.type = 'text/css';
        document.querySelector('head').appendChild(style);
    }
    function insertStatus() {
    var p = document.querySelector('#script-list-option-groups');
        if(p) {
            var status = document.createElement('span');
            status.className = 'filter-status';
            p.appendChild(status);
        }
        p.innerHTML += '<br>';        // ADDS A NEWLINE AT THE END OF THE 'STATUS' ENTRY
    }
    function filterScripts() {
        var activeFilters = [];
        for(var filter in filters) {
            if(filters.hasOwnProperty(filter) && GM_getValue(filter, 'on') == 'on') {
                activeFilters.push(filters[filter]);
            }
        }
        var nodes = document.querySelectorAll('article > h2'), numActiveFilters = activeFilters.length, numFiltered = 0;
        for(var i = 0, numNodes = nodes.length, td = null; i < numNodes && (td = nodes[i]); i++) {
            td.parentNode.className = '';
            for(var j = 0; j < numActiveFilters; j++) {
                if(td.textContent.match(activeFilters[j])) {
                    td.parentNode.className = 'filtered';
                    numFiltered++;
                    break;
                }
            }
        }
        document.querySelector('.filter-status').textContent = '(' + numFiltered + ' filtered)';
    }
    function insertSwitches() {
        var span = document.createElement('span');      
        span.className = 'filter-switches';     
        for(var filter in filters) {
            if(filters.hasOwnProperty(filter)) {
                span.appendChild(createSwitch(filter, GM_getValue(filter, 'on') == 'on'));
            }
        }
        document.querySelector('.filter-status').parentNode.appendChild(span);        
    }
    function createSwitch(label, isOn) {
        var a = document.createElement('a');
        a.className = isOn ? 'filter-on' : 'filter-off';
        a.textContent = label;
        a.addEventListener('click', function(e) {
            if(this.className == 'filter-on') {
                this.className = 'filter-off';
                GM_setValue(this.textContent, 'off');
            } else {
                this.className = 'filter-on';
                GM_setValue(this.textContent, 'on');
            }
            filterScripts();
            e.preventDefault();
        }, false);
        return a;
    }
    function my_GM_setValue(name, value) {
        localStorage.setItem(name, value);
    }
    function my_GM_getValue(name, defaultValue) {
        var value;
        if (!(value = localStorage.getItem(name))) {
            return defaultValue;
        }
        return value;
    }
})();
§
Posted: 11/08/2015

Thanks for mentioning this feature. (I would most probably never discover it myself).
For most of my searching needs, I still prefer the (much simpler) search feature of the site with this script , though.

§
Posted: 13/08/2015
Edited: 13/08/2015

It seems not working ...
Firefox 40.0

I can't find , with Firebug, any ref. to:
article.filtered
.filter-status
.filter-switches
a.filter-on
a.filter-off

Ps:
You need change the include:
// @include https://greasyfork.org/*/scripts*
So other local can match ..

§
Posted: 24/08/2015
Edited: 27/08/2015

@decembre Ok, changed. Thanks (but I don't use a foreign locale).

Today, I managed to make each filter appear under the other.
@kuehlschrank would you mind if I uploaded this script? (giving you credit for the initial code, of course)

Deleted user 12
§
Posted: 03/09/2015

No, go ahead.

§
Posted: 03/09/2015
No, go ahead.

Thank you. I've uploaded it here.

§
Posted: 21/10/2015

Thanks !
Work great !

Post reply

Sign in to post a reply.