-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathutils.js
More file actions
59 lines (54 loc) · 1.57 KB
/
Copy pathutils.js
File metadata and controls
59 lines (54 loc) · 1.57 KB
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
export const getMonths = (month = 12) => {
const d = new Date();
const result = [];
for (let i = 0; i < month; i++) {
d.setMonth(d.getMonth() - 1);
const m = d.getMonth() + 1;
const month = m < 10 ? `0${m}` : m;
result.push(`${d.getFullYear()}-${month}`);
}
return result.sort();
};
export const getParameterByName = (name, url = window.location.href) => {
// eslint-disable-next-line
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return "";
return decodeURIComponent(results[2].replace(/\+/g, " "));
};
export const isSameDay = (d1, d2) => {
return (
d1.getFullYear() === d2.getFullYear() &&
d1.getMonth() === d2.getMonth() &&
d1.getDate() === d2.getDate()
);
};
export const inIframe = () => {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
};
export const handleShareToTwitterClick = (params) => {
const shareUrl = `https://git-contributor.com${params}`;
const shareText = params.includes("contributorMonthlyActivity")
? "monthly active contributor"
: "contributor over time";
if (!inIframe()) {
const text = `Amazing tools to view your repo ${shareText}`;
const newUrl = encodeURIComponent(shareUrl);
window.open(`https://twitter.com/intent/tweet?text=${text}&url=%20%0A${newUrl}%20%0A%20%0A&via=API7ai`, '_blank');
}
window.parent.postMessage(
{
share: {
to: "twitter",
url: shareUrl,
},
},
"*"
);
}