We would like to have a way to reset the prize and spin the wheel every day
Hi there, @Tuna_Homestay ![]()
Sounds interesting! If this request becomes popular, it might be considered in the future ![]()
Guys, if youâd like to implement this feature for your widget, itâs possible to do this with the custom code.
Just let us know in the comment and our devs will be happy to help!
Yes, I would like the wheel to automatically reset on a daily or even hourly basis, allowing users to spin again after each transaction. Could you please assist us with setting this up?
Hi there, @Evaldas_Einikis ![]()
Please add this code to the Custom JS field on the Settings tab of your widgetâs settings:
const WIDGET_ID = 'YOUR_WIDGET_ID';
const LOCAL_STORAGE_SELECTOR = `SpinningWheel.winningRewardId.${WIDGET_ID}`;
const SESSION_STORAGE_SELECTOR = `elfsight-spinning-wheel-${WIDGET_ID}`;
const RESET_AFTER_HOURS = 15;
const waitForElement = (selector, root = document) =>
new Promise((res) => {
let i = 0;
const check = () => {
const component = root.querySelector(selector);
if (component) {
res(component);
} else if (i !== 50) {
setTimeout(check, 100);
i++;
}
};
check();
});
waitForElement(`.elfsight-app-${WIDGET_ID}`).then(() => {
const lsValue = localStorage.getItem(LOCAL_STORAGE_SELECTOR);
if (!lsValue) {
return;
}
try {
const parsedValue = JSON.parse(lsValue);
if (
parsedValue &&
typeof parsedValue === 'object' &&
typeof parsedValue.value === 'string' &&
typeof parsedValue.timestamp === 'number'
) {
const currentTimestamp = Math.floor(Date.now() / 1000);
const timestamp = parsedValue.timestamp;
const resetThreshold = RESET_AFTER_HOURS * 60 * 60;
if (currentTimestamp - timestamp >= resetThreshold) {
localStorage.removeItem(LOCAL_STORAGE_SELECTOR);
sessionStorage.removeItem(SESSION_STORAGE_SELECTOR);
}
}
} catch (e) {
console.error('Error parsing localStorage value:', e);
}
});
Note: This code resets the prize on daily basis.
Replace YOUR_WIDGET_ID in the 1st line of the code with the ID of your widget and let me know if it helped ![]()
Hello Max,
The code brings the following error. If there is a bigger problem with both requirements, for now it would be sufficient for us to solve just the wheel reset problem so we can go live. Can you advise us on the code please.
Line 24: âcontainerâ is defined but never used.
const WIDGET_ID = â8d7bf735-5ce7-4900-9d1d-5e993c88f399â;
const LOCAL_STORAGE_SELECTOR = SpinningWheel.winningRewardId.${WIDGET_ID};
const SESSION_STORAGE_SELECTOR = elfsight-spinning-wheel-${WIDGET_ID};
const RESET_AFTER_HOURS = 24;
const waitForElement = (selector, root = document) =>
new Promise((res) => {
let i = 0;
const check = () => {
const component = root.querySelector(selector);
if (component) {
res(component);
} else if (i !== 50) {
setTimeout(check, 100);
i++;
}
};
check();
});
waitForElement(.elfsight-app-${WIDGET_ID}).then((container) => {
const lsValue = localStorage.getItem(LOCAL_STORAGE_SELECTOR);
if (!lsValue) {
return;
}
try {
const parsedValue = JSON.parse(lsValue);
if (
parsedValue &&
typeof parsedValue === âobjectâ &&
typeof parsedValue.value === âstringâ &&
typeof parsedValue.timestamp === ânumberâ
) {
const currentTimestamp = Math.floor(Date.now() / 1000);
const timestamp = parsedValue.timestamp;
const resetThreshold = RESET_AFTER_HOURS * 60 * 60;
if (currentTimestamp - timestamp >= resetThreshold) {
localStorage.removeItem(LOCAL_STORAGE_SELECTOR);
sessionStorage.removeItem(SESSION_STORAGE_SELECTOR);
}
}
} catch (e) {
console.error(âError parsing localStorage value:â, e);
}
});
This error doesnât affect anything and everything should be working fine. However, weâve adjusted the code and this error wonât appear anymore:
const WIDGET_ID = '8d7bf735-5ce7-4900-9d1d-5e993c88f399';
const LOCAL_STORAGE_SELECTOR = `SpinningWheel.winningRewardId.${WIDGET_ID}`;
const SESSION_STORAGE_SELECTOR = `elfsight-spinning-wheel-${WIDGET_ID}`;
const RESET_AFTER_HOURS = 15;
const waitForElement = (selector, root = document) =>
new Promise((res) => {
let i = 0;
const check = () => {
const component = root.querySelector(selector);
if (component) {
res(component);
} else if (i !== 50) {
setTimeout(check, 100);
i++;
}
};
check();
});
waitForElement(`.elfsight-app-${WIDGET_ID}`).then(() => {
const lsValue = localStorage.getItem(LOCAL_STORAGE_SELECTOR);
if (!lsValue) {
return;
}
try {
const parsedValue = JSON.parse(lsValue);
if (
parsedValue &&
typeof parsedValue === 'object' &&
typeof parsedValue.value === 'string' &&
typeof parsedValue.timestamp === 'number'
) {
const currentTimestamp = Math.floor(Date.now() / 1000);
const timestamp = parsedValue.timestamp;
const resetThreshold = RESET_AFTER_HOURS * 60 * 60;
if (currentTimestamp - timestamp >= resetThreshold) {
localStorage.removeItem(LOCAL_STORAGE_SELECTOR);
sessionStorage.removeItem(SESSION_STORAGE_SELECTOR);
}
}
} catch (e) {
console.error('Error parsing localStorage value:', e);
}
});
Please check it out and let me know if it worked ![]()
Hi, I implemented the code and set the reset 1 hour:
RESET_AFTER_HOURS = 1; After more than one hour I still could not spin the wheel.
Evaldas
Hello Max,
no it is working. Maybe some time needed to pass. Thanks a lot.
Great, youâre welcome ![]()
Hello Max, what can I do if there is no Custom JS field and only a Custom CSS code field?
Hi @mystaceous ![]()
Custom JS field is available in all widgets, including yours. You can find it on the Settings tab ![]()
Sorry about that, I was looking at options within my website, not the app. I appreciate the help!
No problem!
Youâre always welcome ![]()
How do i configure it so it resets every month? Please and thank you.
Hi there, @Texas_Nights ![]()
This code will help you reset the prize monthly:
const WIDGET_ID = 'YOUR_WIDGET_ID';
const LOCAL_STORAGE_SELECTOR = `SpinningWheel.winningRewardId.${WIDGET_ID}`;
const SESSION_STORAGE_SELECTOR = `elfsight-spinning-wheel-${WIDGET_ID}`;
const waitForElement = (selector, root = document) =>
new Promise((res) => {
let i = 0;
const check = () => {
const component = root.querySelector(selector);
if (component) {
res(component);
} else if (i !== 50) {
setTimeout(check, 100);
i++;
}
};
check();
});
waitForElement(`.elfsight-app-${WIDGET_ID}`).then(() => {
const lsValue = localStorage.getItem(LOCAL_STORAGE_SELECTOR);
if (!lsValue) {
return;
}
try {
const parsedValue = JSON.parse(lsValue);
if (
parsedValue &&
typeof parsedValue === 'object' &&
typeof parsedValue.value === 'string' &&
typeof parsedValue.timestamp === 'number'
) {
const currentDate = new Date();
const storedDate = new Date(parsedValue.timestamp * 1000);
// ĐŃĐŸĐČĐ”ŃŃĐ”ĐŒ, ĐžĐ·ĐŒĐ”ĐœĐžĐ»ŃŃ Đ»Đž ĐŒĐ”ŃŃŃ
if (
currentDate.getFullYear() !== storedDate.getFullYear() ||
currentDate.getMonth() !== storedDate.getMonth()
) {
localStorage.removeItem(LOCAL_STORAGE_SELECTOR);
sessionStorage.removeItem(SESSION_STORAGE_SELECTOR);
}
}
} catch (e) {
console.error('Error parsing localStorage value:', e);
}
});
Do not forget to replace YOUR_WIDGET_ID in the 1st line of the code with the ID of your widget ![]()
