Add refresh button

This commit is contained in:
Mars Niermann 2023-03-08 00:37:33 +01:00
parent b37acae0fa
commit a426fa8752
No known key found for this signature in database
GPG key ID: B2D0FC62A74FC971

View file

@ -11,46 +11,97 @@
(function () { (function () {
"use strict"; "use strict";
var username = "mars";
var password = "absw3712mcS";
var apiKey = "38346c399d57454da3bdbf47ba716765";
var userid = "e55a6ca076a14cb5a6ca9cfaa75498c1";
function insert() {
const baseURL = window.origin;
fetch(`${baseURL}/Users/${userid}/Authenticate/?pw=${password}`, {
method: "POST",
headers: {
"X-Emby-Authorization": `MediaBrowser Client="QuickDelete", Device="Chrome", DeviceId="test", Version="10.8.9", Token="${apiKey}"`,
},
})
.then((response) => response.json())
.then((data) => (apiKey = data.AccessToken));
// Define Constants
const username = "mars";
const password = "absw3712mcS";
const apiKey = "38346c399d57454da3bdbf47ba716765";
const userid = "e55a6ca076a14cb5a6ca9cfaa75498c1";
const baseURL = window.origin;
// Authorize user
fetch(`${baseURL}/Users/${userid}/Authenticate/?pw=${password}`, {
method: "POST",
headers: {
"X-Emby-Authorization": `MediaBrowser Client="QuickDelete", Device="Browser", DeviceId="", Version="1.0.0", Token="${apiKey}"`,
},
})
.then((response) => response.json())
.then((data) => (apiKey = data.AccessToken)); // Store AccessToken
// Helper function to create delete button
function delButton() {
let el = document.createElement("button");
el.className = "listItemButton paper-icon-button-light emby-button";
let el2 = document.createElement("span");
// Set icon and color
el2.className = "material-icons delete";
el2.style.color = "#fb4934";
el.appendChild(el2);
// Bind delete function
el.onclick = function () {
let url = `${window.origin}/Items/${this.parentElement.dataset.id}`;
console.log(`Deleting ${url}`);
// Send deletion request
fetch(url, {
method: "DELETE",
headers: {
"X-Emby-Authorization": `MediaBrowser Client="QuickDelete", Device="Chrome", DeviceId="test", Version="10.8.9", Token="${apiKey}"`,
},
});
// Remove parent to provide feedback and prevent double deletion
this.parentElement.remove();
};
//Return complete element
return el2;
}
// Button to refresh the metadata of an item
function refreshButton() {
let el = document.createElement("button");
el.className = "listItemButton paper-icon-button-light emby-button";
let el2 = document.createElement("span");
// Set icon and color
el2.className = "material-icons refresh";
el2.style.color = "#83a598";
el.appendChild(el2);
el.onclick = function () {
let url = `${window.origin}/Items/${this.parentElement.dataset.id}/Refresh?Recursive=true&ImageRefreshMode=FullRefresh&MetadataRefreshMode=FullRefresh&ReplaceAllImages=true&ReplaceAllMetadata=true`;
console.log(`Deleting ${url}`);
// Send deletion request
fetch(url, {
method: "POST",
headers: {
"X-Emby-Authorization": `MediaBrowser Client="QuickDelete", Device="Chrome", DeviceId="test", Version="10.8.9", Token="${apiKey}"`,
},
});
};
return el2;
}
// Insert buttons
function insert() {
const collection = document.getElementsByClassName("listItem"); const collection = document.getElementsByClassName("listItem");
for (let i = 0; i < collection.length; i++) { for (let i = 0; i < collection.length; i++) {
let curr = collection[i]; let curr = collection[i];
let el = document.createElement("button");
el.className = "listItemButton paper-icon-button-light emby-button"; // Append buttons to list
let el2 = document.createElement("span"); curr.appendChild(refreshButton());
el2.className = "material-icons delete"; curr.appendChild(delButton());
el2.style.color = "red";
el.appendChild(el2);
el.onclick = function () {
let url = "https://media.m3.fyi/Items/" + this.parentElement.dataset.id;
console.log(`Deleting ${url}`);
fetch(url, {
method: "DELETE",
headers: {
"X-Emby-Authorization": `MediaBrowser Client="QuickDelete", Device="Chrome", DeviceId="test", Version="10.8.9", Token="${apiKey}"`,
},
});
this.parentElement.remove();
};
curr.appendChild(el);
} }
} }
// Setup key handler
function onKeydown(evt) { function onKeydown(evt) {
// Use https://keycode.info/ to get keys // Alt + Q
if (evt.altKey && evt.keyCode == 81) { if (evt.altKey && evt.keyCode == 81) {
insert(); insert();
} }