-
Notifications
You must be signed in to change notification settings - Fork 0
/
hide_craigslist_categories.user.js
91 lines (85 loc) · 2.8 KB
/
hide_craigslist_categories.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
//
// ==UserScript==
// @name Hide Craigslist Categories
// @namespace http://jkk.us/scripts
// @description Hide Craigslist Categories with a Click. Link to reset filter at bottom of page.
// @include http://*.craigslist.tld/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// ==/UserScript==
//
*/
/*
A craigslist row:
<p class="row">
<span>
<a href="article url">
(article title)
(separator dash)
<font>
(city)
<small class="gc">
<a href="category url">
(category title)
<br class="c">
*/
(function() {
var __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
$(document).ready(function() {
var append_hide_button_to_category_link, clear_omitted_hrefs, get_all_category_links_on_page, get_omitted_hrefs, hide_category, insert_omitted_href, reset_link, scan_page_and_hide_rows;
get_omitted_hrefs = function() {
var refs, val;
val = GM_getValue("omitted_hrefs");
refs = val != null ? val.split("\n") : [];
return refs;
};
insert_omitted_href = function(href) {
var hrefs;
href = href.split('craigslist.org')[1];
hrefs = get_omitted_hrefs();
if ((href != null) && href !== "" && __indexOf.call(hrefs, href) < 0) {
hrefs.push(href);
return GM_setValue("omitted_hrefs", hrefs.join('\n'));
}
};
clear_omitted_hrefs = function() {
return GM_deleteValue("omitted_hrefs");
};
append_hide_button_to_category_link = function(link) {
var hide_button;
hide_button = $("<button>(Hide)</button>");
hide_button.on("click", function() {
insert_omitted_href(link.href);
return scan_page_and_hide_rows();
});
return hide_button.insertAfter(link);
};
get_all_category_links_on_page = function() {
return $("p small.gc a");
};
hide_category = function(category_href) {
var af, href_selector;
href_selector = "[href='" + category_href + "']";
af = $(href_selector);
return af.closest('p').hide();
};
scan_page_and_hide_rows = function() {
var omits;
omits = get_omitted_hrefs();
$.each(omits, function(n, category_href) {
return hide_category(category_href);
});
return null;
};
reset_link = $("<button>(reset hide list)</button>");
reset_link.on("click", function() {
clear_omitted_hrefs();
return get_all_category_links_on_page().closest('p').show();
});
reset_link.appendTo('body');
get_all_category_links_on_page().each(function(n, link) {
return append_hide_button_to_category_link(link);
});
return scan_page_and_hide_rows();
});
}).call(this);