Improve logging

This commit is contained in:
Isaac Shoebottom 2023-11-21 15:05:58 -04:00
parent fe7924cbb5
commit b67dcde975

View File

@ -30,7 +30,7 @@ function isMusicPage(): boolean {
let nodes = document.querySelectorAll("[class*=\"PageHeaderTitle-title\"]") let nodes = document.querySelectorAll("[class*=\"PageHeaderTitle-title\"]")
if (nodes.length === 0) { if (nodes.length === 0) {
console.log("No library name found") log("No library name found")
return false return false
} }
@ -53,17 +53,17 @@ function decidePage(): void {
intervalIds.push(id) intervalIds.push(id)
if (!isMusicPage()) { if (!isMusicPage()) {
console.log("Not music page") log("Not music page")
return return
} }
let url = window.location.href let url = window.location.href
if (url.includes("com.plexapp.plugins.library")) { if (url.includes("com.plexapp.plugins.library")) {
console.log("Library page") log("Library page")
let id = setInterval(libraryPage, interval) let id = setInterval(libraryPage, interval)
intervalIds.push(id) intervalIds.push(id)
} else if (url.includes("details?key=%2Flibrary%2Fmetadata")) { } else if (url.includes("details?key=%2Flibrary%2Fmetadata")) {
console.log("Details page") log("Details page")
let id = setInterval(albumPage, interval) let id = setInterval(albumPage, interval)
intervalIds.push(id) intervalIds.push(id)
} }
@ -90,7 +90,7 @@ function swapCards(cards): void {
let album = elements.item(2) let album = elements.item(2)
card.insertBefore(album, artist) card.insertBefore(album, artist)
console.log("Swapped artist: " + artist.innerText + " and album: " + album.innerText) log("Swapped artist: " + artist.innerText + " and album: " + album.innerText)
// Album has isSecondary // Album has isSecondary
let secondaryClass = album.className.split(" ").find((className) => className.includes("isSecondary")) let secondaryClass = album.className.split(" ").find((className) => className.includes("isSecondary"))
@ -110,7 +110,7 @@ function libraryPage() {
// Select all divs with the attribute data-testid="cellItem" // Select all divs with the attribute data-testid="cellItem"
let cards = document.querySelectorAll("[data-testid=\"cellItem\"]") let cards = document.querySelectorAll("[data-testid=\"cellItem\"]")
if (cards.length === 0) { if (cards.length === 0) {
console.log("No cards found") log("No cards found")
return return
} }
swapCards(cards) swapCards(cards)
@ -126,7 +126,7 @@ function albumPage() {
// Check if the container has two children, so there isn't null errors // Check if the container has two children, so there isn't null errors
if (container.children.length < 2) { if (container.children.length < 2) {
console.log("Not on album page") log("Not on album page")
return return
} }
let artist = container.children.item(0) let artist = container.children.item(0)
@ -136,12 +136,12 @@ function albumPage() {
artist.attributes.getNamedItem("data-testid").value !== "metadata-title" || artist.attributes.getNamedItem("data-testid").value !== "metadata-title" ||
album.attributes.getNamedItem("data-testid").value !== "metadata-subtitle" album.attributes.getNamedItem("data-testid").value !== "metadata-subtitle"
) { ) {
console.log("Not on album page") log("Not on album page")
return return
} }
container.insertBefore(album, artist) container.insertBefore(album, artist)
console.log("Swapped artist: " + artist.innerText + " and album: " + album.innerText) log("Swapped artist: " + artist.innerText + " and album: " + album.innerText)
let newArtist = document.createElement("h2") let newArtist = document.createElement("h2")
let newAlbum = document.createElement("h1") let newAlbum = document.createElement("h1")
@ -225,13 +225,21 @@ function swapPlayer(holder) {
holder.attributes.swap = true holder.attributes.swap = true
} }
function logSwap(artist, album) {
log("Swapped artist: " + artist + " and album: " + album)
}
function log(message: string): void {
console.log("PlexMusicFixer" + message)
}
// "Main" // "Main"
// On href change, run decidePage // On href change, run decidePage
let href = "" let href = ""
const observer = new MutationObserver(() => { const observer = new MutationObserver(() => {
if (window.location.href !== href) { if (window.location.href !== href) {
href = window.location.href href = window.location.href
console.log("Deciding page") log("Deciding page")
decidedIntervalIds.push(setInterval(decidePage, interval)) decidedIntervalIds.push(setInterval(decidePage, interval))
} }
}) })