Skip to content

Commit

Permalink
version 1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamlinerm committed Apr 24, 2024
1 parent a3cf207 commit d170138
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 83 deletions.
2 changes: 1 addition & 1 deletion chrome/popup/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ <h2>Changelog</h2>
<div class="line flex">
<h2>1.1.5</h2>
<ul>
<li>On Crunchyroll now save old release calendar schedule and puts it in current week</li>
<li>Crunchyroll: now put release schedule in current weeks release calendar(queued no dub only)</li>
</ul>
</div>
<div class="line flex">
Expand Down
177 changes: 96 additions & 81 deletions chrome/skipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
const size = new TextEncoder().encode(JSON.stringify(DBCache)).length;
const kiloBytes = size / 1024;
const megaBytes = kiloBytes / 1024;
if (megaBytes <= 5) {
if (megaBytes < 5) {
chrome.storage.local.set({ DBCache });
} else {
log("DBCache cleared", megaBytes);
Expand Down Expand Up @@ -1046,92 +1046,107 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
toggleForm.firstElementChild.appendChild(createFilterElement("filterQueued", "Show Playlist only", settings.General.filterQueued, filterQueued));
toggleForm.firstElementChild.appendChild(createFilterElement("filterDub", "Filter Dub", settings.General.filterDub, filterDub));
}
// start of add CrunchyList to Crunchyroll
function addShowsToList(position, list) {
list.forEach((element) => {
const article = document.createElement("article");
article.className = "release js-release";
article.innerHTML = `
<time class="available-time">${new Date(element.time).toLocaleString([], { hour: "2-digit", minute: "2-digit" })}</time>
<div>
<div class="queue-flag queued enhanced" group_id="283836">
<svg viewBox="0 0 48 48">
<title>In Queue</title>
<use xlink:href="/i/svg/simulcastcalendar/calendar_icons.svg#cr_bookmark"></use>
</svg>
</div>
<h1 class="season-name">
<a class="js-season-name-link" href="${element.href}" itemprop="url">
<cite itemprop="name">${element.name}</cite>
</a>
</h1>
</div>`;
position.appendChild(article);
});
}
function clickOnCurrentDay() {
let days = document.querySelectorAll(".specific-date [datetime]");
for (const day of days) {
const dateOnPage = new Date(day.getAttribute("datetime"));
// if the day of the week is the same as today click on it, like if its Monday click on Monday
if (date.getDay() == dateOnPage.getDay()) {
// need timeout because the page is not fully loaded
setTimeout(() => {
day.click();
}, 100);
// isCurrentWeek
return date.toLocaleDateString() == dateOnPage.toLocaleDateString();
}
}
return false;
}
function createLocalList() {
let localList = [];
document.querySelectorAll("div.queue-flag.queued:not(.enhanced)").forEach((element) => {
const h1 = element.nextElementSibling?.firstChild?.nextSibling;
const name = h1.firstChild.nextSibling.textContent;
if (!name.includes("Dub")) {
const href = h1?.href;
const time = element.parentElement?.parentElement?.firstElementChild?.getAttribute("datetime");
localList.push({ href, name, time });
}
});
return localList;
}
function filterOldList(isCurrentWeek, lastHr, lastMin) {
let oldList = settings.General.savedCrunchyList || [];
// delete all previous weekdays from oldList
if (!isCurrentWeek) {
oldList = [];
} else {
oldList = oldList
.filter((item) => {
return shiftSunday(date.getDay()) - shiftSunday(new Date(item.time).getDay()) <= 0;
})
// delete all items from same weekday before lastElement time
.filter((item) => {
const itemTime = new Date(item.time);
const itemHr = itemTime.getHours();
return new Date(item.time).getDay() != date.getDay() || itemHr > lastHr || (itemHr == lastHr && itemTime.getMinutes() > lastMin);
});
}
return oldList;
}
const shiftSunday = (a) => (a + 6) % 7;
function addSavedCrunchyList() {
let localList = createLocalList();
const lastElement = localList[localList.length - 1];
const isCurrentWeek = clickOnCurrentDay();
const oldList = filterOldList(isCurrentWeek, new Date(lastElement.time).getHours(), new Date(lastElement.time).getMinutes());
settings.General.savedCrunchyList = localList.concat(oldList);
chrome.storage.sync.set({ settings });
if (isCurrentWeek && !document.querySelector("div.queue-flag.queued.enhanced")) {
// now add the old list to the website list
document.querySelectorAll("section.calendar-day").forEach((element) => {
const weekday = new Date(element.querySelector("time")?.getAttribute("datetime")).getDay();
// remove Schedule Coming Soon text
if (shiftSunday(date.getDay()) - shiftSunday(weekday) < 0) element?.children?.[1]?.firstChild?.nextSibling?.remove();
addShowsToList(
element.children[1],
oldList.filter((item) => new Date(item.time).getDay() == weekday)
);
});
}
}
async function Crunchyroll_ReleaseCalendar() {
if (settings.Crunchyroll?.releaseCalendar && url.includes("simulcastcalendar")) {
// Show playlist only
filterQueued(settings.General.filterQueued ? "none" : "block");
filterDub(settings.General.filterDub ? "none" : "block");
if (!document.querySelector("#filterQueued")) addButtons();
// save the old calendar and click on currentDay
let localList = [];
document.querySelectorAll("div.queue-flag.queued:not(.enhanced)").forEach((element) => {
const h1 = element.nextElementSibling?.firstChild?.nextSibling;
const name = h1.firstChild.nextSibling.textContent;
if (!name.includes("Dub")) {
const href = h1?.href;
const time = element.parentElement?.parentElement?.firstElementChild?.getAttribute("datetime");
localList.push({ href, name, time });
}
});
const lastElement = localList[localList.length - 1];
let oldList = settings.General.savedCrunchyList || [];
// delete all previous weekdays from oldList
const lastHr = new Date(lastElement.time).getHours();
const lastMin = new Date(lastElement.time).getMinutes();
let isCurrentWeek = false;
// click on currentday
let days = document.querySelectorAll(".specific-date [datetime]");
for (const day of days) {
const dateOnPage = new Date(day.getAttribute("datetime"));
// if the day of the week is the same as today click on it, like if its Monday click on Monday
if (date.getDay() == dateOnPage.getDay()) {
setTimeout(() => {
day.click();
}, 100);
isCurrentWeek = date.toLocaleDateString() == dateOnPage.toLocaleDateString();
break;
}
}
const shiftSunday = (a) => (a + 6) % 7;
if (!isCurrentWeek) {
oldList = [];
} else {
oldList = oldList
.filter((item) => {
return shiftSunday(date.getDay()) - shiftSunday(new Date(item.time).getDay()) <= 0;
})
// delete all items from same weekday before lastElement time
.filter((item) => {
const itemTime = new Date(item.time);
const itemHr = itemTime.getHours();
return new Date(item.time).getDay() != date.getDay() || itemHr > lastHr || (itemHr == lastHr && itemTime.getMinutes() > lastMin);
});
}
settings.General.savedCrunchyList = localList.concat(oldList);
chrome.storage.sync.set({ settings });
if (isCurrentWeek && !document.querySelector("div.queue-flag.queued.enhanced")) {
function addShowsToList(position, list) {
list.forEach((element) => {
const article = document.createElement("article");
article.className = "release js-release";
article.innerHTML = `
<time class="available-time">${new Date(element.time).toLocaleString([], { hour: "2-digit", minute: "2-digit" })}</time>
<div>
<div class="queue-flag queued enhanced" group_id="283836">
<svg viewBox="0 0 48 48">
<title>In Queue</title>
<use xlink:href="/i/svg/simulcastcalendar/calendar_icons.svg#cr_bookmark"></use>
</svg>
</div>
<h1 class="season-name">
<a class="js-season-name-link" href="${element.href}" itemprop="url">
<cite itemprop="name">${element.name}</cite>
</a>
</h1>
</div>`;
position.appendChild(article);
});
}
// now add the old list to the website list
document.querySelectorAll("section.calendar-day").forEach((element) => {
const weekday = new Date(element.querySelector("time")?.getAttribute("datetime")).getDay();
addShowsToList(
element.children[1],
oldList.filter((item) => new Date(item.time).getDay() == weekday)
);
});
}
// add saved CrunchyList and click on current day
addSavedCrunchyList();
}
}
// HBO functions
Expand Down
2 changes: 1 addition & 1 deletion firefox/skipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ if (isPrimeVideo || isNetflix || isDisney || isHotstar || isCrunchyroll || isHBO
const size = new TextEncoder().encode(JSON.stringify(DBCache)).length;
const kiloBytes = size / 1024;
const megaBytes = kiloBytes / 1024;
if (megaBytes <= 5) {
if (megaBytes < 5) {
browser.storage.local.set({ DBCache });
} else {
log("DBCache cleared", megaBytes);
Expand Down

0 comments on commit d170138

Please sign in to comment.