diff --git a/scripts/Actions.ts b/scripts/Actions.ts deleted file mode 100644 index 3e20ba96..00000000 --- a/scripts/Actions.ts +++ /dev/null @@ -1,20 +0,0 @@ -export * from "./Actions/Audio" -export * from "./Actions/AnimeList" -export * from "./Actions/Diff" -export * from "./Actions/Editor" -export * from "./Actions/Explore" -export * from "./Actions/FollowUser" -export * from "./Actions/Forum" -export * from "./Actions/InfiniteScroller" -export * from "./Actions/Install" -export * from "./Actions/Like" -export * from "./Actions/Notifications" -export * from "./Actions/Object" -export * from "./Actions/Publish" -export * from "./Actions/Search" -export * from "./Actions/Serialization" -export * from "./Actions/Shop" -export * from "./Actions/SideBar" -export * from "./Actions/StatusMessage" -export * from "./Actions/Theme" -export * from "./Actions/Upload" \ No newline at end of file diff --git a/scripts/Actions/AnimeList.ts b/scripts/Actions/AnimeList.ts index 144ee075..3fbe97d5 100644 --- a/scripts/Actions/AnimeList.ts +++ b/scripts/Actions/AnimeList.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Add anime to collection export async function addAnimeToCollection(arn: AnimeNotifier, button: HTMLButtonElement) { diff --git a/scripts/Actions/Audio.ts b/scripts/Actions/Audio.ts index aac8fda8..fe3e1a3f 100644 --- a/scripts/Actions/Audio.ts +++ b/scripts/Actions/Audio.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Play audio export function playAudio(arn: AnimeNotifier, element: HTMLElement) { diff --git a/scripts/Actions/Diff.ts b/scripts/Actions/Diff.ts index b141c7c4..25079336 100644 --- a/scripts/Actions/Diff.ts +++ b/scripts/Actions/Diff.ts @@ -1,4 +1,5 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" +import { requestIdleCallback } from "../Utils" // Load export function load(arn: AnimeNotifier, element: HTMLElement) { @@ -13,7 +14,7 @@ export function diff(arn: AnimeNotifier, element: HTMLElement) { arn.diff(url) .then(() => { // Avoid instant layout thrashing - arn.requestIdleCallback(() => arn.scrollTo(element)) + requestIdleCallback(() => arn.scrollTo(element)) }) .catch(console.error) } \ No newline at end of file diff --git a/scripts/Actions/Editor.ts b/scripts/Actions/Editor.ts index f40455c9..4d530dae 100644 --- a/scripts/Actions/Editor.ts +++ b/scripts/Actions/Editor.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // newAnimeDiffIgnore export function newAnimeDiffIgnore(arn: AnimeNotifier, button: HTMLButtonElement) { diff --git a/scripts/Actions/Explore.ts b/scripts/Actions/Explore.ts index 477289de..b97ba40e 100644 --- a/scripts/Actions/Explore.ts +++ b/scripts/Actions/Explore.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" import { findAll } from "scripts/Utils"; // Filter anime on explore page diff --git a/scripts/Actions/FollowUser.ts b/scripts/Actions/FollowUser.ts index 096016a5..01a87e74 100644 --- a/scripts/Actions/FollowUser.ts +++ b/scripts/Actions/FollowUser.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Follow user export function followUser(arn: AnimeNotifier, elem: HTMLElement) { diff --git a/scripts/Actions/Forum.ts b/scripts/Actions/Forum.ts index abf73888..48d08a43 100644 --- a/scripts/Actions/Forum.ts +++ b/scripts/Actions/Forum.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Edit post export function editPost(arn: AnimeNotifier, element: HTMLElement) { diff --git a/scripts/Actions/InfiniteScroller.ts b/scripts/Actions/InfiniteScroller.ts index ef02035e..8ec05354 100644 --- a/scripts/Actions/InfiniteScroller.ts +++ b/scripts/Actions/InfiniteScroller.ts @@ -1,5 +1,5 @@ -import { AnimeNotifier } from "../AnimeNotifier" -import { Diff } from "../Diff" +import AnimeNotifier from "../AnimeNotifier" +import Diff from "../Diff" // Load more export async function loadMore(arn: AnimeNotifier, button: HTMLButtonElement) { diff --git a/scripts/Actions/Install.ts b/scripts/Actions/Install.ts index 8903d1ef..629a536b 100644 --- a/scripts/Actions/Install.ts +++ b/scripts/Actions/Install.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Chrome extension installation export function installExtension(arn: AnimeNotifier, button: HTMLElement) { diff --git a/scripts/Actions/Like.ts b/scripts/Actions/Like.ts index 61d83bbf..19c140f7 100644 --- a/scripts/Actions/Like.ts +++ b/scripts/Actions/Like.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // like export async function like(arn: AnimeNotifier, element: HTMLElement) { diff --git a/scripts/Actions/Notifications.ts b/scripts/Actions/Notifications.ts index 4296f5cd..7f833892 100644 --- a/scripts/Actions/Notifications.ts +++ b/scripts/Actions/Notifications.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Enable notifications export async function enableNotifications(arn: AnimeNotifier, button: HTMLElement) { diff --git a/scripts/Actions/Object.ts b/scripts/Actions/Object.ts index 9d57290e..2fd83df1 100644 --- a/scripts/Actions/Object.ts +++ b/scripts/Actions/Object.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // New export function newObject(arn: AnimeNotifier, button: HTMLButtonElement) { diff --git a/scripts/Actions/Publish.ts b/scripts/Actions/Publish.ts index 3e49721b..a1df337b 100644 --- a/scripts/Actions/Publish.ts +++ b/scripts/Actions/Publish.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Publish export function publish(arn: AnimeNotifier, button: HTMLButtonElement) { diff --git a/scripts/Actions/Search.ts b/scripts/Actions/Search.ts index 527330fa..91ebbb0d 100644 --- a/scripts/Actions/Search.ts +++ b/scripts/Actions/Search.ts @@ -1,5 +1,5 @@ -import { AnimeNotifier } from "../AnimeNotifier" -import { delay } from "../Utils" +import AnimeNotifier from "../AnimeNotifier" +import { delay, requestIdleCallback } from "../Utils" // Search page reference var emptySearchHTML = "" @@ -122,7 +122,7 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, e: Ke .then(showResponseInElement(arn, url, "anime", animeSearchResults)) .catch(console.error) - arn.requestIdleCallback(() => { + requestIdleCallback(() => { fetch("/_/character-search/" + term, fetchOptions) .then(showResponseInElement(arn, url, "character", characterSearchResults)) .catch(console.error) diff --git a/scripts/Actions/Serialization.ts b/scripts/Actions/Serialization.ts index 847f3978..af4e192f 100644 --- a/scripts/Actions/Serialization.ts +++ b/scripts/Actions/Serialization.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Save new data from an input field export function save(arn: AnimeNotifier, input: HTMLElement) { diff --git a/scripts/Actions/Shop.ts b/scripts/Actions/Shop.ts index 5f7a8cf1..9da14dc9 100644 --- a/scripts/Actions/Shop.ts +++ b/scripts/Actions/Shop.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Charge up export function chargeUp(arn: AnimeNotifier, button: HTMLElement) { @@ -55,7 +55,7 @@ export function buyItem(arn: AnimeNotifier, button: HTMLElement) { if(body !== "ok") { throw body } - + return arn.reloadContent() }) .then(() => arn.statusMessage.showInfo(`You bought ${itemName} for ${price} gems. Check out your inventory to confirm the purchase.`, 4000)) diff --git a/scripts/Actions/SideBar.ts b/scripts/Actions/SideBar.ts index 7547b701..fd88b30e 100644 --- a/scripts/Actions/SideBar.ts +++ b/scripts/Actions/SideBar.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Toggle sidebar export function toggleSidebar(arn: AnimeNotifier) { diff --git a/scripts/Actions/StatusMessage.ts b/scripts/Actions/StatusMessage.ts index a5f6f014..735e7ee0 100644 --- a/scripts/Actions/StatusMessage.ts +++ b/scripts/Actions/StatusMessage.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" // Close status message export function closeStatusMessage(arn: AnimeNotifier) { diff --git a/scripts/Actions/Theme.ts b/scripts/Actions/Theme.ts index 42409c3d..95ecab31 100644 --- a/scripts/Actions/Theme.ts +++ b/scripts/Actions/Theme.ts @@ -1,4 +1,4 @@ -import { AnimeNotifier } from "../AnimeNotifier" +import AnimeNotifier from "../AnimeNotifier" let currentTheme = "light" diff --git a/scripts/Actions/Upload.ts b/scripts/Actions/Upload.ts index 6b20d355..ef21d4fb 100644 --- a/scripts/Actions/Upload.ts +++ b/scripts/Actions/Upload.ts @@ -1,5 +1,5 @@ -import { AnimeNotifier } from "../AnimeNotifier" -import { StatusMessage } from "../StatusMessage" +import AnimeNotifier from "../AnimeNotifier" +import StatusMessage from "../StatusMessage" // Select file export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) { diff --git a/scripts/Actions/index.ts b/scripts/Actions/index.ts new file mode 100644 index 00000000..226d5f6f --- /dev/null +++ b/scripts/Actions/index.ts @@ -0,0 +1,20 @@ +export * from "./Audio" +export * from "./AnimeList" +export * from "./Diff" +export * from "./Editor" +export * from "./Explore" +export * from "./FollowUser" +export * from "./Forum" +export * from "./InfiniteScroller" +export * from "./Install" +export * from "./Like" +export * from "./Notifications" +export * from "./Object" +export * from "./Publish" +export * from "./Search" +export * from "./Serialization" +export * from "./Shop" +export * from "./SideBar" +export * from "./StatusMessage" +export * from "./Theme" +export * from "./Upload" \ No newline at end of file diff --git a/scripts/Analytics.ts b/scripts/Analytics.ts index 832743ab..51e01122 100644 --- a/scripts/Analytics.ts +++ b/scripts/Analytics.ts @@ -1,4 +1,4 @@ -export class Analytics { +export default class Analytics { push() { let analytics = { general: { diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index ce235368..261e6b96 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -1,19 +1,19 @@ -import { Application } from "./Application" -import { Diff } from "./Diff" -import { StatusMessage } from "./StatusMessage" -import { PushManager } from "./PushManager" -import { TouchController } from "./TouchController" -import { NotificationManager } from "./NotificationManager" -import { AudioPlayer } from "./AudioPlayer" -import { Analytics } from "./Analytics" -import { SideBar } from "./SideBar" -import { InfiniteScroller } from "./InfiniteScroller" -import { ServiceWorkerManager } from "./ServiceWorkerManager" +import Application from "./Application" +import Diff from "./Diff" +import StatusMessage from "./StatusMessage" +import PushManager from "./PushManager" +import TouchController from "./TouchController" +import NotificationManager from "./NotificationManager" +import AudioPlayer from "./AudioPlayer" +import Analytics from "./Analytics" +import SideBar from "./SideBar" +import InfiniteScroller from "./InfiniteScroller" +import ServiceWorkerManager from "./ServiceWorkerManager" import { displayAiringDate, displayDate, displayTime } from "./DateView" -import { findAll, delay, canUseWebP, swapElements } from "./Utils" +import { findAll, canUseWebP, requestIdleCallback, swapElements, delay } from "./Utils" import * as actions from "./Actions" -export class AnimeNotifier { +export default class AnimeNotifier { app: Application analytics: Analytics user: HTMLElement @@ -86,15 +86,7 @@ export class AnimeNotifier { window.addEventListener("popstate", this.onPopState.bind(this)) // Idle - this.requestIdleCallback(this.onIdle.bind(this)) - } - - requestIdleCallback(func: Function) { - if("requestIdleCallback" in window) { - window["requestIdleCallback"](func) - } else { - func() - } + requestIdleCallback(this.onIdle.bind(this)) } onReadyStateChange() { diff --git a/scripts/Application.ts b/scripts/Application.ts index 4d569723..e3ab41d8 100644 --- a/scripts/Application.ts +++ b/scripts/Application.ts @@ -1,11 +1,11 @@ -import { Diff } from "./Diff" +import Diff from "./Diff" class LoadOptions { addToHistory?: boolean forceReload?: boolean } -export class Application { +export default class Application { fadeOutClass: string activeLinkClass: string content: HTMLElement diff --git a/scripts/AudioPlayer.ts b/scripts/AudioPlayer.ts index ccc04af7..56e470e7 100644 --- a/scripts/AudioPlayer.ts +++ b/scripts/AudioPlayer.ts @@ -1,7 +1,7 @@ -import { AnimeNotifier } from "./AnimeNotifier" +import AnimeNotifier from "./AnimeNotifier" import { Anime } from "./Types/Anime" -export class AudioPlayer { +export default class AudioPlayer { arn: AnimeNotifier // Web audio diff --git a/scripts/Diff.ts b/scripts/Diff.ts index f62564d4..9105d85b 100644 --- a/scripts/Diff.ts +++ b/scripts/Diff.ts @@ -1,6 +1,6 @@ import { MutationQueue } from "./MutationQueue" -export class Diff { +export default class Diff { static persistentClasses = new Set() static persistentAttributes = new Set() diff --git a/scripts/InfiniteScroller.ts b/scripts/InfiniteScroller.ts index c2e387c5..38773bd0 100644 --- a/scripts/InfiniteScroller.ts +++ b/scripts/InfiniteScroller.ts @@ -1,4 +1,4 @@ -export class InfiniteScroller { +export default class InfiniteScroller { container: HTMLElement threshold: number diff --git a/scripts/NotificationManager.ts b/scripts/NotificationManager.ts index 4ead8aa7..783cee96 100644 --- a/scripts/NotificationManager.ts +++ b/scripts/NotificationManager.ts @@ -1,6 +1,6 @@ -import { Diff } from "./Diff" +import Diff from "./Diff" -export class NotificationManager { +export default class NotificationManager { unseen: number icon: HTMLElement counter: HTMLElement diff --git a/scripts/PushManager.ts b/scripts/PushManager.ts index 0f4195f8..03a9c54c 100644 --- a/scripts/PushManager.ts +++ b/scripts/PushManager.ts @@ -1,6 +1,6 @@ -export class PushManager { +export default class PushManager { pushSupported: boolean - + constructor() { this.pushSupported = ("serviceWorker" in navigator) && ("PushManager" in window) } @@ -52,7 +52,7 @@ export class PushManager { console.error("Subscription does not exist") return } - + await subscription.unsubscribe() this.unsubscribeOnServer(subscription, userId) diff --git a/scripts/ServiceWorkerManager.ts b/scripts/ServiceWorkerManager.ts index 404883ed..5bf38c4e 100644 --- a/scripts/ServiceWorkerManager.ts +++ b/scripts/ServiceWorkerManager.ts @@ -1,6 +1,6 @@ -import { AnimeNotifier } from "./AnimeNotifier" +import AnimeNotifier from "./AnimeNotifier" -export class ServiceWorkerManager { +export default class ServiceWorkerManager { arn: AnimeNotifier uri: string diff --git a/scripts/SideBar.ts b/scripts/SideBar.ts index 6b5ee703..e1407acd 100644 --- a/scripts/SideBar.ts +++ b/scripts/SideBar.ts @@ -1,7 +1,7 @@ -import { TouchController } from "./TouchController" -import { Diff } from "./Diff" +import TouchController from "./TouchController" +import Diff from "./Diff" -export class SideBar { +export default class SideBar { element: HTMLElement touchController: TouchController diff --git a/scripts/StatusMessage.ts b/scripts/StatusMessage.ts index adc81497..953cfb84 100644 --- a/scripts/StatusMessage.ts +++ b/scripts/StatusMessage.ts @@ -1,6 +1,6 @@ import { delay } from "./Utils" -export class StatusMessage { +export default class StatusMessage { container: HTMLElement text: HTMLElement diff --git a/scripts/TouchController.ts b/scripts/TouchController.ts index 28805da9..74accf8c 100644 --- a/scripts/TouchController.ts +++ b/scripts/TouchController.ts @@ -1,4 +1,4 @@ -export class TouchController { +export default class TouchController { x: number y: number @@ -46,7 +46,7 @@ export class TouchController { this.downSwipe() } } - + this.x = undefined this.y = undefined } diff --git a/scripts/Utils.ts b/scripts/Utils.ts deleted file mode 100644 index 8546907d..00000000 --- a/scripts/Utils.ts +++ /dev/null @@ -1,42 +0,0 @@ -export function* findAll(className: string): IterableIterator { - let elements = document.getElementsByClassName(className) - - for(let i = 0; i < elements.length; ++i) { - yield elements[i] as HTMLElement - } -} - -export function delay(millis: number, value?: T): Promise { - return new Promise(resolve => setTimeout(() => resolve(value), millis)) -} - -export function plural(count: number, singular: string): string { - return (count === 1 || count === -1) ? (count + " " + singular) : (count + " " + singular + "s") -} - -export function canUseWebP(): boolean { - return document.createElement("canvas").toDataURL("image/webp").indexOf("data:image/webp") === 0 -} - -export function swapElements(a: Node, b: Node) { - let parent = b.parentNode - let bNext = b.nextSibling - - // Special case for when a is the next sibling of b - if(bNext === a) { - // Just put a before b - parent.insertBefore(a, b) - } else { - // Insert b right before a - a.parentNode.insertBefore(b, a) - - // Now insert a where b was - if(bNext) { - // If there was an element after b, then insert a right before that - parent.insertBefore(a, bNext) - } else { - // Otherwise just append it as the last child - parent.appendChild(a) - } - } -} \ No newline at end of file diff --git a/scripts/Utils/canUseWebP.ts b/scripts/Utils/canUseWebP.ts new file mode 100644 index 00000000..d24155a1 --- /dev/null +++ b/scripts/Utils/canUseWebP.ts @@ -0,0 +1,3 @@ +export function canUseWebP(): boolean { + return document.createElement("canvas").toDataURL("image/webp").indexOf("data:image/webp") === 0 +} \ No newline at end of file diff --git a/scripts/Utils/delay.ts b/scripts/Utils/delay.ts new file mode 100644 index 00000000..3098be3e --- /dev/null +++ b/scripts/Utils/delay.ts @@ -0,0 +1,3 @@ +export function delay(millis: number, value?: T): Promise { + return new Promise(resolve => setTimeout(() => resolve(value), millis)) +} \ No newline at end of file diff --git a/scripts/Utils/findAll.ts b/scripts/Utils/findAll.ts new file mode 100644 index 00000000..1d96460a --- /dev/null +++ b/scripts/Utils/findAll.ts @@ -0,0 +1,7 @@ +export function* findAll(className: string): IterableIterator { + let elements = document.getElementsByClassName(className) + + for(let i = 0; i < elements.length; ++i) { + yield elements[i] as HTMLElement + } +} \ No newline at end of file diff --git a/scripts/Utils/index.ts b/scripts/Utils/index.ts new file mode 100644 index 00000000..4eb261ca --- /dev/null +++ b/scripts/Utils/index.ts @@ -0,0 +1,6 @@ +export * from "./canUseWebP" +export * from "./delay" +export * from "./findAll" +export * from "./plural" +export * from "./requestIdleCallback" +export * from "./swapElements" \ No newline at end of file diff --git a/scripts/Utils/plural.ts b/scripts/Utils/plural.ts new file mode 100644 index 00000000..8bb26612 --- /dev/null +++ b/scripts/Utils/plural.ts @@ -0,0 +1,3 @@ +export function plural(count: number, singular: string): string { + return (count === 1 || count === -1) ? (count + " " + singular) : (count + " " + singular + "s") +} \ No newline at end of file diff --git a/scripts/Utils/requestIdleCallback.ts b/scripts/Utils/requestIdleCallback.ts new file mode 100644 index 00000000..5b2997f6 --- /dev/null +++ b/scripts/Utils/requestIdleCallback.ts @@ -0,0 +1,7 @@ +export function requestIdleCallback(func: Function) { + if("requestIdleCallback" in window) { + window["requestIdleCallback"](func) + } else { + func() + } +} \ No newline at end of file diff --git a/scripts/Utils/swapElements.ts b/scripts/Utils/swapElements.ts new file mode 100644 index 00000000..255d8d37 --- /dev/null +++ b/scripts/Utils/swapElements.ts @@ -0,0 +1,22 @@ +export function swapElements(a: Node, b: Node) { + let parent = b.parentNode + let bNext = b.nextSibling + + // Special case for when a is the next sibling of b + if(bNext === a) { + // Just put a before b + parent.insertBefore(a, b) + } else { + // Insert b right before a + a.parentNode.insertBefore(b, a) + + // Now insert a where b was + if(bNext) { + // If there was an element after b, then insert a right before that + parent.insertBefore(a, bNext) + } else { + // Otherwise just append it as the last child + parent.appendChild(a) + } + } +} \ No newline at end of file diff --git a/scripts/main.ts b/scripts/main.ts index 4f1ab54e..eac027e8 100644 --- a/scripts/main.ts +++ b/scripts/main.ts @@ -1,5 +1,5 @@ -import { Application } from "./Application" -import { AnimeNotifier } from "./AnimeNotifier" +import Application from "./Application" +import AnimeNotifier from "./AnimeNotifier" let app = new Application() let arn = new AnimeNotifier(app) diff --git a/sw/index.d.ts b/sw/index.d.ts index f7ee7450..9ba169dc 100644 --- a/sw/index.d.ts +++ b/sw/index.d.ts @@ -654,7 +654,7 @@ interface ServiceWorkerGlobalScope extends EventTarget { interface NotificationOptions { image?: string; - data?: string; + data?: any; badge?: string; }