Skip to content

Instantly share code, notes, and snippets.

@rwilson
Created July 6, 2022 18:59
Show Gist options
  • Save rwilson/d58b646766d1aef9eeea37de6f9ae120 to your computer and use it in GitHub Desktop.
Save rwilson/d58b646766d1aef9eeea37de6f9ae120 to your computer and use it in GitHub Desktop.
Amazon Parent Dashboard
// The Amazon Parent Dashboard allows searching for titles and hiding them from a profile,
// but you have to do it episode by episode. So, if you want to hide all Cocomelon or Blippi,
// it's a lot of clicking. These functions help. They're ~all structured as Promises to handle
// that UI actions take time, and to support sequencing them easily.
// This returns an HTMLCollection, which is a live view of the DOM
const findTitles = function() {
return document.getElementsByClassName("search-result-allowed-count-single-child");
}
// Returns a Promise which resolves the next title.
const findNextTitle = function() {
return new Promise(
(res, rej) => {
var titles = findTitles();
if (titles.length > 0) {
res(titles[0]);
} else {
rej("No titles found");
}
}
);
}
// Returns a promise which resolves when the modal for the given title is open
const openModal = function(title) {
return new Promise((res, rej) => {
if (title) {
title.click();
setTimeout(res, 500);
} else {
rej("No title provided");
}
});
}
// Returns a promise that resolves when the title is hidden
const hideTitle = function() {
return new Promise((res, rej) => {
const btn = document.getElementById("pd-expl-detailcard-icon-0");
if (btn) {
btn.click();
setTimeout(res, 500);
} else {
rej("Button not found. Is the modal open?");
}
});
}
// Returns a promise that resolves when the model is closed
const closeModal = function() {
return new Promise((res, rej) => {
// This classname looks like it depends on a particular build artifact, so you may have to inspect the
// "x" button in the modal to get the latest.
const elems = document.getElementsByClassName("css-1i6z7vu");
if (elems.length > 0) {
elems[0].click();
setTimeout(res, 500);
} else {
rej("Close button not found. Is the modal open?");
}
});
}
// Find and hide the next title on the page
const hideNextTitle = function() {
return findNextTitle()
.then(openModal, console.log)
.then(hideTitle, console.log)
.then(closeModal, console.log);
}
// Find and hide all titles on the page
const hideAllTitles = function() {
// findTitles() returns an HTMLCollection, which is a live view and modified by each iteration
const helper = (htmlColl, idx) => {
if (htmlColl.length > 0) {
openModal(htmlColl[0])
.then(hideTitle, console.log)
.then(closeModal, console.log)
.then(helper.bind(null, htmlColl), console.log);
}
};
helper(findTitles(), 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment