`
));
}
function isCalendarPageCurrentMonth() {
let today = new Date();
// Extract the calendar date from the URL
let calendarDate = new Date(window.location.href.substring(window.location.href.lastIndexOf('/') + 1));
// If there's no date (current month) or it's the current month then return true
return (isNaN(calendarDate) || (calendarDate.getMonth() === today.getMonth() && calendarDate.getYear() === today.getYear()))
}
// Autoscroll to current date
function scrollCurrentDate() {
if(isCalendarPageCurrentMonth()) {
let todayCard = [...$$('.date-separator:not(.filler) .date')].filter((el) => {
return el.textContent == (new Date()).getDate();
})[0];
if (todayCard) {
todayCard.scrollIntoView(true);
// Scroll up to compensate top navbar
let topNav = $('#top-nav');
let offset = -window.getComputedStyle(topNav).getPropertyValue('height').slice(0, -2);
window.scrollBy(0, offset);
}
}
}
// Process calendar page
function processCalendarPage() {
// Torrent links
for (const el of [...$$('.grid-item[data-type="episode"]')]) {
addLinkToGridItem(el, 'episode');
}
if (GM_config.get('autoscrollToday')) {
whenCalendarReady(() => { scrollCurrentDate(); }, 'autoscroll');
}
// Settings menu icon
let menuIcon = createElement(
`
`
);
menuIcon = $('.sidenav-inner').appendChild(menuIcon);
addEventListener(menuIcon, 'click', () => GM_config.open());
// Jump icon
if(isCalendarPageCurrentMonth()) {
let jumpIcon = createElement(
`
`
);
jumpIcon = $('.sidenav-inner').appendChild(jumpIcon);
addEventListener(jumpIcon, 'click', () => scrollCurrentDate());
}
// Add events to arrows
whenCalendarReady(() => {
for (const el of [...$$('.prev, .next')]) {
addEventListener(
el,
'click',
() => whenCalendarReady(() => processCalendarPage(), 'processAfterChangingMonth'),
'addArrowsEvents'
);
}
});
}
// Process show page
function processShowPage() {
for (const el of [...$$('.grid-item[data-type="season"]')]) { addLinkToGridItem(el, 'season'); }
addLinkToActionList($('.action-buttons'), 'show');
}
// Process season page
function processSeasonPage() {
for (const el of [...$$('.grid-item[data-type="episode"]')]) { addLinkToGridItem(el, 'episode'); }
addLinkToActionList($('.action-buttons'), 'season');
}
// Process episode page
function processEpisodePage() {
addLinkToActionList($('.action-buttons'), 'episode');
}
// Process movies page
function processMoviesPage() {
for (const el of [...$$('.grid-item[data-type="movie"]')]) { addLinkToGridItem(el, 'movie'); }
}
// Process movie page
function processMoviePage() {
addLinkToActionList($('.action-buttons'), 'movie');
}
// Main function
function processPage() {
if (regex.calendar.test(location.pathname)) {
processCalendarPage();
}
else if (regex.show.test(location.pathname)) {
processShowPage();
}
else if (regex.season.test(location.pathname)) {
processSeasonPage();
}
else if (regex.episode.test(location.pathname)) {
processEpisodePage();
}
else if (regex.movies.test(location.pathname)) {
processMoviesPage();
}
else if (regex.movie.test(location.pathname)) {
processMoviePage();
}
}
// Apply styles
$('head').append(createElement(style));
validateSettings();
processPage();
applySettings();
})();