Add refresh button
This commit is contained in:
parent
b37acae0fa
commit
a426fa8752
1 changed files with 84 additions and 33 deletions
|
|
@ -11,46 +11,97 @@
|
|||
|
||||
(function () {
|
||||
"use strict";
|
||||
var username = "mars";
|
||||
var password = "absw3712mcS";
|
||||
var apiKey = "38346c399d57454da3bdbf47ba716765";
|
||||
var userid = "e55a6ca076a14cb5a6ca9cfaa75498c1";
|
||||
function insert() {
|
||||
|
||||
// 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="Chrome", DeviceId="test", Version="10.8.9", Token="${apiKey}"`,
|
||||
"X-Emby-Authorization": `MediaBrowser Client="QuickDelete", Device="Browser", DeviceId="", Version="1.0.0", Token="${apiKey}"`,
|
||||
},
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((data) => (apiKey = data.AccessToken));
|
||||
.then((data) => (apiKey = data.AccessToken)); // Store AccessToken
|
||||
|
||||
const collection = document.getElementsByClassName("listItem");
|
||||
for (let i = 0; i < collection.length; i++) {
|
||||
let curr = collection[i];
|
||||
// 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 = "red";
|
||||
el2.style.color = "#fb4934";
|
||||
el.appendChild(el2);
|
||||
|
||||
// Bind delete function
|
||||
el.onclick = function () {
|
||||
let url = "https://media.m3.fyi/Items/" + this.parentElement.dataset.id;
|
||||
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();
|
||||
};
|
||||
curr.appendChild(el);
|
||||
//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");
|
||||
|
||||
for (let i = 0; i < collection.length; i++) {
|
||||
let curr = collection[i];
|
||||
|
||||
// Append buttons to list
|
||||
curr.appendChild(refreshButton());
|
||||
curr.appendChild(delButton());
|
||||
}
|
||||
}
|
||||
|
||||
// Setup key handler
|
||||
function onKeydown(evt) {
|
||||
// Use https://keycode.info/ to get keys
|
||||
// Alt + Q
|
||||
if (evt.altKey && evt.keyCode == 81) {
|
||||
insert();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue