Skip to content

Commit

Permalink
feat(Keyboard): Add toggle wishlist with W
Browse files Browse the repository at this point in the history
  • Loading branch information
Bamdad Sabbagh committed Apr 23, 2022
1 parent c77e51c commit 14773a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Add multiple features to <a href="https://www.bandcamp.com/">bandcamp.com</a>
- `C` copy track info
- `N` next track
- `P` previous track
- `W` toggle wishlist
- `Shift + P` play first track
- `` seek 10 sec forward
- `` seek 10 sec backward
Expand Down
8 changes: 7 additions & 1 deletion src/app/controllers/keyboard.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Keys =
| 'KeyC'
| 'KeyP'
| 'KeyN'
| 'KeyZ'
| 'ArrowUp'
| 'ArrowDown'
| 'ArrowLeft'
Expand Down Expand Up @@ -57,16 +58,21 @@ export class KeyboardController {
Space: () => BandcampFacade.getPlay().click(),
KeyP: () => BandcampFacade.getPrevious().click(),
KeyN: () => BandcampFacade.getNext().click(),
KeyZ: () => BandcampFacade.toggleWishlist(),
ArrowRight: () => BandcampFacade.seekForward(),
ArrowLeft: () => BandcampFacade.seekBackward(),
ArrowUp: () => this.controllers.volume.increaseVolume(),
ArrowDown: () => this.controllers.volume.decreaseVolume(),
};
}

private static isBody(target: EventTarget): boolean {
return target instanceof Element && target.tagName.toUpperCase() === 'BODY';
}

private static handleKeyboard() {
document.addEventListener('keydown', (e) => {
if (!(e.target instanceof Element && e.target.tagName.toUpperCase() === 'BODY')) {
if (!(this.isBody(e.target))) {
return;
}

Expand Down
13 changes: 13 additions & 0 deletions src/app/facades/bandcamp.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ export class BandcampFacade {
firstPlayButton.click();
}

public static toggleWishlist(): void {
const wishlist = document.querySelector('#collect-item');
const {className} = wishlist;

if (className.includes('wishlisted')) {
const el = wishlist.children[1] as HTMLSpanElement;
el.click();
} else if (className.includes('wishlist')) {
const el = wishlist.firstElementChild as HTMLSpanElement;
el.click();
}
}

public static rectifyMargins(): void {
const player = BandcampFacade.getPlayer();
const tracks = BandcampFacade.getTracks();
Expand Down

0 comments on commit 14773a0

Please sign in to comment.