* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
let prizesArr = ["谢谢", "奶茶", "汉堡", "咖啡", "西瓜", "鸡腿", "柠檬", "蛋糕"];
let arrBigImg = ["./img/1-beer.png", "./img/2-milk.png", "./img/3-hamburg.png",
"./img/4-coffee.png", "./img/5-watermelon.png", "./img/6-drumstick.png",
"./img/7-lemon.png", "./img/8-cake.png", "./img/9-prizes.png"];
let allPrizesLi = document.querySelectorAll('.prizes-li');
let prizesImg = document.querySelectorAll('.pic');
let count = 0;
let isClick = true;
let index = 3;
let prizesPosition = 0;
for (let j = 0;j < prizesImg.length; j++) {
prizesImg[j].src = arrBigImg[j];
}
let speed = 500;
function roll() {
speed -= 50;
if (speed <= 10) {
speed = 10;
}
for (let j = 0; j < allPrizesLi.length; j++) {
allPrizesLi[j].classList.remove('active');
}
prizesPosition++;
if (prizesPosition >= allPrizesLi.length - 1) {
prizesPosition = 0;
count++;
}
allPrizesLi[prizesPosition].classList.add('active');
let initSpeed = 500;
let timer;
let totalCount = 5;
if (count >= totalCount && (prizesPosition + 1) === index) {
clearTimeout(timer);
isClick = true;
speed = initSpeed;
timer = setTimeout(openDialog, 1000);
} else {
timer = setTimeout(roll, speed);
if (count >= totalCount - 1 || speed <= 50) {
speed += 100;
}
}
}
function startDraw() {
if (isClick) {
count = 0;
index = Math.floor(Math.random() * prizesArr.length + 1);
roll();
isClick = false;
}
}
function openDialog() {
linkObj.messageFromHtml(prizesArr[prizesPosition]);
}