forked from thesam73/wordle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
share.ts
57 lines (53 loc) · 1.73 KB
/
share.ts
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
import copy from 'copy-to-clipboard';
import { getGuessStatuses } from './statuses'
import { solutionIndex } from './words'
import { lang } from './param'
//import { GAME_TITLE } from '../constants/strings'
import i18n from '../i18n'
export const GA_TRACKING_ID = 'AW-625715352'
export const shareStatus = (guesses: string[], lost: boolean, conversion_func: string) => {
/* navigator.clipboard.writeText(
`${i18n.t("home.title")} ${solutionIndex} ${lost ? 'X' : guesses.length}/6\n\n` +
generateEmojiGrid(guesses)
) */
let href = window.location.href;
let randStr = Math.random().toString(36).slice(-4);
randStr = randStr.split('').map((c) => (Math.round(Math.random()*10) % 2 === 0 ? c.toUpperCase() : c)).join('');
if (href.indexOf('?') !== -1){
href += '&f=' + randStr;
} else {
href += '?f=' + randStr;
}
let title = i18n.t("home.title");
if (title === "Palora") {
title = "Palora.me"
}
copy(
`${title} ${solutionIndex+1} ${lost ? 'X' : guesses.length}/6\n\n` +
generateEmojiGrid(guesses) + '\n' + href
);
fetch('/stat/click_share/?lang=' + lang + '&f=' + randStr);
//window.gtag_report_conversion_homepage_share(href);
//eval(conversion_func + "('" + href + "')");
alert("needreplace2eval" + conversion_func + "('" + href + "')")
}
export const generateEmojiGrid = (guesses: string[]) => {
return guesses
.map((guess) => {
const status = getGuessStatuses(guess)
return guess
.split('')
.map((_, i) => {
switch (status[i]) {
case 'correct':
return '🟩'
case 'present':
return '🟨'
default:
return '⬜'
}
})
.join('')
})
.join('\n')
}