logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

settings.js (973B)


  1. export default class Settings {
  2. constructor(keyBase = null) {
  3. this.keyBase = keyBase;
  4. }
  5. generateKey(id) {
  6. return this.keyBase ? [this.keyBase, `id${id}`].join('.') : id;
  7. }
  8. set(id, data) {
  9. const key = this.generateKey(id);
  10. try {
  11. const encodedData = JSON.stringify(data);
  12. localStorage.setItem(key, encodedData);
  13. return data;
  14. } catch (e) {
  15. return null;
  16. }
  17. }
  18. get(id) {
  19. const key = this.generateKey(id);
  20. try {
  21. const rawData = localStorage.getItem(key);
  22. return JSON.parse(rawData);
  23. } catch (e) {
  24. return null;
  25. }
  26. }
  27. remove(id) {
  28. const data = this.get(id);
  29. if (data) {
  30. const key = this.generateKey(id);
  31. try {
  32. localStorage.removeItem(key);
  33. } catch (e) {
  34. }
  35. }
  36. return data;
  37. }
  38. }
  39. export const pushNotificationsSetting = new Settings('mastodon_push_notification_data');
  40. export const tagHistory = new Settings('mastodon_tag_history');