Use const variables when applicable

This commit is contained in:
2019-11-17 18:25:14 +09:00
parent 454e8572e3
commit 878f1913e3
39 changed files with 405 additions and 403 deletions

View File

@ -4,22 +4,22 @@ import AnimeNotifier from "../AnimeNotifier"
export async function addAnimeToCollection(arn: AnimeNotifier, button: HTMLButtonElement) {
button.disabled = true
let {animeId} = button.dataset
const {animeId} = button.dataset
if(!animeId) {
console.error("Button without anime ID:", button)
return
}
let apiEndpoint = arn.findAPIEndpoint(button)
const apiEndpoint = arn.findAPIEndpoint(button)
try {
await arn.post(apiEndpoint + "/add/" + animeId)
arn.reloadContent()
// Show status message
let response = await fetch("/api/anime/" + animeId)
let anime = await response.json()
const response = await fetch("/api/anime/" + animeId)
const anime = await response.json()
arn.statusMessage.showInfo(`Added ${anime.title.canonical} to your collection.`)
} catch(err) {
arn.statusMessage.showError(err)
@ -33,15 +33,15 @@ export async function removeAnimeFromCollection(arn: AnimeNotifier, button: HTML
}
button.textContent = "Removing..."
let {animeId, nick} = button.dataset
const {animeId, nick} = button.dataset
if(!animeId || !nick) {
console.error("Button without nick or anime ID:", button)
return
}
let apiEndpoint = arn.findAPIEndpoint(button)
let status = document.getElementById("Status") as HTMLSelectElement
const apiEndpoint = arn.findAPIEndpoint(button)
const status = document.getElementById("Status") as HTMLSelectElement
try {
await arn.post(apiEndpoint + "/remove/" + animeId)
@ -58,7 +58,7 @@ export async function deleteAnimeList(arn: AnimeNotifier, button: HTMLElement) {
}
button.textContent = "Deleting..."
let {returnPath} = button.dataset
const {returnPath} = button.dataset
if(!returnPath) {
console.error("Button without data-return-path:", button)

View File

@ -2,7 +2,7 @@ import AnimeNotifier from "../AnimeNotifier"
// Play audio
export function playAudio(arn: AnimeNotifier, element: HTMLElement) {
let {mediaId, audioSrc} = element.dataset
const {mediaId, audioSrc} = element.dataset
if(!mediaId || !audioSrc) {
console.error("Invalid media ID or audio source:", element)
@ -39,7 +39,7 @@ export async function playNextTrack(arn: AnimeNotifier) {
// Set volume
export function setVolume(arn: AnimeNotifier, element: HTMLInputElement) {
let volume = parseFloat(element.value) / 100.0
const volume = parseFloat(element.value) / 100.0
arn.audioPlayer.setVolume(volume)
}

View File

@ -3,7 +3,7 @@ import { requestIdleCallback } from "../Utils"
// Load
export function load(arn: AnimeNotifier, element: HTMLElement) {
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
const url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
if(!url) {
arn.statusMessage.showError("Link doesn't have a target")
@ -15,7 +15,7 @@ export function load(arn: AnimeNotifier, element: HTMLElement) {
// Diff
export async function diff(arn: AnimeNotifier, element: HTMLElement) {
let url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
const url = element.dataset.url || (element as HTMLAnchorElement).getAttribute("href")
if(!url) {
arn.statusMessage.showError("Link doesn't have a target")

View File

@ -6,8 +6,8 @@ export async function newAnimeDiffIgnore(arn: AnimeNotifier, button: HTMLButtonE
return
}
let id = button.dataset.id
let hash = button.dataset.hash
const id = button.dataset.id
const hash = button.dataset.hash
try {
await arn.post(`/api/new/ignoreanimedifference`, {
@ -27,15 +27,15 @@ export async function importKitsuAnime(arn: AnimeNotifier, button: HTMLButtonEle
return
}
let newTab = window.open()
const newTab = window.open()
if(!newTab) {
arn.statusMessage.showError("Error opening new tab")
return
}
let animeId = button.dataset.id
let response = await fetch(`/api/import/kitsu/anime/${animeId}`, {
const animeId = button.dataset.id
const response = await fetch(`/api/import/kitsu/anime/${animeId}`, {
method: "POST",
credentials: "same-origin"
})
@ -54,22 +54,22 @@ export async function deleteKitsuAnime(arn: AnimeNotifier, button: HTMLButtonEle
return
}
let animeId = button.dataset.id
const animeId = button.dataset.id
await arn.post(`/api/delete/kitsu/anime/${animeId}`)
arn.reloadContent()
}
// Multi-search anime
export async function multiSearchAnime(arn: AnimeNotifier, textarea: HTMLTextAreaElement) {
let results = document.getElementById("multi-search-anime") as HTMLDivElement
let animeTitles = textarea.value.split("\n")
const results = document.getElementById("multi-search-anime") as HTMLDivElement
const animeTitles = textarea.value.split("\n")
results.innerHTML = ""
for(let i = 0; i < animeTitles.length; i++) {
console.log(animeTitles[i])
let response = await fetch("/_/anime-search/" + animeTitles[i])
let html = await response.text()
const response = await fetch("/_/anime-search/" + animeTitles[i])
const html = await response.text()
results.innerHTML += "<h3>" + animeTitles[i] + "</h3>" + html
}
@ -79,7 +79,7 @@ export async function multiSearchAnime(arn: AnimeNotifier, textarea: HTMLTextAre
// Download soundtrack file
export async function downloadSoundTrackFile(arn: AnimeNotifier, button: HTMLButtonElement) {
let id = button.dataset.id
const id = button.dataset.id
try {
await arn.post(`/api/soundtrack/${id}/download`)
@ -96,7 +96,7 @@ export async function startJob(arn: AnimeNotifier, button: HTMLButtonElement) {
return
}
let jobName = button.dataset.job
const jobName = button.dataset.job
if(!confirm(`Are you sure you want to start the "${jobName}" job?`)) {
return

View File

@ -3,24 +3,24 @@ import { findAll } from "scripts/Utils"
// Filter anime on explore page
export function filterAnime(arn: AnimeNotifier, _: HTMLInputElement) {
let root = document.getElementById("filter-root") as HTMLElement
const root = document.getElementById("filter-root") as HTMLElement
let elementYear = document.getElementById("filter-year") as HTMLSelectElement
let elementSeason = document.getElementById("filter-season") as HTMLSelectElement
let elementStatus = document.getElementById("filter-status") as HTMLSelectElement
let elementType = document.getElementById("filter-type") as HTMLSelectElement
const elementYear = document.getElementById("filter-year") as HTMLSelectElement
const elementSeason = document.getElementById("filter-season") as HTMLSelectElement
const elementStatus = document.getElementById("filter-status") as HTMLSelectElement
const elementType = document.getElementById("filter-type") as HTMLSelectElement
for(let element of findAll("anime-grid-image")) {
let img = element as HTMLImageElement
for(const element of findAll("anime-grid-image")) {
const img = element as HTMLImageElement
img.src = arn.emptyPixel()
img.classList.remove("element-found")
img.classList.remove("element-color-preview")
}
let year = elementYear.value || "any"
let season = elementSeason.value || "any"
let status = elementStatus.value || "any"
let type = elementType.value || "any"
const year = elementYear.value || "any"
const season = elementSeason.value || "any"
const status = elementStatus.value || "any"
const type = elementType.value || "any"
arn.diff(`${root.dataset.url}/${year}/${season}/${status}/${type}`)
}
@ -32,7 +32,7 @@ export function toggleHideAddedAnime() {
// Hides anime that are already in your list.
export function hideAddedAnime() {
for(let anime of findAll("anime-grid-cell")) {
for(const anime of findAll("anime-grid-cell")) {
if(anime.dataset.added !== "true") {
continue
}
@ -43,7 +43,7 @@ export function hideAddedAnime() {
// Hides anime that are not in your list.
export async function calendarShowAddedAnimeOnly(arn: AnimeNotifier, element: HTMLInputElement) {
let calendar = document.getElementById("calendar")
const calendar = document.getElementById("calendar")
if(!calendar || calendar.dataset.showAddedAnimeOnly === undefined) {
return
@ -57,8 +57,8 @@ export async function calendarShowAddedAnimeOnly(arn: AnimeNotifier, element: HT
}
// Save the state in the database
let showAddedAnimeOnly = calendar.dataset.showAddedAnimeOnly === "true"
let apiEndpoint = arn.findAPIEndpoint(element)
const showAddedAnimeOnly = calendar.dataset.showAddedAnimeOnly === "true"
const apiEndpoint = arn.findAPIEndpoint(element)
try {
await arn.post(apiEndpoint, {

View File

@ -2,22 +2,22 @@ import AnimeNotifier from "../AnimeNotifier"
// Edit post
export function editPost(_: AnimeNotifier, element: HTMLElement) {
let postId = element.dataset.id
const postId = element.dataset.id
if(!postId) {
console.error("Post missing post ID:", postId)
return
}
let render = document.getElementById("render-" + postId) as HTMLElement
let source = document.getElementById("source-" + postId) as HTMLElement
let edit = document.getElementById("edit-toolbar-" + postId) as HTMLElement
const render = document.getElementById("render-" + postId) as HTMLElement
const source = document.getElementById("source-" + postId) as HTMLElement
const edit = document.getElementById("edit-toolbar-" + postId) as HTMLElement
render.classList.toggle("hidden")
source.classList.toggle("hidden")
edit.classList.toggle("hidden")
let title = document.getElementById("title-" + postId)
const title = document.getElementById("title-" + postId)
if(title) {
title.classList.toggle("hidden")
@ -26,12 +26,12 @@ export function editPost(_: AnimeNotifier, element: HTMLElement) {
// Save post
export async function savePost(arn: AnimeNotifier, element: HTMLElement) {
let postId = element.dataset.id
let source = document.getElementById("source-" + postId) as HTMLTextAreaElement
let title = document.getElementById("title-" + postId) as HTMLInputElement
let text = source.value
const postId = element.dataset.id
const source = document.getElementById("source-" + postId) as HTMLTextAreaElement
const title = document.getElementById("title-" + postId) as HTMLInputElement
const text = source.value
let updates: any = {
const updates: any = {
Text: text,
}
@ -40,7 +40,7 @@ export async function savePost(arn: AnimeNotifier, element: HTMLElement) {
updates.Title = title.value
}
let apiEndpoint = arn.findAPIEndpoint(element)
const apiEndpoint = arn.findAPIEndpoint(element)
try {
await arn.post(apiEndpoint, updates)
@ -56,7 +56,7 @@ export async function deletePost(arn: AnimeNotifier, element: HTMLElement) {
return
}
let endpoint = arn.findAPIEndpoint(element)
const endpoint = arn.findAPIEndpoint(element)
try {
await arn.post(endpoint + "/delete")
@ -68,10 +68,10 @@ export async function deletePost(arn: AnimeNotifier, element: HTMLElement) {
// Create post
export async function createPost(arn: AnimeNotifier, element: HTMLElement) {
let textarea = document.getElementById("new-post-text") as HTMLTextAreaElement
let {parentId, parentType} = element.dataset
const textarea = document.getElementById("new-post-text") as HTMLTextAreaElement
const {parentId, parentType} = element.dataset
let post = {
const post = {
text: textarea.value,
parentId,
parentType,
@ -89,11 +89,11 @@ export async function createPost(arn: AnimeNotifier, element: HTMLElement) {
// Create thread
export async function createThread(arn: AnimeNotifier) {
let title = document.getElementById("title") as HTMLInputElement
let text = document.getElementById("text") as HTMLTextAreaElement
let category = document.getElementById("tag") as HTMLInputElement
const title = document.getElementById("title") as HTMLInputElement
const text = document.getElementById("text") as HTMLTextAreaElement
const category = document.getElementById("tag") as HTMLInputElement
let thread = {
const thread = {
title: title.value,
text: text.value,
tags: [category.value]
@ -109,9 +109,9 @@ export async function createThread(arn: AnimeNotifier) {
// Reply to a post
export async function reply(arn: AnimeNotifier, element: HTMLElement) {
let apiEndpoint = arn.findAPIEndpoint(element)
let repliesId = `replies-${element.dataset.postId}`
let replies = document.getElementById(repliesId)
const apiEndpoint = arn.findAPIEndpoint(element)
const repliesId = `replies-${element.dataset.postId}`
const replies = document.getElementById(repliesId)
if(!replies) {
console.error("Missing replies container:", element)
@ -119,14 +119,14 @@ export async function reply(arn: AnimeNotifier, element: HTMLElement) {
}
// Delete old reply area
let oldReplyArea = document.getElementById("new-post")
const oldReplyArea = document.getElementById("new-post")
if(oldReplyArea) {
oldReplyArea.remove()
}
// Delete old reply button
let oldPostActions = document.getElementsByClassName("new-post-actions")[0]
const oldPostActions = document.getElementsByClassName("new-post-actions")[0]
if(oldPostActions) {
oldPostActions.remove()
@ -134,8 +134,8 @@ export async function reply(arn: AnimeNotifier, element: HTMLElement) {
// Fetch new reply UI
try {
let response = await fetch(`${apiEndpoint}/reply/ui`)
let html = await response.text()
const response = await fetch(`${apiEndpoint}/reply/ui`)
const html = await response.text()
replies.innerHTML = html + replies.innerHTML
arn.onNewContent(replies)
arn.assignActions()
@ -161,13 +161,13 @@ export function unlockThread(arn: AnimeNotifier, element: HTMLButtonElement) {
// Set thread locked state
async function setThreadLock(arn: AnimeNotifier, element: HTMLButtonElement, state: boolean) {
let verb = state ? "lock" : "unlock"
const verb = state ? "lock" : "unlock"
if(!confirm(`Are you sure you want to ${verb} this Thread?`)) {
return
}
let endpoint = arn.findAPIEndpoint(element)
const endpoint = arn.findAPIEndpoint(element)
try {
await arn.post(`${endpoint}/${verb}`)

View File

@ -6,7 +6,7 @@ export async function join(arn: AnimeNotifier, element: HTMLElement) {
return
}
let apiEndpoint = arn.findAPIEndpoint(element)
const apiEndpoint = arn.findAPIEndpoint(element)
try {
await arn.post(`${apiEndpoint}/join`)
@ -23,7 +23,7 @@ export async function leave(arn: AnimeNotifier, element: HTMLElement) {
return
}
let apiEndpoint = arn.findAPIEndpoint(element)
const apiEndpoint = arn.findAPIEndpoint(element)
try {
await arn.post(`${apiEndpoint}/leave`)

View File

@ -17,10 +17,10 @@ export async function loadMore(arn: AnimeNotifier, button: HTMLButtonElement) {
arn.loading(true)
button.disabled = true
let index = button.dataset.index
const index = button.dataset.index
try {
let response = await fetch("/_" + arn.app.currentPath + "/from/" + index, {
const response = await fetch("/_" + arn.app.currentPath + "/from/" + index, {
credentials: "same-origin"
})
@ -28,7 +28,7 @@ export async function loadMore(arn: AnimeNotifier, button: HTMLButtonElement) {
throw response.statusText
}
let newIndex = response.headers.get("X-LoadMore-Index")
const newIndex = response.headers.get("X-LoadMore-Index")
// End of data?
if(!newIndex || newIndex === "-1") {
@ -39,7 +39,7 @@ export async function loadMore(arn: AnimeNotifier, button: HTMLButtonElement) {
}
// Get the HTML response
let html = await response.text()
const html = await response.text()
// Add the HTML to the existing target
Diff.mutations.queue(() => {

View File

@ -3,7 +3,7 @@ import AnimeNotifier from "../AnimeNotifier"
// like
export async function like(arn: AnimeNotifier, element: HTMLElement) {
arn.statusMessage.showInfo("Liked!", 1000)
let apiEndpoint = arn.findAPIEndpoint(element)
const apiEndpoint = arn.findAPIEndpoint(element)
try {
await arn.post(apiEndpoint + "/like")
@ -16,7 +16,7 @@ export async function like(arn: AnimeNotifier, element: HTMLElement) {
// unlike
export async function unlike(arn: AnimeNotifier, element: HTMLElement) {
arn.statusMessage.showInfo("Disliked!", 1000)
let apiEndpoint = arn.findAPIEndpoint(element)
const apiEndpoint = arn.findAPIEndpoint(element)
try {
await arn.post(apiEndpoint + "/unlike")

View File

@ -2,7 +2,7 @@ import AnimeNotifier from "../AnimeNotifier"
// New
export async function newObject(arn: AnimeNotifier, button: HTMLButtonElement) {
let dataType = button.dataset.type
const dataType = button.dataset.type
if(!dataType) {
console.error("Missing data type:", button)
@ -10,13 +10,13 @@ export async function newObject(arn: AnimeNotifier, button: HTMLButtonElement) {
}
try {
let response = await arn.post(`/api/new/${dataType}`)
const response = await arn.post(`/api/new/${dataType}`)
if(!response) {
throw `Failed creating ${dataType}`
}
let json = await response.json()
const json = await response.json()
await arn.app.load(`/${dataType}/${json.id}/edit`)
} catch(err) {
arn.statusMessage.showError(err)
@ -25,8 +25,8 @@ export async function newObject(arn: AnimeNotifier, button: HTMLButtonElement) {
// Delete
export async function deleteObject(arn: AnimeNotifier, button: HTMLButtonElement) {
let confirmType = button.dataset.confirmType
let returnPath = button.dataset.returnPath
const confirmType = button.dataset.confirmType
const returnPath = button.dataset.returnPath
if(!confirm(`Are you sure you want to delete this ${confirmType}?`)) {
return
@ -39,7 +39,7 @@ export async function deleteObject(arn: AnimeNotifier, button: HTMLButtonElement
}
}
let endpoint = arn.findAPIEndpoint(button)
const endpoint = arn.findAPIEndpoint(button)
try {
await arn.post(endpoint + "/delete")

View File

@ -2,7 +2,7 @@ import AnimeNotifier from "../AnimeNotifier"
// Publish
export async function publish(arn: AnimeNotifier, button: HTMLButtonElement) {
let endpoint = arn.findAPIEndpoint(button)
const endpoint = arn.findAPIEndpoint(button)
try {
await arn.post(endpoint + "/publish")
@ -14,7 +14,7 @@ export async function publish(arn: AnimeNotifier, button: HTMLButtonElement) {
// Unpublish
export async function unpublish(arn: AnimeNotifier, button: HTMLButtonElement) {
let endpoint = arn.findAPIEndpoint(button)
const endpoint = arn.findAPIEndpoint(button)
try {
await arn.post(endpoint + "/unpublish")

View File

@ -3,10 +3,10 @@ import { delay, requestIdleCallback } from "../Utils"
import Diff from "scripts/Diff";
// Search page reference
var emptySearchHTML = ""
var searchPage: HTMLElement
var searchPageTitle: HTMLElement
var correctResponseRendered = {
let emptySearchHTML = ""
let searchPage: HTMLElement
let searchPageTitle: HTMLElement
const correctResponseRendered = {
"anime": false,
"character": false,
"posts": false,
@ -18,13 +18,13 @@ var correctResponseRendered = {
}
// Search types
var searchTypes = Object.keys(correctResponseRendered)
const searchTypes = Object.keys(correctResponseRendered)
// Save old term to compare
var oldTerm = ""
let oldTerm = ""
// Containers for all the search results
var results = new Map<string, HTMLElement>()
const results = new Map<string, HTMLElement>()
// Delay before a request is sent
const searchDelay = 140
@ -44,10 +44,10 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, evt?:
}
// Determine if we're already seeing the search page
let searchPageActivated = (searchPage === arn.app.content.children[0])
const searchPageActivated = (searchPage === arn.app.content.children[0])
// Check if the search term really changed
let term = search.value.trim()
const term = search.value.trim()
if(term === oldTerm && searchPageActivated) {
return
@ -56,12 +56,12 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, evt?:
oldTerm = term
// Reset
for(let key of searchTypes) {
for(const key of searchTypes) {
correctResponseRendered[key] = false
}
// Set browser URL
let url = "/search/" + term
const url = "/search/" + term
document.title = "Search: " + term
arn.app.currentPath = url
@ -74,7 +74,7 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, evt?:
try {
// Fetch empty search frame if needed
if(emptySearchHTML === "") {
let response = await fetch("/_/empty-search")
const response = await fetch("/_/empty-search")
emptySearchHTML = await response.text()
}
@ -101,7 +101,7 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, evt?:
}
if(!results["anime"]) {
for(let key of searchTypes) {
for(const key of searchTypes) {
results[key] = document.getElementById(`${key}-search-results`)
}
@ -128,7 +128,7 @@ export async function search(arn: AnimeNotifier, search: HTMLInputElement, evt?:
}
// Search the other types (everything except anime)
for(let key of searchTypes) {
for(const key of searchTypes) {
if(key === "anime") {
continue
}
@ -151,7 +151,7 @@ function showResponseInElement(arn: AnimeNotifier, url: string, typeName: string
throw response.statusText
}
let html = await response.text()
const html = await response.text()
if(html.includes("no-search-results")) {
Diff.mutations.queue(() => (element.parentElement as HTMLElement).classList.add("search-section-disabled"))
@ -179,10 +179,10 @@ export function searchBySpeech(arn: AnimeNotifier, element: HTMLElement) {
return
}
let searchInput = document.getElementById("search") as HTMLInputElement
let oldPlaceholder = searchInput.placeholder
const searchInput = document.getElementById("search") as HTMLInputElement
const oldPlaceholder = searchInput.placeholder
let SpeechRecognition: any = window["SpeechRecognition"] || window["webkitSpeechRecognition"]
const SpeechRecognition: any = window["SpeechRecognition"] || window["webkitSpeechRecognition"]
recognition = new SpeechRecognition()
recognition.continuous = false
recognition.interimResults = false
@ -190,8 +190,8 @@ export function searchBySpeech(arn: AnimeNotifier, element: HTMLElement) {
recognition.onresult = evt => {
if(evt.results.length > 0) {
let result = evt.results.item(0).item(0)
let term = result.transcript
const result = evt.results.item(0).item(0)
const term = result.transcript
if(term !== "") {
searchInput.value = term

View File

@ -8,8 +8,8 @@ export async function save(arn: AnimeNotifier, input: HTMLElement) {
return
}
let obj = {}
let isContentEditable = input.isContentEditable
const obj = {}
const isContentEditable = input.isContentEditable
let value = isContentEditable ? input.textContent : (input as HTMLInputElement).value
if(value === undefined || value === null) {
@ -35,7 +35,7 @@ export async function save(arn: AnimeNotifier, input: HTMLElement) {
(input as HTMLInputElement).disabled = true
}
let apiEndpoint = arn.findAPIEndpoint(input)
const apiEndpoint = arn.findAPIEndpoint(input)
try {
await arn.post(apiEndpoint, obj)
@ -71,8 +71,8 @@ export async function enable(arn: AnimeNotifier, button: HTMLButtonElement) {
return
}
let obj = {}
let apiEndpoint = arn.findAPIEndpoint(button)
const obj = {}
const apiEndpoint = arn.findAPIEndpoint(button)
obj[button.dataset.field] = true
button.disabled = true
@ -99,8 +99,8 @@ export async function disable(arn: AnimeNotifier, button: HTMLButtonElement) {
return
}
let obj = {}
let apiEndpoint = arn.findAPIEndpoint(button)
const obj = {}
const apiEndpoint = arn.findAPIEndpoint(button)
obj[button.dataset.field] = false
button.disabled = true
@ -122,9 +122,9 @@ export async function disable(arn: AnimeNotifier, button: HTMLButtonElement) {
// Append new element to array
export async function arrayAppend(arn: AnimeNotifier, element: HTMLElement) {
let field = element.dataset.field
let object = element.dataset.object || ""
let apiEndpoint = arn.findAPIEndpoint(element)
const field = element.dataset.field
const object = element.dataset.object || ""
const apiEndpoint = arn.findAPIEndpoint(element)
try {
await arn.post(apiEndpoint + "/field/" + field + "/append", object)
@ -140,9 +140,9 @@ export async function arrayRemove(arn: AnimeNotifier, element: HTMLElement) {
return
}
let field = element.dataset.field
let index = element.dataset.index
let apiEndpoint = arn.findAPIEndpoint(element)
const field = element.dataset.field
const index = element.dataset.index
const apiEndpoint = arn.findAPIEndpoint(element)
try {
await arn.post(apiEndpoint + "/field/" + field + "/remove/" + index)
@ -158,14 +158,14 @@ export function increaseEpisode(arn: AnimeNotifier, element: HTMLElement) {
return
}
let prev = element.previousSibling
const prev = element.previousSibling
if(prev === null || !(prev instanceof HTMLElement) || prev.textContent === null) {
console.error("Previous sibling is invalid:", element)
return
}
let episodes = parseInt(prev.textContent)
const episodes = parseInt(prev.textContent)
prev.textContent = String(episodes + 1)
return save(arn, prev)
}
@ -181,12 +181,12 @@ export function addNumber(arn: AnimeNotifier, element: HTMLElement) {
return
}
let input = document.getElementById(element.dataset.id) as HTMLInputElement
let add = parseInt(element.dataset.add)
let num = parseInt(input.value)
let newValue = num + add
let min = parseInt(input.min)
let max = parseInt(input.max)
const input = document.getElementById(element.dataset.id) as HTMLInputElement
const add = parseInt(element.dataset.add)
const num = parseInt(input.value)
const newValue = num + add
const min = parseInt(input.min)
const max = parseInt(input.max)
if(newValue > max) {
arn.statusMessage.showError("Maximum: " + max)

View File

@ -2,7 +2,7 @@ import AnimeNotifier from "../AnimeNotifier"
// Charge up
export function chargeUp(arn: AnimeNotifier, button: HTMLElement) {
let amount = button.dataset.amount
const amount = button.dataset.amount
arn.loading(true)
arn.statusMessage.showInfo("Creating PayPal transaction... This might take a few seconds.")
@ -18,7 +18,7 @@ export function chargeUp(arn: AnimeNotifier, button: HTMLElement) {
throw "Error creating PayPal payment"
}
let link = payment.links.find(link => link.rel === "approval_url")
const link = payment.links.find(link => link.rel === "approval_url")
if(!link) {
throw "Error finding PayPal payment link"
@ -26,7 +26,7 @@ export function chargeUp(arn: AnimeNotifier, button: HTMLElement) {
arn.statusMessage.showInfo("Redirecting to PayPal...", 5000)
let url = link.href
const url = link.href
window.location.href = url
})
.catch(err => arn.statusMessage.showError(err))
@ -35,14 +35,14 @@ export function chargeUp(arn: AnimeNotifier, button: HTMLElement) {
// Toggle fade
export function toggleFade(_: AnimeNotifier, button: HTMLElement) {
let elementId = button.dataset.elementId
const elementId = button.dataset.elementId
if(!elementId) {
console.error("Missing element ID:", elementId)
return
}
let element = document.getElementById(elementId)
const element = document.getElementById(elementId)
if(!element) {
console.error("Invalid element ID:", elementId)
@ -58,9 +58,9 @@ export function toggleFade(_: AnimeNotifier, button: HTMLElement) {
// Buy item
export function buyItem(arn: AnimeNotifier, button: HTMLElement) {
let itemId = button.dataset.itemId
let itemName = button.dataset.itemName
let price = button.dataset.price
const itemId = button.dataset.itemId
const itemName = button.dataset.itemName
const price = button.dataset.price
if(!confirm(`Would you like to buy ${itemName} for ${price} gems?`)) {
return

View File

@ -2,6 +2,6 @@ import AnimeNotifier from "../AnimeNotifier"
// Toggle sidebar
export function toggleSidebar(_: AnimeNotifier) {
let sidebar = document.getElementById("sidebar") as HTMLElement
const sidebar = document.getElementById("sidebar") as HTMLElement
sidebar.classList.toggle("sidebar-visible")
}

View File

@ -102,7 +102,7 @@ export function nextTheme(arn: AnimeNotifier) {
// Find current index and apply theme of next index
for(let i = 0; i < themesSorted.length; i++) {
if(themesSorted[i] === currentThemeName) {
let newIndex = (i + 1) % themesSorted.length
const newIndex = (i + 1) % themesSorted.length
applyThemeAndPreview(arn, themesSorted[newIndex])
break
}
@ -135,15 +135,15 @@ export function applyThemeAndPreview(arn: AnimeNotifier, themeName: string) {
// Apply theme
export function applyTheme(themeName: string) {
let rootStyle = document.documentElement.style
let theme = themes[themeName]
const rootStyle = document.documentElement.style
const theme = themes[themeName]
// Apply base theme
if(theme["base-theme"]) {
applyTheme(theme["base-theme"])
}
for(let property in theme) {
for(const property in theme) {
if(!theme.hasOwnProperty(property)) {
continue
}
@ -164,13 +164,13 @@ export function applyTheme(themeName: string) {
// Color picker
export function pickColor(_: AnimeNotifier, element: HTMLElement) {
let rootStyle = document.documentElement.style
let variableName = `--${element.dataset.variable}`
let input = document.createElement("input")
const rootStyle = document.documentElement.style
const variableName = `--${element.dataset.variable}`
const input = document.createElement("input")
input.type = "color"
input.oninput = () => {
let color = hexToHSL(input.value)
const color = hexToHSL(input.value)
if(!color) {
return

View File

@ -3,8 +3,8 @@ import { bytesHumanReadable, uploadWithProgress } from "../Utils"
// Select file
export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) {
let fileType = button.dataset.type
let endpoint = button.dataset.endpoint
const fileType = button.dataset.type
const endpoint = button.dataset.endpoint
if(endpoint === "/api/upload/user/cover" && arn.user && arn.user.dataset.pro !== "true") {
alert("Please buy a PRO account to use this feature.")
@ -12,7 +12,7 @@ export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) {
}
// Click on virtual file input element
let input = document.createElement("input")
const input = document.createElement("input")
input.setAttribute("type", "file")
input.value = ""
@ -26,7 +26,7 @@ export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) {
return
}
let file = input.files[0]
const file = input.files[0]
// Check mime type for images
if(fileType === "image" && !file.type.startsWith("image/")) {
@ -42,9 +42,9 @@ export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) {
// Preview image
if(fileType === "image") {
let previews = document.getElementsByClassName(button.id + "-preview")
let dataURL = await readImageAsDataURL(file)
let img = await loadImage(dataURL)
const previews = document.getElementsByClassName(button.id + "-preview")
const dataURL = await readImageAsDataURL(file)
const img = await loadImage(dataURL)
switch(endpoint) {
case "/api/upload/user/image":
@ -73,11 +73,11 @@ export function selectFile(arn: AnimeNotifier, button: HTMLButtonElement) {
// Upload file
function uploadFile(file: File, fileType: string, endpoint: string, arn: AnimeNotifier) {
let reader = new FileReader()
const reader = new FileReader()
reader.onloadend = async () => {
let result = reader.result as ArrayBuffer
let fileSize = result.byteLength
const result = reader.result as ArrayBuffer
const fileSize = result.byteLength
if(fileSize === 0) {
arn.statusMessage.showError("File is empty")
@ -87,7 +87,7 @@ function uploadFile(file: File, fileType: string, endpoint: string, arn: AnimeNo
arn.statusMessage.showInfo(`Preparing to upload ${fileType} (${bytesHumanReadable(fileSize)})`, -1)
try {
let responseText = await uploadWithProgress(endpoint, {
const responseText = await uploadWithProgress(endpoint, {
method: "POST",
credentials: "include",
headers: {
@ -95,7 +95,7 @@ function uploadFile(file: File, fileType: string, endpoint: string, arn: AnimeNo
},
body: reader.result
}, e => {
let progress = e.loaded / (e.lengthComputable ? e.total : fileSize) * 100
const progress = e.loaded / (e.lengthComputable ? e.total : fileSize) * 100
arn.statusMessage.showInfo(`Uploading ${fileType}...${progress.toFixed(1)}%`, -1)
})
@ -118,10 +118,10 @@ function uploadFile(file: File, fileType: string, endpoint: string, arn: AnimeNo
// Read image as data URL
function readImageAsDataURL(file: File): Promise<string> {
return new Promise((resolve, reject) => {
let reader = new FileReader()
const reader = new FileReader()
reader.onloadend = () => {
let dataURL = reader.result as string
const dataURL = reader.result as string
resolve(dataURL)
}
@ -137,7 +137,7 @@ function readImageAsDataURL(file: File): Promise<string> {
// Load image and resolve when loading has finished
function loadImage(url: string): Promise<HTMLImageElement> {
return new Promise((resolve, reject) => {
let img = new Image()
const img = new Image()
img.src = url
img.onload = () => {
@ -153,15 +153,15 @@ function loadImage(url: string): Promise<HTMLImageElement> {
// Preview image
function previewImage(dataURL: string, endpoint: string, previews: HTMLCollectionOf<Element>) {
if(endpoint === "/api/upload/user/image") {
let svgPreview = document.getElementById("avatar-input-preview-svg") as HTMLImageElement
const svgPreview = document.getElementById("avatar-input-preview-svg") as HTMLImageElement
if(svgPreview) {
svgPreview.classList.add("hidden")
}
}
for(let preview of previews) {
let img = preview as HTMLImageElement
for(const preview of previews) {
const img = preview as HTMLImageElement
img.classList.remove("hidden")
// Make not found images visible again
@ -176,9 +176,9 @@ function previewImage(dataURL: string, endpoint: string, previews: HTMLCollectio
// Update sidebar avatar
function updateSideBarAvatar(url: string) {
let sidebar = document.getElementById("sidebar") as HTMLElement
let userImage = sidebar.getElementsByClassName("user-image")[0] as HTMLImageElement
let lazyLoad = userImage["became visible"]
const sidebar = document.getElementById("sidebar") as HTMLElement
const userImage = sidebar.getElementsByClassName("user-image")[0] as HTMLImageElement
const lazyLoad = userImage["became visible"]
if(lazyLoad) {
userImage.dataset.src = url

View File

@ -13,8 +13,8 @@ export async function unfollowUser(arn: AnimeNotifier, element: HTMLElement) {
// Update follow
async function updateFollow(arn: AnimeNotifier, element: HTMLElement, message: string) {
let api = element.dataset.api
let nick = document.getElementById("nick")
const api = element.dataset.api
const nick = document.getElementById("nick")
if(!api || !nick || !nick.textContent) {
console.error("Missing data-api or invalid nick:", element)
@ -34,7 +34,7 @@ async function updateFollow(arn: AnimeNotifier, element: HTMLElement, message: s
export function showMore(_: AnimeNotifier, showMoreElement: HTMLElement) {
const elements = [...document.getElementsByClassName("show-more")]
for(let element of elements) {
for(const element of elements) {
Diff.mutations.queue(() => element.classList.remove("show-more"))
}

View File

@ -2,21 +2,21 @@ import AnimeNotifier from "../AnimeNotifier"
// Toggle play video
export function togglePlayVideo(arn: AnimeNotifier, element: HTMLElement) {
let mediaId = element.dataset.mediaId
const mediaId = element.dataset.mediaId
if(!mediaId) {
console.error("Missing data-media-id:", element)
return
}
let container = document.getElementById(mediaId)
const container = document.getElementById(mediaId)
if(!container) {
console.error("Invalid data-media-id:", element)
return
}
let video = container.getElementsByTagName("video")[0]
const video = container.getElementsByTagName("video")[0]
video.volume = arn.audioPlayer.volume
if(video.readyState >= 2) {
@ -41,23 +41,23 @@ function togglePlayVideoElement(video: HTMLVideoElement) {
// Toggle fullscreen
export function toggleFullscreen(_: AnimeNotifier, button: HTMLElement) {
let elementId = button.dataset.id
const elementId = button.dataset.id
if(!elementId) {
console.error("Missing data-id:", button)
return
}
let element = document.getElementById(elementId)
const element = document.getElementById(elementId)
if(!element) {
console.error("Invalid data-id:", button)
return
}
let requestFullscreen = element.requestFullscreen || element["mozRequestFullScreen"] || element["webkitRequestFullScreen"] || element["msRequestFullscreen"]
let exitFullscreen = document.exitFullscreen || document["mozCancelFullScreen"] || document["webkitExitFullscreen"] || document["msExitFullscreen"]
let fullscreen = document.fullscreen || document["webkitIsFullScreen"] || document["mozFullScreen"]
const requestFullscreen = element.requestFullscreen || element["mozRequestFullScreen"] || element["webkitRequestFullScreen"] || element["msRequestFullscreen"]
const exitFullscreen = document.exitFullscreen || document["mozCancelFullScreen"] || document["webkitExitFullscreen"] || document["msExitFullscreen"]
const fullscreen = document.fullscreen || document["webkitIsFullScreen"] || document["mozFullScreen"]
if(fullscreen) {
exitFullscreen.call(document)