-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathefn.user.js
executable file
·148 lines (129 loc) · 4.53 KB
/
efn.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
138
139
140
141
142
143
144
145
146
147
148
// ==UserScript==
// @name Extended Field Notes
// @description Makes field notes usable in other places: shows already found caches from there in your statistics, and changes the display of caches in bookmark lists as if they were already logged as found.
// @author JakeDot <[email protected]>
// @namespace https://github.com/jakedot/userscripts/
// @updateURL https://raw.githubusercontent.com/jakedot/userscripts/master/efn.meta.js
// @downloadURL https://raw.githubusercontent.com/jakedot/userscripts/master/efn.user.js
// @icon https://www.geocaching.com/images/icons/32/write_log.png
// @include https://www.geocaching.com/my/statistics.aspx
// @include http://www.geocaching.com/my/statistics.aspx
// @include https://www.geocaching.com/bookmarks/*
// @include http://www.geocaching.com/bookmarks/*
// @exclude https://www.geocaching.com/bookmarks/
// @exclude http://www.geocaching.com/bookmarks/
// @version 1.5
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
// @grant none
// @grant GM_xmlhttpRequest
// ==/UserScript==
$(function(){
console.log("extended field notes 1.5");
var fieldnotes,
found = [],
dnf = [],
logRowSel = ".Table tbody tr",
bmReg = /\/bookmarks\/.*\.aspx$/, bmCase,
stReg = /\/statistics\.aspx$/, stCase,
gcCodeReg = /\/geocache\/(.+)_/,
path = window.location.pathname;
// Boolean extension functions
var bf = (function() {
function any() {
for (var b of arguments) {
if (b) return true;
}
return false;
}
function all() {
for (var b of arguments) {
if (!b) return false;
}
return true;
}
return {
any: any,
all: all,
none: (...a) => !any(...a),
notall: (...a) => !all(...a),
};
})();
$.extend(Boolean, bf);
function defVal(cond, val) {
return !cond ? val : cond;
}
function inc(a, i) {
a[i] = defVal(a[i],0) + 1;
}
function isOnPath() {
return Boolean.any(
bmCase = bmReg.test(path),
stCase = stReg.test(path),
undefined
);
}
function handle() {
if (bmCase) {
bmHandle();
} else if (stCase) {
stHandle();
}
}
function stHandle() {
var dates = {},
months = [undefined ,"January","February","March","April","May","June","July","August","September","October","November","December"]; // begin index 1
$.each(found,function(i,tr){
var tr_date = $("td:eq(2)", tr).text().split(" ");
var day = Number(tr_date[0]),
month = months.indexOf(tr_date[1]);
var id = month+"_"+day;
inc(dates,id);
});
$.each(dates,function(i,f){
var $id = $("#"+i);
var m = Number($id.text());
$id.text(m + f);
$id.css({"background-color":"#f88","color":"#fff"});
});
}
function gcCode(url, callback) {
// need XHR for responseURL
var xhr = new XMLHttpRequest();
xhr.open('HEAD', url, true);
xhr.onload = function () {
var code = gcCodeReg.exec(xhr.responseURL)[1];
callback(code);
};
xhr.send(null);
}
function bmHandle() {
$.each(found, function(i,tr) {
var url = $("td:eq(1) a",tr).attr("href");
gcCode(url, function(code){
var row = $(logRowSel + ":contains(" + code + ")"),
row2 = $("#" + row.attr("id") + "2");
row.add(row2).addClass("TertiaryRow");
$("td:eq(2)", row).html('<img src="/images/icons/16/found.png" alt="X" title="List Owner Found It!">');
});
});
}
function isLogType(lt, tr) {
var log = $("td:eq(3):contains("+lt+")", tr);
return log.length && log.length > 0;
}
if (isOnPath()) {
$.get("//www.geocaching.com/my/fieldnotes.aspx")
.done(function(val) {
fieldnotes = $(logRowSel, $.parseHTML(val));
fieldnotes.each(function(i,tr){
if(isLogType("Found it", tr)) {
found.push(tr);
}
if (isLogType("Did not find",tr)) {
dnf.push(tr);
}
});
handle(path);
});
}
});