-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinject.js
executable file
·88 lines (71 loc) · 3.52 KB
/
inject.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
function loadLogbookPage(pageIdx, showPersonal, showFriends, limit) {
var loadPersonalAfter;
if (showFriends === "true" && showPersonal === "true") {
showPersonal = "false";
loadPersonalAfter = "true";
}
$.getJSON("/seek/geocache.logbook", {
tkn: userToken,
idx: pageIdx + 1,
num: limit,
sp: showPersonal,
sf: showFriends,
decrypt: decryptLogs
},
function(response) {
if (response.status == "success") {
if (response.pageInfo.rows > 0) {
var logTbody = $("#cache_logs_table")[0].firstChild;
//This needs a unique class, otherwise insertBefore("tbody") would insert it before any tbody on this page
if ($(".main_tbody").length === 0) {
logTbody.nextSibling.className = "main_tbody";
}
var logContainer = $("#cache_logs_container")[0];
if (showFriends === "true") {
var breakLine;
if (typeof loadPersonalAfter === 'undefined') {
breakLine = "";
} else {
breakLine = "<br>";
}
if (response.pageInfo.rows == 1) {
$(breakLine + "<h3>1 Friend Log</h3>").insertBefore(logContainer.firstChild.nextSibling.firstChild);
} else {
//bigger than 1
$(breakLine + "<h3> " + response.pageInfo.rows + " Friends Logs</h3>").insertBefore(logContainer.firstChild.nextSibling.firstChild);
}
} else if (showPersonal === "true") {
if (response.pageInfo.rows == 1) {
$("<h3>My Log</h3>").insertBefore(logContainer.firstChild.nextSibling.firstChild);
} else {
//bigger than 1
$("<h3>My Logs</h3>").insertBefore(logContainer.firstChild.nextSibling.firstChild);
}
}
var logs = $.tmpl("tmplCacheLogRow", response.data);
//There is an issue of logs being loaded inside the images section, as a patch is better to remove them
//https://github.com/rfsbraz/Geocaching.com-Friends-Logs/issues/1
$(logs).find("table").remove();
logs.insertBefore(logTbody);
logs.find("a.tb_images").each(function() {
var $this = $(this);
$this.fancybox({
'type': 'image',
'titlePosition': 'inside',
'padding': 10,
titleFormat: function() {
return $this.data('title');
}
});
});
if (typeof loadPersonalAfter === 'undefined') {
$("<br><h3>Logbook</h3>").insertBefore($(".main_tbody"));
}
}
if (loadPersonalAfter === "true") {
loadLogbookPage(pageIdx, "true", "false", limit);
}
}
});
}
loadLogbookPage(0, $("#inject").attr("showMyLogs"), $("#inject").attr("showFriendsLogs"), $("#inject").attr("limit"));