-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
156 lines (141 loc) · 6.05 KB
/
index.html
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BNB Parser</title>
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var MIN_REVIEWS = 15;
var MIN_RATING = 4.8;
window.onload = function () {
window.opener.postMessage('ready', '*')
window.app = new Vue({
el: '#app',
data: {
min_reviews: MIN_REVIEWS,
min_rating: MIN_RATING,
sort_by: 'price',
require_sqm: false,
sorted: Object.freeze([])
},
methods: {
totalPrice: (listing) => listing.pricing_quote.price.total.amount_formatted,
pricePerNight: (listing) => listing.pricing_quote.price_string,
amountOfNights: (listing) => {
let title = listing.pricing_quote.price.price_items[0].localized_title;
return Number(title.split(' x ')[1].split(' ')[0]);
},
bookLink: function (listing) {
// nesting href params from search page
return 'https://www.airbnb.com/rooms/' + listing.id + '?' + window.json.href;
},
sortAndFilter: function () {
var sorted = window.json.listings.sort(function (a, b) {
switch (window.app.sort_by) {
case 'price':
return a.pricing_quote.price.total.amount - b.pricing_quote.price.total.amount;
case 'price_rev':
return b.pricing_quote.price.total.amount - a.pricing_quote.price.total.amount;
case 'reviews_count':
return b.reviews_count - a.reviews_count;
case 'avg_rating':
return (b.avg_rating ? b.avg_rating : 0) - (a.avg_rating ? a.avg_rating : 0);
case 'by_sqm':
return b.sqm - a.sqm;
}
})
let min_reviews = Number(window.app.min_reviews);
let min_rating = Number(window.app.min_rating);
var sorted = sorted.filter(function (listing) {
// new flats assume 0 rating
let rating = listing.avg_rating ? listing.avg_rating : 0;
if (listing.reviews_count >= min_reviews && rating >= min_rating) {
if (window.app.require_sqm && listing.sqm == 0) {
return false;
}
return true;
} else {
//console.log('fail', l)
return false
}
})
console.log(sorted)
this.sorted = sorted
}
}
})
}
window.onmessage = function (e) {
//if (e.origin == 'https://airbnb.com')
window.json = JSON.parse(e.data)
let reg = /([0-9]+)[ ]?sqm/igm
for (let listing of window.json.listings) {
listing.sqm = reg.exec(listing.name)
// 0 if not provided
listing.sqm = listing.sqm ? Number(listing.sqm[1]) : 0
}
window.app.sortAndFilter()
}
</script>
</head>
<body>
<div class="container" id=app>
<div class="row">
<div class="col-md-2">
<label>Found</label>
<input class="form-control-plaintext" readonly type="text" v-model="sorted.length"
style="font-weight: 800;">
</div>
<div class="col-md-2">
<label>Min Reviews</label>
<input class="form-control form-control-sm" @change="sortAndFilter()" v-model="min_reviews">
</div>
<div class="col-md-2">
<label>Min Rating</label>
<input class="form-control form-control-sm" @change="sortAndFilter()" v-model="min_rating">
</div>
<div class="col-md-6">
<label>Sort</label>
<select class="form-control form-control-sm" v-model="sort_by" @change="sortAndFilter()">
<option value="price">Price (low to high)</option>
<option value="price_rev">Price (high to low)</option>
<option value="reviews_count">Reviews count</option>
<option value="avg_rating">Avg rating</option>
<option value="by_sqm">By sqm in the name</option>
</select>
</div>
</div>
<!-- <input @change="sortAndFilter()" type="checkbox" v-model="require_sqm"> Require "sqm" -->
<div v-if="sorted.length > 100">
<h1>Showing only first 100 listings.</h1>
</div>
<ul class="list-group">
<li class="list-group-item" v-for="listing in sorted.slice(0,100)">
<div class="row">
<div class="col-md-1">
<img :src="listing.picture_url" width="72px">
</div>
<div class="col-md-2 text-right">
{{amountOfNights(listing)}} nights x {{pricePerNight(listing)}}<br />
Total: <span style="font-weight: 800;">{{totalPrice(listing)}}</span>
</div>
<div class="col-md-2">
★
<span style="font-weight: 800;">{{listing.avg_rating}}</span>
<span style="color: #717171">({{listing.reviews_count}})</span>
</div>
<div class="col-md-5">
<a :href="bookLink(listing)">{{listing.name}}</a>
</div>
<div class="col-md-2">
{{listing.city}}
<!-- <img v-for="pic in listing.picture_urls.slice(0,10)" :src="pic" height="100px"> -->
</div>
</div>
</li>
</ul>
</div>
</body>
</html>