const renderGalleryItem = (function() {
const selectionItem = []
return function(randomNumber) {
fetch(`https://source.unsplash.com/collection/${collectionID}/${imageWidth}x${imageHeight}/?sig=${randomNumber}`)
.then((data) => {
localStorage.setItem('unsplashWall', data.url)
selectionItem.push(data.url)
})
// selectionItem.push(data.url)
// localStorage.setItem('selectionItem', JSON.stringify(selectionItem))
if ('FirstOpen' in localStorage) {
document.querySelector('#main').style.backgroundImage = 'url(' + './welcomeInstant.jpg' + ')';
} else {
if ('NopeRandomBg' in localStorage) {
document.querySelector('#main').style.backgroundImage = 'url(' + localStorage.getItem('bgImg') + ')';
} else {
localStorage.bgImg = localStorage.unsplashWall;
document.querySelector('#main').style.backgroundImage = 'url(' + localStorage.getItem('unsplashWall') + ')';
}
}
}
})()
function runOncePerDayUnsplash() {
if (!hasOneDayPassedUnsplash()) return false;
for (let i = 0; i < numItemsToGenerate; i++) {
let randomImageIndex = Math.floor(Math.random() * numImagesAvailable);
renderGalleryItem(randomImageIndex);
}
}
function runOncePerDayUnsplash() {
if (!hasOneDayPassedUnsplash()) return false;
let selectionItem = [] // <- вот здесь объяви selectionItem
function renderGalleryItem(randomNumber) {
fetch(`https://source.unsplash.com/collection/${collectionID}/${imageWidth}x${imageHeight}/?sig=${randomNumber}`)
.then((data) => {
localStorage.setItem('unsplashWall', data.url)
selectionItem.push(data.url)
})
// selectionItem.push(data.url)
// localStorage.setItem('selectionItem', JSON.stringify(selectionItem))
if ('FirstOpen' in localStorage) {
document.querySelector('#main').style.backgroundImage = 'url(' + './welcomeInstant.jpg' + ')';
} else {
if ('NopeRandomBg' in localStorage) {
document.querySelector('#main').style.backgroundImage = 'url(' + localStorage.getItem('bgImg') + ')';
} else {
localStorage.bgImg = localStorage.unsplashWall;
document.querySelector('#main').style.backgroundImage = 'url(' + localStorage.getItem('unsplashWall') + ')';
}
}
}
for (let i = 0; i < numItemsToGenerate; i++) {
let randomImageIndex = Math.floor(Math.random() * numImagesAvailable);
renderGalleryItem(randomImageIndex);
}
}
function loadImage(collectionID, imageWidth, imageHeight, randomNumber) {
let selectionItem = []
fetch(`https://source.unsplash.com/collection/${collectionID}/${imageWidth}x${imageHeight}/?sig=${randomNumber}`)
.then((data) => {
localStorage.setItem('unsplashWall', data.url)
selectionItem.push(data.url)
localStorage.setItem('selectionItem', JSON.stringify(selectionItem))
})
}
loadImage(42, 420, 420, 777)
обязательно ли для замыкания возвращать функцию или достаточно лишь открывающие и закрывающие кавычки самой функции.