// ==UserScript== // @name Custom Anime Scheduler // @namespace http://tampermonkey.net/ // @version 0.1.6 // @description Schedules anime from any season // @author You // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net // @grant GM_setValue // @grant GM_getValue // @match *.livechart.me/* // @require https://code.jquery.com/jquery-3.6.4.min.js // @run-at document-end // @license MIT // @downloadURL none // ==/UserScript== const $ = window.jQuery; function convertToDateLinkText(date) { let realMonth = date.getMonth() + 1; let dateString = date.getDate(); if (dateString < 10) { dateString = '0' + dateString; } if (realMonth < 10) { realMonth = '0' + realMonth; } const dateLinkFormat_ = date.getFullYear() + '-' + realMonth + '-' + dateString; return dateLinkFormat_; } function convertToDateObject(dateString) { const modifiedDateString = dateString + " 00:00:00"; const dateObject = new Date(modifiedDateString); return dateObject; } function speedChange(diff) { const daysString = GM_getValue("days_speed"); const speed = Number(daysString); const newDiff = diff * Math.ceil(7 / speed); return newDiff; } function daysSinceStartingDay(date) { let daysSince; const startingDay_ = GM_getValue("starting_day"); if (startingDay_ == "monday") { daysSince = (date.getDay() + 6) % 7; } else if (startingDay_ == "relative") { daysSince = (date.getDay() + speedChange(1) - 1) % 7; } else { daysSince = date.getDay(); } return daysSince; } function shiftDate(date, diff) { const daysShifted = date.getDate() + diff; date.setDate(daysShifted); } function getDayTextFromNum(num) { let weekDay; switch(num) { case 0: weekDay = "Sun"; break; case 1: weekDay = "Mon"; break; case 2: weekDay = "Tue"; break; case 3: weekDay = "Wed"; break; case 4: weekDay = "Thu"; break; case 5: weekDay = "Fri"; break; case 6: weekDay = "Sat"; break; } return weekDay; } function getDayText(date) { let weekDay; const dayNum = date.getDay(); weekDay = getDayTextFromNum(dayNum); return weekDay; } function convertToDateButtonText(date) { let retString; let dateString = date.getDate(); const weekDay = getDayText(date); const realMonth = date.getMonth() + 1; if (dateString < 10) { dateString = '0' + dateString; } retString = weekDay + ' ' + realMonth + '/' + dateString; return retString; } function GetURLParameter(sParam) { const sPageURL = window.location.search.substring(1); const sURLVariables = sPageURL.split('&'); for (let i = 0; i < sURLVariables.length; i++) { let sParameterName = sURLVariables[i].split('='); if (sParameterName[0] == sParam) { return decodeURIComponent(sParameterName[1]); } } } function highlightTTDay(dayText, dayStatus) { let timeTableBox = $('.timetable'); const tTDayQuery = 'h2:contains("' + dayText + '")'; let TTDayH2 = timeTableBox.find(tTDayQuery); let TTDay = TTDayH2.parent().parent(); TTDay.removeClass("past"); TTDay.addClass(dayStatus); } $(window).bind("load", function () { const $today = new Date(); const todayHoursToMidnight = convertToDateObject(convertToDateLinkText($today)); let scheduleDate = convertToDateObject(GM_getValue("start_date")); const settingDate = convertToDateObject(GM_getValue("setting_date")); const daysDiff = (todayHoursToMidnight - settingDate) / (1000 * 60 * 60 * 24); const daysDiffWithSpeed = speedChange(daysDiff); shiftDate(scheduleDate, daysDiffWithSpeed); const currentCustomDateText = convertToDateLinkText(scheduleDate); const weekStartDiff = -daysSinceStartingDay(scheduleDate); shiftDate(scheduleDate, weekStartDiff); const dateLinkFormat = convertToDateLinkText(scheduleDate); const scheduleDateLink = 'https://www.livechart.me/timetable?date=' + dateLinkFormat; const SettingsTab = '
'; let CustomScheduleTab; if (GM_getValue("start_date") == undefined) { CustomScheduleTab = ' '; } else { CustomScheduleTab = ' '; } $(SettingsTab).insertBefore('.site-header--navigation>.flex-spacer'); let headlinesButton = $('a[href="/headlines"]').parent(); $(headlinesButton).attr('id', 'headlines-button'); $(CustomScheduleTab).insertBefore('.site-header--navigation>#headlines-button'); const urlDateText = GetURLParameter('date'); let urlDateObject = convertToDateObject(urlDateText); shiftDate(urlDateObject, -7); const urlDateLastWeekText = convertToDateLinkText(urlDateObject); const urlDateButtonText = convertToDateButtonText(urlDateObject); const lastWeekButton = ''; let weekChangeRow = $('div.column.small-6.float-right.text-right').parent() if (weekChangeRow.find("a").length == 1) { weekChangeRow.prepend(lastWeekButton); } let currentCustomDate = convertToDateObject(currentCustomDateText); const scheduleDayText = getDayText(currentCustomDate); if (urlDateText == dateLinkFormat) { highlightTTDay(scheduleDayText, "today"); const scheduleDayNum = currentCustomDate.getDay(); for (let i = scheduleDayNum; i < 7; i++) { let futureDayText = getDayTextFromNum(i); highlightTTDay(futureDayText, "future"); } const startingDay = GM_getValue("starting_day"); if (startingDay == "monday") { highlightTTDay("Sun", "future"); } } let BrowseList = $('.small-up-4'); $('.small-up-4 > div:last-child').remove(); const rowsNum = 20; const colsNum = 4; let yearGrid = new Array (colsNum); for (let i = 0; i < colsNum; i++) { yearGrid[i] = new Array(rowsNum); } let i = 0; let k = 0; $('.small-up-4 div').each(function() { if (i < rowsNum) { yearGrid[k][i] = $(this); i++; } else { k++; if (k < colsNum) { i = 0; yearGrid[k][i] = $(this); } } }); const thisYear = $today.getFullYear(); for (let year = (thisYear - 3); year >= 1960; year--) { if (i < rowsNum) { yearGrid[k][i] = (''); i++; } else { k++; if (k < colsNum) { i = 0; year++; } } } $(BrowseList).empty(); let r = 0; let c = 0; for (let r = 0; r < rowsNum; r++) { for (let c = 0; c < colsNum; c++) { $(BrowseList).append(yearGrid[c][r]); } } $(BrowseList).removeClass('grid-padding-x'); let PreferencesList = '.large-push-2 > div[class="ul-tabs-overflow"] > ul[class="ul-tabs"]'; const ScheduleSettingsPrefTab = '