-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.html
212 lines (183 loc) · 7.28 KB
/
background.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!-
THIS FILE IS INVALID, DONT USE. Need to remove this later..
hRecipeHelper, a Chrome extention for building microformat compatable.
Copyright (c) 2012 Lee Clarke
LICENSE:
This file is part of hRecipeHelper (http://github.com/leeclarke/hRecipeHelper).
hRecipeHelper is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
later version.
hRecipeHelper is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with TheGardenDroid. If not, see
<http://www.gnu.org/licenses/>.
-->
<html>
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/jquery.url.js"></script>
<script type="text/javascript" src="js/formData.js"></script>
<script>
var BLOGGER = "www.blogger.com";
var BLOGGER_POST = "/post-edit.g";
var BLOGGER_CREATE = "/post-create.g";
/**
* //Cant use Chrome with the Blogger api with out getting an ugly popup... so odd, come on google really?
* Moving output to the popup to display for copy/paste
*/
function processData(data, options) {
var currentURL = "";
//debug
var toString = "rec-name:"+ data.$recName + " ingredients:"+ data.$ingredients + " yield:" + data.$yield;
debug("got data: "+toString)
var hRecipeCode = convertTohRecipe(data, options);
debug("hrecipe=="+hRecipeCode);
return hRecipeCode;
//chrome.tabs.executeScript(null, {code:"updateText('"+hRecipeCode+"')"})
debug("done");
}
/* a few notes to be used for new features
chrome.tabs.getSelected(null, function(tab) {
var url = tab.url;
jQuery.url.setUrl(url)
debug("HOST="+jQuery.url.attr("host"));
//var currField == document.activeElement;
//chrome.tabs.executeScript(null, {code:"updateText('TESTER')"})
//chrome.tabs.executeScript(null, {code:"console.log('active=='+document.activeElement)"})
});
*/
/**
* Converts data to the hRecipe format with default formatting tags.
*/
function convertTohRecipe(data, options) {
var microformat = "<div class=\"hrecipe\">\n";
if(data){
microformat += ("<h1 class=\"fn\">" + data.$recName + "</h1>\n");
//if(data.$summary) microformat += ("<><p class=\"summary\">" + data.$summary + "</p>\n");
if(data.$author) microformat += ("<p><label>By </label><span class=\"author\">" + data.$author + "</span></p>\n");
if(data.$published) microformat += ("<p>Published <span class=\"published\">" + data.$published + "</span></p>\n");
if(data.$photos.length>0 && data.$photos[0].length > 0) {
microformat += ("<img src=\"" + data.$photos[0] + "\" class=\"photo\" style=\"height:140px;width:140px;border-width:0px;\" alt=\"" + data.$recName + "\">\n");
}
if(data.$summary) microformat += ("<p class=\"summary\">" + data.$summary + "</p>\n");
microformat +="<h2>Ingredients</h2>\n";
if(options.blt_ingrediants == true) {
microformat +="<ul>\n";
for(var i in data.$ingredients) {
if(data.$ingredients[i].length >0) {
microformat += ("<li class=\"ingredient\">" + data.$ingredients[i] + "</li>\n");
}
}
microformat +="</ul>\n";
}else {
microformat +="<div>\n";
for(var i in data.$ingredients) {
if(data.$ingredients[i].length >0) {
microformat += ("<span class=\"ingredient\">" + data.$ingredients[i] + "</span><br>\n");
}
}
microformat +="</div>\n";
}
if(data.$instructions) {
microformat +="<h2>Instructions</h2>\n";
if(options.nbr_instr == true) {
var listType = (data.$instructions.length==1)?"ul":"ol";
microformat +="<" + listType + ">\n";
for(i in data.$instructions) {
if(data.$instructions[i].length >0) {
microformat += ("<li class=\"ingredient\">" + data.$instructions[i] + "</li>\n");
}
}
microformat +="</" + listType + ">\n";
} else {
microformat +="<div>\n";
for(i in data.$instructions) {
if(data.$instructions[i].length >0) {
microformat += ("<div class=\"ingredient\">" + data.$instructions[i] + "</div><br>\n");
}
}
microformat +="</div>\n";
}
}
if(data.$yield) microformat += ("<p><span style='font-weight:bold;'>Yield:</span><span class=\"yield\"> "+data.$yield+"</span></p>\n");
if(data.$preptime || data.$cooktime) {
microformat += "<span class=\"duration\">\n";
var prep = "0M";
var cook = "0M";
if(data.$preptime) {
prep = parseTime(data.$preptime);
microformat += ("<p><span style='font-weight:bold;'>Prep Time:</span><span class=\"preptime\"><span class=\"value-title\" title=\""+prep+"\"></span> "+data.$preptime+"</span></p>\n");
}
if(data.$cooktime) {
cook = parseTime(data.$cooktime);
microformat += ("<p><span style='font-weight:bold;'>Cook time:</span><span class=\"cooktime\"><span class=\"value-title\" title=\""+cook+"\"></span> "+data.$cooktime+"</span></p>\n");
}
microformat += "</span>\n";
}
if(options.blt_nutrition == true) {
if(data.$nutritions.length>0 && data.$nutritions[0].length > 0) {
microformat +="<h2>Nutrition</h2>\n";
microformat +="<p>\n";
microformat +="<ul class=\"nutrition\">";
for(var n in data.$nutritions) {
if(data.$nutritionTypes[n].length >0) {
microformat += "<li>"+toProperCase(data.$nutritionTypes[n])+": <span class=\""+ (data.$nutritionTypes[n].replace(" ","")).toLowerCase() + "\">" +(data.$nutritions[n] + "</span></li>\n");
}
}
microformat +="</ul>\n</p>\n";
}
} else {
if(data.$nutritions.length>0 && data.$nutritions[0].length > 0) {
microformat +="<h2>Nutrition</h2>\n";
microformat +="\n";
microformat +="<div class=\"nutrition\">";
for(var n in data.$nutritions) {
if(data.$nutritionTypes[n].length >0) {
microformat += "<div>"+toProperCase(data.$nutritionTypes[n])+": <span class=\""+ (data.$nutritionTypes[n].replace(" ","")).toLowerCase() + "\">" +(data.$nutritions[n] + "</span></div>\n");
}
}
microformat +="</div><br>\n\n";
}
}
if(data.$tags && data.$tags.length >0 && data.$tags[0].length > 0) {
var tagCode = [];
microformat +="<span style='font-weight:bold;'>Tags: </span>";
for(var t in data.$tags) {
tagCode.push("<span class=\"tag\">"+data.$tags[t]+"</span>");
}
microformat += tagCode.join(',');
microformat +="</span>";
}
}
microformat += "</div>";
return microformat;
}
/**
* Makes first letter of each word uppercase.
*/
function toProperCase(strIn) {
var results = []
if(strIn) {
var words = strIn.toLowerCase().split(" ");
for(w in words) {
var first = words[w].charAt(0).toUpperCase();
results.push(first + words[w].substr(1));
}
}
return results.join(" ");
}
/**
* Parse method expects to recieve time formatted in the hh:mm format and simply yanks out the : and adds markers
*/
function parseTime(timeValue) {
var result = "PT";
var timeSplit = timeValue.split(":");
if(timeSplit.length == 2) {
result += (timeSplit[0]+"H"+timeSplit[1]+"M");
} else {
result += (timeValue+"M");
}
return result;
}
</script>
</html>