This repository has been archived by the owner on Jul 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
unfuckify-yad2.user.js
137 lines (108 loc) · 4.18 KB
/
unfuckify-yad2.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// ==UserScript==
// @name Unfuckify yad2
// @namespace http://www.eran.io
// @version 0.0.3
// @description Make using yad2 not want to make you kill yourself
// @match www.yad2.co.il/Nadlan/rent.php*
// @match www.yad2.co.il/Nadlan/sales.php*
// @match www.yad2.co.il/Nadlan/rent_info.php?*
// @match www.yad2.co.il/Nadlan/tivrent_info.php?*
// @match www.yad2.co.il
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// ==/UserScript==
// hide piece of shit distractions
[
// uncomment the following line to remove tivuch
// ".main_table_wrap:eq(1)",
// removes "new projects" banner in details page, comment out if it interests you
"#mainFrame > div.right_column > div > div > table > tbody > tr:nth-child(1) > td:nth-child(2) > div",
".bannerBetweenTables_main",
".search_banners",
"#Hotpics",
"#lastsearch_block",
"iframe",
".walla_strip",
".articles_block",
"#footer",
".intro_block",
"#GamboBanner",
"#rtower",
".banner_strip",
"#top_banners",
"[alt*='Platinum']",
"#ad_martef",
".left_column > div:last-of-type",
"#mainIndex > div.left_column > div.current_ads_block",
"#mainIndex > div.left_column > div.login_block + div + div + div",
"#mainIndex > div.right_column > div.mador_index_block_wrap > div.mador_index_block_prom_IMAGE",
"#mainIndex > div.pie",
"#mainIndex > div.yad1_banners"
].forEach(function(elementName) {
$(elementName).hide();
});
// remove piece of shit distractions
[
"#GamboBanner",
"#rtower",
"#leftSekindo",
"#facebookBox",
"#dynamicLeftBanner",
".moving_promotion_deals_back",
".platinum",
"[id*='Fusion_holder_']"
].forEach(function(elementName) {
$(elementName).remove();
});
function getBackgroundColorBySeen(seen) {
return (seen === 1) ? '#FCF3D7' : '#E2E3E8';
}
function loadAdState(aid) {
// read from local storage, deserialize
var adState = JSON.parse(localStorage.getItem(aid));
// return the loaded adstate or some default
return adState || {seen: 0, interest: true};
}
function saveAdState(aid, state) {
// just save
localStorage.setItem(aid, JSON.stringify(state));
}
function renderRowInterest(rowElement, aid, interest) {
var lastTdText = interest ? '-' : '+';
var rowTextColor = interest ? '#000000' : '#BBBBBB';
// change "details" to "dont give a fuck"
rowElement.find('td:last-child').html(lastTdText).click({aid: aid, interest: !interest}, setAdInterest);
rowElement.find('td').css('color', rowTextColor);
}
function setAdInterest(event) {
// update interest
var adState = loadAdState(event.data.aid);
adState.interest = event.data.interest;
saveAdState(event.data.aid, adState);
// re-render row
renderRowInterest($(this).parent(), event.data.aid, event.data.interest);
}
function augmentAds(adPrefix, linkPrefix) {
$("tr[id^='" + adPrefix + "']").each(function(index) {
// get the ad identifier
var aid = $(this).attr('id').replace(adPrefix, '');
// get the attributes for this ad, use default
var adState = loadAdState(aid);
// increment # of times we've seen this ad
adState.seen += 1;
// indicate how many times we've seen it
$(this).find('td:eq(1)').html('<a href=http://www.yad2.co.il/Nadlan/' + linkPrefix + aid + '>' + adState.seen + '</a>');
// set background color
$(this).find('td')
.css('background', getBackgroundColorBySeen(adState.seen))
.css('font-weight', 'normal');
// change the row to reflect if we've expressed disgust at it yet
renderRowInterest($(this), aid, adState.interest);
// save what we know about this item
saveAdState(aid, adState);
});
}
// augment rent and
augmentAds('tr_Ad_2_2_', 'rent_info.php?NadlanID=');
augmentAds('tr_Ad_2_6_', 'tivrent_info.php?NadlanID=');
augmentAds('tr_Ad_2_1_', 'sales_info.php?NadlanID=');
augmentAds('tr_Ad_2_5_', 'tivsales_info.php?NadlanID=');