Here is the code, how would I remove config
from it?
https://jsfiddle.net/2w19gmjo/
const videoPlayer = (function makeVideoPlayer() {
const config = {};
function loadIframeScript() {
const tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
const firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
function onYouTubeIframeAPIReady() {
const videoIds = config.videoIds;
const cover = document.querySelector(".play");
const wrapper = cover.parentElement;
const frameContainer = wrapper.querySelector(".video");
config.player = addPlayer(frameContainer, videoIds);
}
function isPlaylist(videoIds) {
return Array.isArray(videoIds) && videoIds.length;
}
function shufflePlaylist(player) {
player.setShuffle(true);
player.playVideoAt(0);
player.stopVideo();
}
function onPlayerReady(event) {
const player = event.target;
player.setVolume(100);
shufflePlaylist(player);
}
function createPlaylist(videoIds) {
return videoIds.join();
}
function createOptions(videoIds) {
const options = {
height: 360,
host: "https://www.youtube-nocookie.com",
width: 640
};
options.playerVars = {
autoplay: 0,
cc_load_policy: 0,
controls: 1,
disablekb: 1,
fs: 0,
iv_load_policy: 3,
rel: 0
};
options.events = {
"onReady": onPlayerReady
};
if (isPlaylist(videoIds)) {
options.playerVars.loop = 1;
options.playerVars.playlist = createPlaylist(videoIds);
} else {
options.videoId = videoIds;
}
return options;
}
function isVideoId(videoIds) {
return typeof videoIds === "string";
}
function getVideoId(video, videoIds) {
const videoId = video.dataset.id;
if (isVideoId(videoIds)) {
return videoIds;
}
return videoId;
}
function getVideoIds(video, ids) {
if (isPlaylist(ids)) {
return ids;
} else {
const videoId = getVideoId(video, ids);
return videoId;
}
}
function createVideoOptions(video, ids) {
const videoIds = getVideoIds(video, ids);
const options = createOptions(videoIds);
return options;
}
function addPlayer(video, ids) {
const options = createVideoOptions(video, ids);
const player = new YT.Player(video, options);
return player;
}
function play() {
const player = config.player;
if (player && player.playVideo) {
player.playVideo();
}
}
function init(videoIds) {
config.videoIds = videoIds;
loadIframeScript();
window.onYouTubeIframeAPIReady = onYouTubeIframeAPIReady;
return play;
}
return {
init,
play
};
}());
ilenia
September 21, 2022, 12:33pm
2
can’t you just delete it?
or do you want to replace it with something else?
I want to remove it entirely.
The whole thing.
const config = {};
It may need to be replaced with something else though.
ilenia
September 21, 2022, 1:24pm
4
and what do you want to obtain with that?
do you understand its current use?
Kinda, were you able to figure it out?
If not, I will give it a try, see if I can do it.
ilenia
September 23, 2022, 8:52am
6
I am not doing it for you, and if you don’t understand what it is doing I am not sure why you wrote it like that in the first place
Does this look good to you? https://jsfiddle.net/7f5qLxcd/
const videoPlayer = (function makeVideoPlayer() {
let playlist = "";
let player;
function loadIframeScript() {
const tag = document.createElement("script");
tag.src = "https://www.youtube.com/iframe_api";
const firstScriptTag = document.getElementsByTagName("script")[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
function onYouTubeIframeAPIReady() {
const cover = document.querySelector(".play");
const wrapper = cover.parentElement;
const frameContainer = wrapper.querySelector(".video");
player = addPlayer(frameContainer, playlist);
}
function isPlaylist(videoIds) {
return Array.isArray(videoIds) && videoIds.length;
}
function shufflePlaylist(player) {
player.setShuffle(true);
player.playVideoAt(0);
player.stopVideo();
}
function onPlayerReady(event) {
player = event.target;
player.setVolume(100);
shufflePlaylist(player);
}
function createPlaylist(videoIds) {
return videoIds.join();
}
function createOptions(videoIds) {
const options = {
height: 360,
host: "https://www.youtube-nocookie.com",
width: 640
};
options.playerVars = {
autoplay: 0,
cc_load_policy: 0,
controls: 1,
disablekb: 1,
fs: 0,
iv_load_policy: 3,
rel: 0
};
options.events = {
"onReady": onPlayerReady
};
if (isPlaylist(videoIds)) {
options.playerVars.loop = 1;
options.playerVars.playlist = createPlaylist(videoIds);
} else {
options.videoId = videoIds;
}
return options;
}
function isVideoId(videoIds) {
return typeof videoIds === "string";
}
function getVideoId(video, videoIds) {
const videoId = video.dataset.id;
if (isVideoId(videoIds)) {
return videoIds;
}
return videoId;
}
function getVideoIds(video, ids) {
if (isPlaylist(ids)) {
return ids;
} else {
const videoId = getVideoId(video, ids);
return videoId;
}
}
function createVideoOptions(video, ids) {
const videoIds = getVideoIds(video, ids);
const options = createOptions(videoIds);
return options;
}
function addPlayer(video, ids) {
const options = createVideoOptions(video, ids);
player = new YT.Player(video, options);
return player;
}
function play() {
if (player && player.playVideo) {
player.playVideo();
}
}
function init(videoIds) {
player = null;
loadIframeScript();
window.onYouTubeIframeAPIReady = onYouTubeIframeAPIReady;
playlist = videoIds;
return play;
}
return {
init,
play
};
}());
It looks like you took the properties that were once on the config
object and made them into their own local variables. It’s not better or worse. It’s functionally the same.
Again, reiterating what @ilenia was asking, what’s your goal in doing that?
system
Closed
March 25, 2023, 2:33am
9
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.