Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
SaidRasinlic committed Apr 17, 2024
1 parent 2b544c9 commit 7a10f70
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/main.bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 17 additions & 14 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ import './assets/images/king.png';
import './assets/images/title.png';

// Declare and initialize empty ID that will hold our game ID from Local Storage
let id = '';
const id = 'clifViPYRUQYKbzRzvcV';

// Get game ID from Local Storage, if no game ID is created, create it!
window.onload = async () => {
if (!localStorage.getItem('test')) {
id = await Leaderboard.createGame();
const reGex = /(?<=Game with ID: ).+(?= )/gi;
id = id.result.match(reGex).toString();
localStorage.setItem('test', id);
} else {
id = localStorage.getItem('test');
// Load all players with name: score format
Leaderboard.load(id);
}
};
Leaderboard.load(id);

// Get game ID from Local Storage, if no game ID is created,
// This creates new game with new ID always..
// window.onload = async () => {
// if (!localStorage.getItem('test')) {
// id = await Leaderboard.createGame();
// const reGex = /(?<=Game with ID: ).+(?= )/gi;
// id = id.result.match(reGex).toString();
// localStorage.setItem('test', id);
// } else {
// id = localStorage.getItem('test');
// // Load all players with name: score format
// Leaderboard.load(id);
// }
// };

// Get DOM elements to manipulate them
const name = document.querySelector('#name');
Expand Down

0 comments on commit 7a10f70

Please sign in to comment.