~gm-dev-launchpad/launchpad-gm-scripts/master

38.1.1 by Markus Korn
* lp_hide_tags.user.js: added script to hide and sort the list of project
1
// ==UserScript==
2
// @name           LP_HideTags
3
// @namespace      http://thekorn.com/greasemonkey/
4
// @description    (Launchpad) hide and sort tags
5
// @include        https://*.launchpad.net/*
6
// @include        https://*.edge.launchpad.net/*
7
// @include        https://launchpad.net/*
8
// @date           2008-07-21
9
// @creator        Markus Korn <thekorn@gmx.de>
10
// ==/UserScript==
11
12
13
(function() {
14
40 by Brian Murray
grammar corrections
15
// threshold: min. number of tag appearances for a project
38.1.1 by Markus Korn
* lp_hide_tags.user.js: added script to hide and sort the list of project
16
var threshold = 10;
17
// max_tags: max. number of shown tags, if this is -1 all tags fitting the threshold criteria will be shown
38.1.2 by Markus Korn
* lp_hide_tags.user.js: added black- and whitelist support
18
var max_tags = 15;
38.1.1 by Markus Korn
* lp_hide_tags.user.js: added script to hide and sort the list of project
19
// min_tags: if the number of tags for a project is smaller than this show a sorted list of all tags
20
var min_tags = 30;
40 by Brian Murray
grammar corrections
21
// whitelist: always show tags in this list, ignore other setting for these tags
38.1.2 by Markus Korn
* lp_hide_tags.user.js: added black- and whitelist support
22
var whitelist = ["bitesize"];
23
// blacklist: do not show tags in this list
24
var blacklist = ["apport-crash", "apport-bug"];
38.1.1 by Markus Korn
* lp_hide_tags.user.js: added script to hide and sort the list of project
25
// ------- End of User settable data -------
26
27
function xpath(query, context) {
28
    context = context ? context : document;
29
    return document.evaluate(query, context, null,
30
                            XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
31
}
32
33
function sort_tags(a, b) {
34
    return b["count"] - a["count"];
35
}
36
38.1.2 by Markus Korn
* lp_hide_tags.user.js: added black- and whitelist support
37
function in_list(value, mylist) {
38
    for (s in mylist) {
39
        if (mylist[s] == value) {
40
            return true;
41
        }
42
    }
43
    return false;    
44
}
45
38.1.1 by Markus Korn
* lp_hide_tags.user.js: added script to hide and sort the list of project
46
window.addEventListener("load", function(e) {
47
48
    var tags = [];
38.1.2 by Markus Korn
* lp_hide_tags.user.js: added black- and whitelist support
49
    var whitelist_tags = [];
38.1.1 by Markus Korn
* lp_hide_tags.user.js: added script to hide and sort the list of project
50
    var tag_nodes = xpath("//div[@class='portlet' and @id='portlet-tags']/div[@class='portletBody']/table//tr");
51
    for ( var i = 0; i < tag_nodes.snapshotLength; i++ ) {
52
        var tag = {};
53
        var node = tag_nodes.snapshotItem(i);
54
        var m = xpath("td[2]", node);
55
        tag["count"] = m.snapshotItem(0).textContent;
56
        tag["node"] = node;
38.1.2 by Markus Korn
* lp_hide_tags.user.js: added black- and whitelist support
57
        m = xpath("td[1]/a", node);
58
        name = m.snapshotItem(0).textContent;
59
        if (in_list(name, blacklist)) {
60
            //Nothing
61
        } else if (in_list(name, whitelist)) {
62
            whitelist_tags.push(tag);
63
        } else if (!(tag_nodes.snapshotLength > min_tags && tag["count"] < threshold)) {
38.1.1 by Markus Korn
* lp_hide_tags.user.js: added script to hide and sort the list of project
64
            tags.push(tag);
65
        }
66
        node.parentNode.removeChild(node);
67
    }
38.1.2 by Markus Korn
* lp_hide_tags.user.js: added black- and whitelist support
68
    tags = tags.sort(sort_tags);
69
    if (max_tags != -1) {
70
        tags = tags.slice(0, max_tags);
38.1.1 by Markus Korn
* lp_hide_tags.user.js: added script to hide and sort the list of project
71
    }
38.1.2 by Markus Korn
* lp_hide_tags.user.js: added black- and whitelist support
72
    tags = tags.concat(whitelist_tags);
73
    tags = tags.sort(sort_tags);
38.1.1 by Markus Korn
* lp_hide_tags.user.js: added script to hide and sort the list of project
74
    var tag_node = xpath("//div[@class='portlet' and @id='portlet-tags']/div[@class='portletBody']/table").snapshotItem(0);
75
    for ( var i = 0; i < tags.length; i++) {
76
        tag_node.appendChild(tags[i]["node"]);
77
    }
78
  }, false);
79
})();