-
Notifications
You must be signed in to change notification settings - Fork 2
/
justeat.js
97 lines (85 loc) · 3.38 KB
/
justeat.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
/************************************************************************************************
* Main content script for Just Check extension - displays food hygiene information on Just-Eat
* and Hungry House takeaway clearing house websites.
*
* For Hungry House, this only works when the website is in 'expanded' view, as the compact view
* doesn't contain the address of the takeaway.
*
* Created 06 June 2013 by pezholio
*
* Contributers:
* Raj Bhaskar <[email protected]>
***********************************************************************************************/
var source= document.URL.toLowerCase();
// Just-Eat detected
if (source.indexOf("just-eat") != -1)
{
$(".restaurants .restaurant").each(function() {
name = $(this).find(".title h2 a").text()
address = $(this).find(".address").text().trim()
postcode = getPostcodeFromAddress(address);
if (postcode)
{
// Search
var search_url= "http://ratings.food.gov.uk/search/" + name + "/" + postcode + "/json";
// make the call to the web service, sending some additional parameters to the callback
// (success) function [insertAfter, takeawayBox]
$.ajax({
url: search_url,
dataType: "json",
insertAfter: ".address",
takeawayBox: $(this),
success: processRatings
});
} // end if a postcode was found
});
} // end if this is Just-Eat
// Hungry House detected
else if (source.indexOf("hungryhouse") != -1)
{
// Force expanded mode so we can see the scores
$('.homepagePostCodeForm form').append('<input name="view[name]" value="expanded" type="hidden" />')
$("#restsSearchResultsList .restsSearchItemRes").each(function() {
var name= $(this).find(".restsMainInfo h3 a").text().trim();
var address= $(this).find(".restsMap div:first-child").text().trim();
var postcode= getPostcodeFromAddress(address);
// only search if we found a postcode
if (postcode)
{
// now search for the restaurant on the FSA website
var search_url= "http://ratings.food.gov.uk/search/" + name + "/" + postcode + "/json";
// make the call to the web service, sending some additional parameters to the callback
// (success) function [insertAfter, takeawayBox]
$.ajax({
url: search_url,
dataType: "json",
insertAfter: "a.buttonsOld",
takeawayBox: $(this),
success: processRatings
});
} // end if a postcode was found
});
} // end if this is Hungry House
// Fill My Belly detected
else if (source.indexOf("fillmybelly") != -1) {
$(".search-product").each(function() {
var name= $(this).find(".searchlogo-heading span:first").text().trim();
var address= $(this).find("img.displayblock").attr('alt').trim();
var postcode= getPostcodeFromAddress(address);
// only search if we found a postcode
if (postcode)
{
// now search for the restaurant on the FSA website
var search_url= "http://ratings.food.gov.uk/search/" + name + "/" + postcode + "/json";
// make the call to the web service, sending some additional parameters to the callback
// (success) function [insertAfter, takeawayBox]
$.ajax({
url: search_url,
dataType: "json",
insertAfter: ".searchlogo",
takeawayBox: $(this),
success: processRatings
});
} // end if a postcode was found
});
}