Skip to content

Commit

Permalink
Add possibility to switch between profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
kieferro committed Dec 4, 2022
1 parent 2925254 commit c125d70
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ chrome.storage.sync.get('defaultBoardSwitch', function (result) {
document
.querySelector('.profile-icon.new-profile')
.addEventListener('click', addColorProfile);
document
.querySelector('#leftPicker')
.addEventListener('click', () => shiftCurrentProfile(-1));
document
.querySelector('#rightPicker')
.addEventListener('click', () => shiftCurrentProfile(1));

//Functions
function boardSwitch(toggle) {
Expand Down Expand Up @@ -388,6 +394,24 @@ function addColorProfile() {
}
}

function shiftCurrentProfile(delta) {
let listProfiles = document.querySelectorAll('.profile-icon.profile');
let n = listProfiles.length;
let currentIndex = 0;

for (let i = 0; i < n; i++) {
if (listProfiles[i].classList.contains('current')) {
listProfiles[i].classList.remove('current');
currentIndex = i;
}
}
currentIndex = (((currentIndex + delta) % n) + n) % n;
listProfiles[currentIndex].classList.add('current');

document.querySelector('#currentProfile').textContent =
'profile' + currentIndex.toString();
}

const hideBoardColorSelectors = () => {
boardColorSelector.forEach((item) => {
item.style.display = 'none';
Expand Down

0 comments on commit c125d70

Please sign in to comment.