|
| 1 | +import { updateSettings } from '$utils/updateSettings'; |
| 2 | +import { quranMetaData } from '$data/quranMeta'; |
| 3 | + |
| 4 | +// Set of functions for testing/debugging certain features |
| 5 | +class devTools { |
| 6 | + constructor() { |
| 7 | + if (typeof window !== 'undefined') { |
| 8 | + window.BookmarkAndNotesManager = this; |
| 9 | + } |
| 10 | + } |
| 11 | + |
| 12 | + generateRandomText(wordCount) { |
| 13 | + const words = ['Lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'sed', 'do', 'eiusmod', 'tempor', 'incididunt', 'ut', 'labore', 'et', 'dolore', 'magna', 'aliqua', 'Ut', 'enim', 'ad', 'minim', 'veniam', 'quis', 'nostrud', 'exercitation', 'ullamco', 'laboris', 'nisi']; |
| 14 | + let text = ''; |
| 15 | + for (let i = 0; i < wordCount; i++) { |
| 16 | + text += words[Math.floor(Math.random() * words.length)] + ' '; |
| 17 | + } |
| 18 | + return text.trim(); |
| 19 | + } |
| 20 | + |
| 21 | + addRandomBookmarks(count) { |
| 22 | + for (let i = 0; i < count; i++) { |
| 23 | + // Generate a random chapter number between 1 and 114 |
| 24 | + let chapterNumber = Math.floor(Math.random() * 114) + 1; |
| 25 | + |
| 26 | + // Get the maximum number of verses in the selected chapter |
| 27 | + let maxVerses = quranMetaData[chapterNumber].verses; |
| 28 | + |
| 29 | + // Generate a random verse number between 1 and maxVerses |
| 30 | + let verseNumber = Math.floor(Math.random() * maxVerses) + 1; |
| 31 | + |
| 32 | + // Create the key in the format chapter:verse |
| 33 | + let key = `${chapterNumber}:${verseNumber}`; |
| 34 | + |
| 35 | + // Add the key as a bookmark |
| 36 | + updateSettings({ type: 'userBookmarks', key: key, set: true }); |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + addRandomNotes(count) { |
| 41 | + for (let i = 0; i < count; i++) { |
| 42 | + // Generate a random chapter number between 1 and 114 |
| 43 | + let chapterNumber = Math.floor(Math.random() * 114) + 1; |
| 44 | + |
| 45 | + // Get the maximum number of verses in the selected chapter |
| 46 | + let maxVerses = quranMetaData[chapterNumber].verses; |
| 47 | + |
| 48 | + // Generate a random verse number between 1 and maxVerses |
| 49 | + let verseNumber = Math.floor(Math.random() * maxVerses) + 1; |
| 50 | + |
| 51 | + // Create the key in the format chapter:verse |
| 52 | + let key = `${chapterNumber}:${verseNumber}`; |
| 53 | + |
| 54 | + // Generate a random text of 20-30 words |
| 55 | + let notesValue = this.generateRandomText(Math.floor(Math.random() * 11) + 20); |
| 56 | + |
| 57 | + // Add the key and value as a note |
| 58 | + updateSettings({ type: 'userNotes', key: key, value: notesValue, set: true }); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + deleteBookmarks() { |
| 63 | + updateSettings({ type: 'userBookmarks', key: [], override: true }); |
| 64 | + } |
| 65 | + |
| 66 | + deleteNotes() { |
| 67 | + updateSettings({ type: 'userNotes', key: {}, override: true }); |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +// Instantiate the class to make it globally available, but only if localhost |
| 72 | +if (location.hostname === 'localhost' || location.hostname === '127.0.0.1' || location.hostname === '') { |
| 73 | + window.devTools = new devTools(); |
| 74 | +} |
0 commit comments