-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomWord.js
More file actions
118 lines (101 loc) · 3.68 KB
/
RandomWord.js
File metadata and controls
118 lines (101 loc) · 3.68 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
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
import { animals } from "./wordlists/animals.js";
import { basics } from "./wordlists/basics.js";
import { basics2 } from "./wordlists/basics2.js";
import { cakes } from "./wordlists/cakes.js"
import { christmas } from "./wordlists/christmas.js"
import { clothing } from "./wordlists/clothing.js"
import { colours } from "./wordlists/colours.js";
import { community } from "./wordlists/community.js";
import { days } from "./wordlists/days.js";
import { drinks } from "./wordlists/drinks.js";
import { emotions } from "./wordlists/emotions.js";
import { extras } from "./wordlists/extras.js";
import { family } from "./wordlists/family.js";
import { food } from "./wordlists/food.js";
import { fruit } from "./wordlists/fruit.js";
import { hobbies } from "./wordlists/hobbies.js";
import { home } from "./wordlists/home.js";
import { illness } from "./wordlists/illness.js";
import { months } from "./wordlists/months.js";
import { numbers } from "./wordlists/numbers.js";
import { places } from "./wordlists/places.js";
import { timeClock } from "./wordlists/time clock.js";
import { timeScales } from "./wordlists/time scales.js";
import { transport } from "./wordlists/transport.js";
import { vegetables } from "./wordlists/vegetables.js";
import { weather } from "./wordlists/weather.js";
const masterList = [
...animals,
...basics,
...basics2,
...cakes,
...christmas,
...clothing,
...colours,
...community,
...days,
...drinks,
...emotions,
...extras,
...family,
...food,
...fruit,
...hobbies,
...home,
...illness,
...months,
...numbers,
...places,
...timeClock,
...timeScales,
...transport,
...vegetables,
...weather,
]
//https://stackoverflow.com/questions/49338193/how-to-use-code-from-script-with-type-module
window.setRandomWord = function setRandomWord() {
var randomWord = masterList[Math.floor(Math.random() * masterList.length)];
setWordCount(masterList.length);
setWordText(randomWord);
setVideo(randomWord);
setLinkUrl(randomWord);
//setFingerSpell(randomWord);
}
function setWordText(word) {
// displays the random word
const wordEle = document.getElementById("word");
wordEle.textContent = word;
}
function setVideo(word) {
// sets the video link based on the word
const lowerCaseWord = word.toLowerCase()
const primaryLink = `https://media.signbsl.com/videos/bsl/signstation/${lowerCaseWord}.mp4`;
const primaryVideoEle = document.getElementById("primary_video");
primaryVideoEle.src = primaryLink;
primaryVideoEle.className = "";
// if the word ends with s, it may be plural, so we try another video link with the final s stripped
const secondaryVideoEle = document.getElementById("secondary_video");
const secondaryWordEle = document.getElementById("secondary_word");
if (lowerCaseWord.endsWith('s')) {
// secondary word, prepare 2nd video element
const secondaryWord = lowerCaseWord.slice(0, -1);
const primaryLink = `https://media.signbsl.com/videos/bsl/signstation/${secondaryWord}.mp4`;
secondaryVideoEle.src = primaryLink;
secondaryVideoEle.className = "";
// display secondary word
secondaryWordEle.textContent = secondaryWord;
} else {
// TODO: try adding an S to make it plural?
secondaryVideoEle.className = "is-hidden";
secondaryWordEle.textContent = "";
}
}
function setLinkUrl(word) {
const linkEle = document.getElementById("link");
linkEle.href = `https://www.signbsl.com/sign/${word}`
}
function setWordCount(count) {
// displays the random word
const countEle = document.getElementById("count");
countEle.textContent = count;
}