popup.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. console.log('popup.js is doing something');
  2. window.tempData = {
  3. temp: 'howdy temp',
  4. init() {
  5. console.log('temp init function');
  6. this.temp = 'seeya temp'
  7. },
  8. }
  9. console.log('popup.js is CONTINUING');
  10. document.addEventListener('alpine:init', () => {
  11. console.log('doing MORE');
  12. console.log('doing MORE', Alpine);
  13. Alpine.data('playlistManager', () => ({
  14. temp: "hey temp",
  15. playlists: {},
  16. init() {
  17. this.loadPlaylists();
  18. },
  19. async loadPlaylists() {
  20. try {
  21. const result = await browser.storage.local.get("playlists");
  22. console.log('LOAD RESULT', result);
  23. this.playlists = result.playlists || {};
  24. } catch (error) {
  25. console.error("Error loading playlists:", error);
  26. }
  27. },
  28. formatPlaylistName(name) {
  29. // Convert "listening-1" to "Listening - 1"
  30. return name
  31. .split('-')
  32. .map(part => part.charAt(0).toUpperCase() + part.slice(1))
  33. .join(' - ');
  34. },
  35. openVideo(url) {
  36. browser.tabs.create({ url });
  37. },
  38. async removeVideo(playlistName, index) {
  39. // Make a copy of the current playlist
  40. const playlist = [...this.playlists[playlistName]];
  41. // Remove the video at the specified index
  42. playlist.splice(index, 1);
  43. // Create an updated playlists object with the remaining playlists unchanged
  44. const updatedPlaylists = {
  45. ...this.playlists,
  46. [playlistName]: playlist
  47. };
  48. // Update the playlists in storage
  49. try {
  50. await browser.storage.local.set({ playlists: updatedPlaylists });
  51. this.playlists = updatedPlaylists;
  52. } catch (error) {
  53. console.error("Error removing video:", error);
  54. }
  55. }
  56. }));
  57. });
  58. console.log('popup.js FINISHED doing something');