Refactor scripts

This commit is contained in:
2019-11-18 11:04:13 +09:00
parent 7e25ee6faf
commit 1ddcd4d570
33 changed files with 670 additions and 749 deletions

View File

@ -1,5 +1,5 @@
import requestIdleCallback from "scripts/Utils/requestIdleCallback"
import AnimeNotifier from "../AnimeNotifier"
import { requestIdleCallback } from "../Utils"
// Load
export function load(arn: AnimeNotifier, element: HTMLElement) {

View File

@ -1,5 +1,6 @@
import emptyPixel from "scripts/Utils/emptyPixel"
import findAll from "scripts/Utils/findAll"
import AnimeNotifier from "../AnimeNotifier"
import { findAll } from "scripts/Utils"
// Filter anime on explore page
export function filterAnime(arn: AnimeNotifier, _: HTMLInputElement) {
@ -12,7 +13,7 @@ export function filterAnime(arn: AnimeNotifier, _: HTMLInputElement) {
for(const element of findAll("anime-grid-image")) {
const img = element as HTMLImageElement
img.src = arn.emptyPixel()
img.src = emptyPixel
img.classList.remove("element-found")
img.classList.remove("element-color-preview")
}

View File

@ -2,24 +2,24 @@ import AnimeNotifier from "../AnimeNotifier"
// Enable notifications
export async function enableNotifications(arn: AnimeNotifier, _: HTMLElement) {
if(!arn.user || !arn.user.dataset.id) {
if(!arn.user) {
return
}
arn.statusMessage.showInfo("Enabling instant notifications...")
await arn.pushManager.subscribe(arn.user.dataset.id)
await arn.pushManager.subscribe(arn.user.id)
arn.updatePushUI()
arn.statusMessage.showInfo("Enabled instant notifications for this device.")
}
// Disable notifications
export async function disableNotifications(arn: AnimeNotifier, _: HTMLElement) {
if(!arn.user || !arn.user.dataset.id) {
if(!arn.user) {
return
}
arn.statusMessage.showInfo("Disabling instant notifications...")
await arn.pushManager.unsubscribe(arn.user.dataset.id)
await arn.pushManager.unsubscribe(arn.user.id)
arn.updatePushUI()
arn.statusMessage.showInfo("Disabled instant notifications for this device.")
}

View File

@ -1,6 +1,7 @@
import Diff from "scripts/Diff"
import delay from "scripts/Utils/delay"
import requestIdleCallback from "scripts/Utils/requestIdleCallback"
import AnimeNotifier from "../AnimeNotifier"
import { delay, requestIdleCallback } from "../Utils"
import Diff from "scripts/Diff";
// Search page reference
let emptySearchHTML = ""
@ -111,7 +112,7 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, evt?:
searchPageTitle.textContent = document.title
if(!term || term.length < 1) {
await arn.innerHTML(searchPage, emptySearchHTML)
await Diff.innerHTML(searchPage, emptySearchHTML)
arn.app.emit("DOMContentLoaded")
return
}
@ -168,7 +169,7 @@ function showResponseInElement(arn: AnimeNotifier, url: string, typeName: string
correctResponseRendered[typeName] = true
}
await arn.innerHTML(element, html)
await Diff.innerHTML(element, html)
arn.onNewContent(element)
}
}

View File

@ -1,5 +1,5 @@
import hexToHSL from "scripts/Utils/hexToHSL"
import AnimeNotifier from "../AnimeNotifier"
import { hexToHSL } from "scripts/Utils"
let currentThemeName = "light"
let previewTimeoutID: number = 0
@ -7,8 +7,8 @@ let previewTimeoutID: number = 0
// let themeWheelTimeoutID: number = 0
const themes = {
"light": {},
"dark": {
light: {},
dark: {
"link-color-h": "45",
"link-color-s": "100%",
"link-color-l": "66%",
@ -117,7 +117,7 @@ export function applyThemeAndPreview(arn: AnimeNotifier, themeName: string) {
clearTimeout(previewTimeoutID)
// If it's the free light theme or a PRO user, nothing to do here
if(currentThemeName === "light" || (arn.user && arn.user.dataset.pro == "true")) {
if(currentThemeName === "light" || (arn.user && arn.user.IsPro())) {
return
}

View File

@ -1,12 +1,13 @@
import bytesHumanReadable from "scripts/Utils/bytesHumanReadable"
import uploadWithProgress from "scripts/Utils/uploadWithProgress"
import AnimeNotifier from "../AnimeNotifier"
import { bytesHumanReadable, uploadWithProgress } from "../Utils"
// Select file
export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) {
const fileType = button.dataset.type
const endpoint = button.dataset.endpoint
if(endpoint === "/api/upload/user/cover" && arn.user && arn.user.dataset.pro !== "true") {
if(endpoint === "/api/upload/user/cover" && arn.user && !arn.user.IsPro()) {
alert("Please buy a PRO account to use this feature.")
return
}