campaignTrail_temp.election_json = [
{
"model": "campaign_trail.election",
"pk": 21,
"fields": {
"year": 2020,
"summary": "
Thank you for electing Howard Schultz as President. This moment reflects a shared belief that leadership should inspire possibility, strengthen communities, and bring people together around a common purpose. Together, we begin a new chapter rooted in responsibility, opportunity, and service.
President Schultz's mission is simple. To help inspire and nurture the American spirit, one citizen, one community, one neighborhood at a time. Drawing on decades of experience building partnerships and investing in people, this administration is committed to strengthening trust, expanding opportunity, and creating a country where everyone has a seat at the table.
Our mission builds on our guiding principles. Principles we hope will endure for a second term.
",
"image_url": "https://i.imgur.com/MZ6PCCk.png",
"winning_electoral_vote_number": 270,
"advisor_url": "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/schultz3.png",
"recommended_reading": "",
"has_visits": 1,
"no_electoral_majority_image": "https://thecampaigntrail.net/static/images/2012-no-majority.jpg",
"creator": "Dan Bryan",
"is_historical": true,
"display_year": "2024 Schultz",
"recommended_reading_enabled": true
}
}
];
campaignTrail_temp.temp_election_list = [
{
"id": 21,
"year": 2020,
"is_premium": 0,
"display_year": "2024 Schultz"
}
];
RecReading = true;
campaignTrail_temp.credits = "I Heath";
campaignTrail_temp.global_parameter_json = [
{
"model": "campaign_trail.global_parameter",
"pk": 1,
"fields": {
"vote_variable": 1.125,
"max_swing": 0.12,
"start_point": 0.94,
"candidate_issue_weight": 10,
"running_mate_issue_weight": 3,
"issue_stance_1_max": -0.71,
"issue_stance_2_max": -0.3,
"issue_stance_3_max": -0.125,
"issue_stance_4_max": 0.125,
"issue_stance_5_max": 0.3,
"issue_stance_6_max": 0.71,
"global_variance": 0.01,
"state_variance": 0.005,
"question_count": 25,
"default_map_color_hex": "#C9C9C9",
"no_state_map_color_hex": "#999999"
}
}
];
campaignTrail_temp.candidate_json = [
{
"model": "campaign_trail.candidate",
"pk": 300,
"fields": {
"first_name": "Howard",
"last_name": "Schultz",
"election": 21,
"party": "Independent",
"state": "Washington",
"priority": 1,
"description": "cant think of a Schultz desc check back later.
",
"color_hex": "#144537",
"secondary_color_hex": "#90C0FF",
"is_active": 1,
"image_url": "https://i.imgur.com/gc10Kcx.png",
"electoral_victory_message": "Congratulations! You have won the 2020 election.
Things may have been closer and more contested than you hoped for, but the final result remains. Can you help bring the country back together after a tumultuous few years? Or will you be seen as a lame duck from the first day -- unable to keep the two wings of your party coordinated? Time will tell.
",
"electoral_loss_message": "Sorry! You have lost the 2020 election.
After an election in which many of your supporters claimed democracy itself was at stake, what happens now? Perhaps the party will need to go in a completely different direction in 2024. As for yourself, it seems that your long, illustrious political career has surely drawn to a close.
",
"no_electoral_majority_message": "Sorry! You have lost the 2020 election.
In spite of the 269-269 tie in the electoral college, Republicans control a majority of state delegations in the House of Representatives. After an election in which many of your supporters claimed democracy itself was at stake, what happens now? Perhaps the party will need to go in a completely different direction in 2024.
",
"description_as_running_mate": "",
"candidate_score": 1,
"running_mate": false
}
},
{
"model": "campaign_trail.candidate",
"pk": 301,
"fields": {
"first_name": "The",
"last_name": "Republicans",
"election": 21,
"party": "Republican",
"state": "Rage",
"priority": 2,
"description": "How did this happen? How did we lose? We had it in the bag. Things like this don't just happen. We were beating Tulsi so bad, and then this guy comes in and swoops to a victory? They stole it. Or something like that. They had to have.
And who knows what can happen now? Schultz is basically a Democrat plant. We all know it. The...the riots..the transgenders...all of it. Someone has to put a stop to this. Someone has to bring back common sense. Whether Trump or someone else. We're the natural party of government, you know.
",
"color_hex": "#8e0b11",
"secondary_color_hex": "#FFA0A0",
"is_active": 1,
"image_url": "https://i.imgur.com/QGbZNMG.png",
"electoral_victory_message": "Congratulations! You have won the 2020 election.
For the second time in a row, many analysts saw a victory for you as practically impossible. But whatever they say, it is clear that your Make America Great Again agenda has been vindicated. Where do you take things from here?
",
"electoral_loss_message": "Sorry! You have lost the 2020 election.
After an election in which many of your supporters claimed democracy itself was at stake, what happens now? Many analysts believe the party will need to go in a completely different direction next time. As for yourself, will you take these results sitting down, or will you prepare yourself for an epic political comeback in 2024?
",
"no_electoral_majority_message": "Congratulations! You have won the 2020 election.
In spite of the 269-269 tie in the electoral college, Republicans control a majority of state delegations in the House of Representatives. A lot of liberals are absolutely distraught and outraged that the election came down to such a technicality, but hey, those are the rules!
",
"description_as_running_mate": "",
"candidate_score": 1,
"running_mate": false
}
},
{
"model": "campaign_trail.candidate",
"pk": 302,
"fields": {
"first_name": "Childish",
"last_name": "Pefectionists",
"election": 21,
"party": "Libertarian",
"state": "South Carolina",
"priority": 3,
"description": "'",
"color_hex": "#69a72a",
"secondary_color_hex": "#FFFFC0",
"is_active": 0,
"image_url": "'",
"electoral_victory_message": "'",
"electoral_loss_message": "'",
"no_electoral_majority_message": "'",
"description_as_running_mate": "'",
"candidate_score": 1,
"running_mate": false
}
},
{
"model": "campaign_trail.candidate",
"pk": 303,
"fields": {
"first_name": "The",
"last_name": "Democrats",
"election": 21,
"party": "Democratic",
"state": "Disarray",
"priority": 4,
"description": "How could things go so wrong?I mean, Tulsi wasn't perfect. But after all that happened under Trump, how could people vote for his low-calorie equivalent? We're not that disliked, are we?
And who knows what can happen now? Schultz is basically a Republican plant. We all know it. The...the bigotry...the tax cuts...all of it. Someone has to put a stop to this. Someone has to bring back common decency. But we have it in the bag this time. We have Congress, we know when.
",
"color_hex": "#739fd0",
"secondary_color_hex": "#A1FFA1",
"is_active": 1,
"image_url": "https://i.imgur.com/0M9Uff8.png",
"electoral_victory_message": "'",
"electoral_loss_message": "'",
"no_electoral_majority_message": "'",
"description_as_running_mate": "'",
"candidate_score": 2,
"running_mate": false
}
},
{
"model": "campaign_trail.candidate",
"pk": 304,
"fields": {
"first_name": "Jamie",
"last_name": "Dimon",
"election": 21,
"party": "Independent",
"state": "New York",
"priority": 5,
"description": "'",
"color_hex": "#0000FF",
"secondary_color_hex": "#90C0FF",
"is_active": 0,
"image_url": "https://i.imgur.com/WM8jBEh.png",
"electoral_victory_message": "'",
"electoral_loss_message": "'",
"no_electoral_majority_message": "'",
"description_as_running_mate": "Kamala Harris is a Senator from California who made her own run for President in 2020. She would be acceptable to moderates and financial supporters, has some appeal to progressives, and brings diversity to the ticket. She's not the preferred choice of most progressives.
",
"candidate_score": 0,
"running_mate": true
}
},
{
"model": "campaign_trail.candidate",
"pk": 305,
"fields": {
"first_name": "Chuck",
"last_name": "Schumer",
"election": 21,
"party": "Democratic",
"state": "New York",
"priority": 6,
"description": "'",
"color_hex": "#0000FF",
"secondary_color_hex": "#90C0FF",
"is_active": 0,
"image_url": "https://i.imgur.com/E8epWks.png",
"electoral_victory_message": "'",
"electoral_loss_message": "'",
"no_electoral_majority_message": "'",
"description_as_running_mate": "Susan Rice was a UN Ambassador and a National Security Advisor to Barack Obama, and brings decades of foreign policy experience. She would be a true center-left pick, but has never run for elected office. Her foreign policy record would also be a turnoff to progressives.
",
"candidate_score": 0,
"running_mate": true
}
},
{
"model": "campaign_trail.candidate",
"pk": 306,
"fields": {
"first_name": "Karen",
"last_name": "Bass",
"election": 21,
"party": "Democrat",
"state": "California",
"priority": 7,
"description": "'",
"color_hex": "#0000FF",
"secondary_color_hex": "#90C0FF",
"is_active": 0,
"image_url": "https://thecampaigntrail.net/static/images/karen-bass-2020.jpg",
"electoral_victory_message": "'",
"electoral_loss_message": "'",
"no_electoral_majority_message": "'",
"description_as_running_mate": "Karen Bass is a Congresswoman from California and Chair of the Congressional Black Caucus. She has taken more progressive policy stances (including support for Medicare For All) than some of the other candidates, with the attendant supporters and detractors.
",
"candidate_score": 0,
"running_mate": false
}
},
{
"model": "campaign_trail.candidate",
"pk": 309,
"fields": {
"first_name": "Donald J.",
"last_name": "Trump",
"election": 21,
"party": "Republican",
"state": "Florida",
"priority": 10,
"description": "'",
"color_hex": "#FF0000",
"secondary_color_hex": "#FFA0A0",
"is_active": 0,
"image_url": "https://i.imgur.com/KeKiR37.png",
"electoral_victory_message": "'",
"electoral_loss_message": "'",
"no_electoral_majority_message": "'",
"description_as_running_mate": "From the moment he was born in a plush Queens hospital, Donald J. Trump was taught that there are two types of person in the world; the killers, the winners, the people who reap life's rewards- and the losers. Trump has carried this counsel with him year after high-rolling year, and finally, he reached the top, the Grand Prize, the Killer among Killers, the Presidency.
But when another businessman, a nigh-mirror image of him, overtook him, it all changed. The establishment suits turned on him, cast him away like a dog. Was it over? Had he become another loser, another Freddy, another Mike Tyson? No. He refused to accept it. He'd claw his way back, become King of the Party again, by hook or by crook, by fair means or foul.
",
"candidate_score": 0,
"running_mate": true
}
},
{
"model": "campaign_trail.candidate",
"pk": 310,
"fields": {
"first_name": "Kevin",
"last_name": "McCarthy",
"election": 21,
"party": "Republican (Establishment)",
"state": "California",
"priority": 11,
"description": "'",
"color_hex": "#FF0000",
"secondary_color_hex": "#FFA0A0",
"is_active": 0,
"image_url": "https://i.imgur.com/QPt55is.png",
"electoral_victory_message": "'",
"electoral_loss_message": "'",
"no_electoral_majority_message": "'",
"description_as_running_mate": "Must it be him? Do we really have to nominate him again? Is there really nothing we can do? After all, this is the President who managed to lose to an Independent! An Independent! Haven't we tolerated his shenanigans long enough? Isn't it time for the adults to retake control of the party?
Heading up those adults is Bakersfield's Kevin McCarthy. McCarthy gained the gavel after reluctant, in-over-his-head-Paul Ryan was hounded out by the same Freedom Caucus that installed him, and he's hoping he can avoid ending up like him. Kev's mission is three-pronged; take back the House in 2022, find an alternative, any alternative, to Trump, in 2024, and guide them to victory in 2024. It seems simple, but perhaps it's a fool's errand. McCarthy can only pray the party isn't too far gone yet.",
"candidate_score": 0,
"running_mate": true
}
},
{
"model": "campaign_trail.candidate",
"pk": 311,
"fields": {
"first_name": "Spike",
"last_name": "Cohen",
"election": 21,
"party": "Libertarian",
"state": "Maryland",
"priority": 12,
"description": "'",
"color_hex": "#FFFF00",
"secondary_color_hex": "#FFFFC0",
"is_active": 0,
"image_url": "'",
"electoral_victory_message": "'",
"electoral_loss_message": "'",
"no_electoral_majority_message": "'",
"description_as_running_mate": "'",
"candidate_score": 0,
"running_mate": true
}
},
{
"model": "campaign_trail.candidate",
"pk": 312,
"fields": {
"first_name": "Angela",
"last_name": "Walker",
"election": 21,
"party": "Green",
"state": "Wisconsin",
"priority": 13,
"description": "'",
"color_hex": "#00C100",
"secondary_color_hex": "#A1FFA1",
"is_active": 0,
"image_url": "'",
"electoral_victory_message": "'",
"electoral_loss_message": "'",
"no_electoral_majority_message": "'",
"description_as_running_mate": "'",
"candidate_score": 0,
"running_mate": false
}
}
];
campaignTrail_temp.running_mate_json = [
{
"model": "campaign_trail.running_mate",
"pk": 200,
"fields": {
"candidate": 300,
"running_mate": 304
}
},
{
"model": "campaign_trail.running_mate",
"pk": 201,
"fields": {
"candidate": 303,
"running_mate": 305
}
},
{
"model": "campaign_trail.running_mate",
"pk": 205,
"fields": {
"candidate": 301,
"running_mate": 309
}
},
{
"model": "campaign_trail.running_mate",
"pk": 206,
"fields": {
"candidate": 301,
"running_mate": 310
}
},
{
"model": "campaign_trail.running_mate",
"pk": 207,
"fields": {
"candidate": 302,
"running_mate": 311
}
}
];
campaignTrail_temp.opponents_default_json = [
{
"election": 21,
"candidates": [
300,
301,
302,
303,
306,
312
]
}
];
campaignTrail_temp.opponents_weighted_json = [
{
"election": 21,
"candidates": [
300,
301,
302,
303,
306,
312
]
}
];
campaignTrail_temp.modBoxTheme = {
"header_color": "#036244",
"header_text_color": "#ffffff",
"header_text_shadow": "1px 1px 2px rgba(0, 0, 0, 0.7)",
"description_background_color": "#f8f8f8",
"description_text_color": "#000000",
"main_color": "#0f3e30",
"secondary_color": "#ffffff",
"secondary_hover_color": "#dbdcdf",
"scrollbar_color": "#ffffff #0f3e30",
"scrollbar_width": "auto",
"image_border": "4px solid #ffffff",
"ui_text_color": "#111827"
};
jet_data = {
"headerColor": "#036244",
"headerTextColor": "#ffffff",
"windowColor": "#ffffff",
"containerColor": "#0f3e30",
"innerWindowColor": "#c4d4ca",
"innerWindowTextColor": "#000000",
"descriptionWindowColor": "#f8f8f8",
"descriptionWindowTextColor": "#000000",
"startButtonColor": "#e8e8e8",
"bannerImageUrl": "https://i.imgur.com/WqGdogO.png",
"backgroundImageUrl": "https://media.gettyimages.com/id/2161039356/photo/starbucks-coffee-at-kansai-international-airport-japan.jpg?s=612x612&w=0&k=20&c=edRitKE5mGUsyyapRRQhNweYlWRO6clVtguF__UUAkQ=",
"gameTitle": "CEOTUS",
"customQuote": "",
"quoteTextColor": "#ffffff",
"endingTextColor": "#000000",
"modBoxTheme": {
"header_color": "#036244",
"header_text_color": "#ffffff",
"header_image_url": "",
"header_text_shadow": "1px 1px 2px rgba(0, 0, 0, 0.7)",
"header_font": "",
"header_margin": "",
"description_background_color": "#f8f8f8",
"description_text_color": "#000000",
"main_color": "#0f3e30",
"secondary_color": "#ffffff",
"secondary_hover_color": "#dbdcdf",
"scrollbar_color": "#ffffff #0f3e30",
"scrollbar_width": "auto",
"image_border": "4px solid #ffffff",
"election_image_display": "",
"ui_text_color": "#111827"
}
};
//#startcode
function applyTheme(theme) {
const gameHeader = document.querySelector(".game_header");
if (gameHeader && theme.coloring_title) {
gameHeader.style.backgroundColor = theme.coloring_title;
}
const gameWindow = document.getElementById("game_window");
if (gameWindow && theme.coloring_window) {
gameWindow.style.backgroundColor = theme.coloring_window;
}
const container = document.querySelector(".container");
if (container && theme.coloring_container) {
container.style.backgroundColor = theme.coloring_container;
}
const headerImg = document.getElementById("header");
if (headerImg && theme.header_image) {
headerImg.src = theme.header_image;
}
if (theme.body_background) {
document.body.style.backgroundImage = `url("${theme.body_background}")`;
document.body.style.backgroundSize = "cover";
document.body.style.backgroundAttachment = "fixed";
}
const style = document.createElement("style");
style.textContent = `
#results_container { color: #000000; }
#wittyquote { color: #ffffff; }
.game_header h2 { color: #ffffff; }
.inner_window_w_desc { background-color: #c4d4ca !important; color: #000000; }
.inner_window_front, .person_description_window, .election_description_window, .description_window_small { background-color: #f8f8f8 !important; color: #000000; }
.campaign_trail_start_emphasis { background-color: #e8e8e8 !important; }
`;
document.head.appendChild(style);
}
corrr = "\n CEOTUS
\n ";
const theme = nct_stuff.themes[nct_stuff.selectedTheme];
// define / override theme values
theme.coloring_title = "#036244";
theme.coloring_window = "#ffffff";
theme.coloring_container = "#0f3e30";
theme.header_image = "https://i.imgur.com/WqGdogO.png";
theme.body_background = "https://media.gettyimages.com/id/2161039356/photo/starbucks-coffee-at-kansai-international-airport-japan.jpg?s=612x612&w=0&k=20&c=edRitKE5mGUsyyapRRQhNweYlWRO6clVtguF__UUAkQ=";
applyTheme(theme);
// This is a modified version of the music player
// used in the mod Infinite Carnage.
class Song {
constructor(title, artist, coverLink, audioOrYouTube) {
this.title = title;
this.artist = artist;
this.coverLink = coverLink;
// detect and parse YouTube IDs, otherwise treat as a standard audio link
const ytMatch = audioOrYouTube?.match(
/(?:youtu\.be\/|youtube\.com\/(?:watch\?v=|embed\/|v\/|shorts\/))([\w-]{11})/
);
if (ytMatch) {
this.youtubeId = ytMatch[1];
this.audioLink = null;
} else {
this.youtubeId = null;
this.audioLink = audioOrYouTube || null;
}
}
getTitle() { return this.title; }
getArtist() { return this.artist; }
getCoverLink() { return this.coverLink; }
getAudioLink() { return this.audioLink; }
getYouTubeId() { return this.youtubeId; }
}
class Playlist {
constructor() {
this.songs = [];
this.currentSongIndex = 0;
}
addSong(song) {
this.songs.push(song);
}
getCurrentSong() {
return this.songs[this.currentSongIndex];
}
playNext() {
if (this.songs.length === 0) return;
this.currentSongIndex = (this.currentSongIndex + 1) % this.songs.length;
}
playPrevious() {
if (this.songs.length === 0) return;
this.currentSongIndex = (this.currentSongIndex - 1 + this.songs.length) % this.songs.length;
}
}
window.Playlist = Playlist;
window.Song = Song;
let playlist = null;
let currentPlaylistIndex = 0;
let isRepeat = false;
let ytApiReady = false;
let ytPlayer = null;
let ytPlayerReady = false;
let ytProgressTimer = null;
let ytAutoAdvancing = false;
let ytConstructing = false;
const ytCallbacks = [];
function flushYTCallbacks() {
if (!ytPlayer || typeof ytPlayer.loadVideoById !== "function") return;
while (ytCallbacks.length > 0) {
const callback = ytCallbacks.shift();
callback?.();
}
}
(function injectYouTubeAPI() {
if (document.getElementById("yt-iframe-api")) return;
const tag = document.createElement("script");
tag.id = "yt-iframe-api";
tag.src = "https://www.youtube.com/iframe_api";
document.head.appendChild(tag);
})();
window.onYouTubeIframeAPIReady = function () {
ytApiReady = true;
};
const ASSETS = {
bg: "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/musicplaerbackground.png",
infoBg: "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/spotify.png",
btnPlaylist: "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/shuffle.png",
btnPrev: "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/back2.png",
btnPlay: "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/play2.png",
btnPause: "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/pause2.png",
btnNext: "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/forward2.png",
btnRepeat: "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/Repeat.png",
volIcon: "https://file.garden/aZpOy1sRbiDb3nw_/AC%20File%20Change/volume2.png"
};
const allPlaylists = [
[
new Song("oval_office", "AJCW", "https://i.scdn.co/image/ab67616d00001e02adb7d224828f4be4d786eec6", "https://youtu.be/G1T_BQEJ8-g"),
new Song("My heart will stop in joy", "The Caretaker", "https://i.scdn.co/image/ab67616d00001e02a3b886e9a6ae396fb568d746", "https://youtu.be/1V69TwJhuOU"),
new Song("Love Me", "JMSN", "https://i.scdn.co/image/ab67616d0000b2739ff39b31a327e5440076a9f9", "https://youtu.be/k-NvyxGHG3I"),
new Song("Kiss Me (Kill Me)", "JerryTerry", "https://i1.sndcdn.com/artworks-mw2CItfvjbEWzzE4-tbmoPw-t500x500.jpg", "https://youtu.be/1XxhVkIx6-M"),
new Song("INVISIBLE", "Duran Duran", "https://i.scdn.co/image/ab67616d00001e026a5be5601ccc727d0dbb9c1f", "https://youtu.be/FKwVFWwA_x8"),
new Song("Heartaches by the Number", "Billy Cobb", "https://i.scdn.co/image/ab67616d0000b2732ab7f4761cf29426172bcc16", "https://youtu.be/EiTUW6VR5T4"),
new Song("Franklin Shepard, Inc.", "New Broadway Cast of Merrily We Roll Along", "https://i.scdn.co/image/ab67616d00001e0200ab137f1e93438063661e35", "https://youtu.be/GoyTjfExX6Q")
]
];
function isYouTubeSong(song) {
return !!song?.getYouTubeId?.();
}
function getScaledVolume(volumeStep) {
const normalized = volumeStep / 9;
return Math.pow(normalized, 3);
}
function stopYTProgressPump() {
if (ytProgressTimer) {
clearInterval(ytProgressTimer);
ytProgressTimer = null;
}
}
function startYTProgressPump(progressBar) {
stopYTProgressPump();
ytProgressTimer = setInterval(() => {
if (!progressBar) return;
const duration = backendGetDuration();
const current = backendGetCurrentTime();
const progress = duration > 0 ? (current / duration) * 100 : 0;
progressBar.value = progress;
progressBar.style.background =
`linear-gradient(to right, #16893f ${progress}%, #ddd ${progress}%)`;
}, 250);
}
function syncYTVolumeFromSlider() {
const volumeSlider = document.getElementById("volumeSlider");
if (!volumeSlider || !ytPlayer) return;
const volumeStep = parseInt(volumeSlider.value, 10);
const scaled = getScaledVolume(volumeStep);
ytPlayer.setVolume(Math.round(scaled * 100));
if (scaled === 0) ytPlayer.mute();
else ytPlayer.unMute();
}
function ensureYTPlayer(onReady) {
if (onReady) ytCallbacks.push(onReady);
if (ytPlayer && ytPlayerReady && typeof ytPlayer.loadVideoById === "function") {
flushYTCallbacks();
return;
}
if (ytConstructing) return;
const createPlayer = () => {
let holder = document.getElementById("ytplayer");
if (!holder) {
const el = document.createElement("div");
el.id = "ytplayer";
el.style.width = "0px";
el.style.height = "0px";
el.style.position = "absolute";
el.style.overflow = "hidden";
el.style.pointerEvents = "none";
document.body.appendChild(el);
holder = el;
}
ytConstructing = true;
try {
ytPlayer = new YT.Player("ytplayer", {
height: "0",
width: "0",
videoId: "",
playerVars: {
autoplay: 0,
controls: 0,
disablekb: 1,
fs: 0,
rel: 0,
playsinline: 1
},
events: {
onReady: (event) => {
ytConstructing = false;
ytPlayer = event.target;
ytPlayerReady = true;
syncYTVolumeFromSlider();
flushYTCallbacks();
},
onStateChange: (e) => {
if (e.data === YT.PlayerState.ENDED) {
ytAutoAdvancing = true;
window._spotifyOnYTEnded?.();
}
if (e.data === YT.PlayerState.PLAYING && ytAutoAdvancing) {
syncYTVolumeFromSlider();
ytAutoAdvancing = false;
}
}
}
});
} catch (e) {
ytConstructing = false;
console.log("Could not create the YouTube player.", e);
}
};
if (!ytApiReady || !window.YT || !window.YT.Player) {
const timer = setInterval(() => {
if (ytApiReady && window.YT && window.YT.Player) {
clearInterval(timer);
createPlayer();
}
}, 50);
} else {
createPlayer();
}
}
function backendSetSrcAndLoad(song, audio, progressBar) {
if (!song) return;
if (isYouTubeSong(song)) {
ensureYTPlayer(() => {
const id = song.getYouTubeId();
if (ytAutoAdvancing) {
try { ytPlayer.mute(); } catch (e) {}
ytPlayer?.loadVideoById?.(id);
} else {
ytPlayer?.loadVideoById?.(id);
syncYTVolumeFromSlider();
}
if (progressBar) startYTProgressPump(progressBar);
});
audio.pause();
audio.src = "";
audio.load();
} else {
stopYTProgressPump();
if (ytPlayer) ytPlayer.stopVideo?.();
audio.src = song.getAudioLink() || "";
audio.load();
}
}
function backendPlay(audio) {
const song = playlist?.getCurrentSong();
if (!song) return;
if (isYouTubeSong(song)) {
ensureYTPlayer(() => {
ytPlayer?.playVideo?.();
});
} else {
audio.play().catch(e => console.log("Direct playback deferred for user interaction.", e));
}
}
function backendPause(audio) {
const song = playlist?.getCurrentSong();
if (!song) return;
if (isYouTubeSong(song)) {
ytPlayer?.pauseVideo?.();
} else {
audio.pause();
}
}
function backendSetVolume(audio, volume) {
audio.volume = volume;
const song = playlist?.getCurrentSong();
if (isYouTubeSong(song) && ytPlayer) {
ytPlayer.setVolume(Math.round(volume * 100));
if (volume === 0) ytPlayer.mute();
else ytPlayer.unMute();
}
}
function backendGetCurrentTime() {
const song = playlist?.getCurrentSong();
if (isYouTubeSong(song) && ytPlayer) {
return ytPlayer.getCurrentTime?.() || 0;
}
const audio = document.getElementById("audio");
return audio ? audio.currentTime || 0 : 0;
}
function backendGetDuration() {
const song = playlist?.getCurrentSong();
if (isYouTubeSong(song) && ytPlayer) {
return ytPlayer.getDuration?.() || 0;
}
const audio = document.getElementById("audio");
return audio ? audio.duration || 0 : 0;
}
function backendSeekTo(seconds) {
const song = playlist?.getCurrentSong();
const audio = document.getElementById("audio");
if (isYouTubeSong(song) && ytPlayer) {
ytPlayer.seekTo(seconds, true);
} else if (audio && audio.duration > 0) {
audio.currentTime = seconds;
}
}
function updateUI(activePlaylist) {
const currentSong = activePlaylist.getCurrentSong();
const player = document.getElementById("player");
if (!player || !currentSong) return;
player.querySelector("#cover").src = currentSong.getCoverLink() || "";
player.querySelector("#title").textContent = currentSong.getTitle();
player.querySelector("#artist").textContent = currentSong.getArtist();
}
window.updateUI = updateUI;
function changePlaylist(newPlaylist) {
playlist = newPlaylist;
playlist.currentSongIndex = 0;
updateUI(playlist);
const audio = document.getElementById("audio");
const progressBar = document.getElementById("progress-bar");
const playPauseButton = document.getElementById("playPauseButton");
if (audio && progressBar) {
backendSetSrcAndLoad(playlist.getCurrentSong(), audio, progressBar);
backendPlay(audio);
if (playPauseButton) playPauseButton.src = ASSETS.btnPause;
}
}
window.changePlaylist = changePlaylist;
function setupMusicPlayer() {
const gameWindow = document.getElementById("game_window");
if (!gameWindow) return;
if (document.getElementById("player")) return;
isRepeat = localStorage.getItem("IC_repeat_mode") === "true";
currentPlaylistIndex = parseInt(localStorage.getItem("IC_selected_playlist") || "0", 10);
const savedSongIndex = parseInt(localStorage.getItem("IC_selected_song") || "0", 10);
const savedVolume = localStorage.getItem("IC_music_volume");
const initialVolume = savedVolume !== null ? parseInt(savedVolume, 10) : 1;
playlist = new Playlist();
allPlaylists[currentPlaylistIndex].forEach(data => playlist.addSong(data));
playlist.currentSongIndex = (savedSongIndex >= 0 && savedSongIndex < playlist.songs.length) ? savedSongIndex : 0;
const style = document.createElement("style");
style.textContent = `
#player {
border: 3px solid #C9C9C9;
display: flex;
flex-direction: row;
align-items: center;
height: 191px;
background-image: url("${ASSETS.bg}");
font-family: sans-serif;
}
#display-box {
display: flex;
align-items: center;
width: 50%;
}
#cover {
width: 176px;
height: 176px;
object-fit: cover;
}
#info-container {
display: flex;
flex-direction: row;
height: 178px;
width: 127px;
margin-top: 3px;
background-image: url("${ASSETS.infoBg}");
background-size: cover;
color: white;
}
#song-info {
width: 100%;
padding: 5px;
box-sizing: border-box;
}
#title {
font-weight: normal;
white-space: pre-line;
margin: 10px 2px;
font-size: 14px;
}
#artist {
margin: 0;
font-size: 11px;
margin: auto 2px;
opacity: 0.8;
}
#controls-container {
display: flex;
flex-direction: column;
align-items: center;
margin: 10px;
width: 100%;
padding-bottom: 3%;
}
#controls {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
width: 80%;
gap: 5px;
}
#controls img {
cursor: pointer;
transition: opacity 0.1s;
}
#controls img:hover {
opacity: 0.8;
}
#progress-bar-container {
width: 100%;
}
#progress-bar {
width: 80%;
margin: 20px auto 0 auto;
display: flex;
height: 10px;
background: #ddd;
border-radius: 5px;
appearance: none;
cursor: pointer;
background-image: linear-gradient(to right, #16893f 0%, #ddd 0%);
background-size: 100% 100%;
background-repeat: no-repeat;
position: relative;
}
#progress-bar::-webkit-slider-thumb {
appearance: none;
height: 14px;
width: 14px;
border-radius: 50%;
background: #767676;
margin-top: -1px;
border: none;
box-shadow: none;
}
#progress-bar::-moz-range-thumb {
height: 14px;
width: 14px;
border-radius: 50%;
background: #767676;
border: none;
box-shadow: none;
}
#volume-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
#volume-slider-container {
display: flex;
align-items: center;
justify-content: center;
height: 126px;
margin-top: auto;
}
#volumeSlider {
appearance: none;
transform: rotate(-90deg);
height: 10px;
width: 100px;
background: #ddd;
border-radius: 5px;
cursor: pointer;
background-image: linear-gradient(to right, #16893f 0%, #ddd 0%);
background-size: 100% 100%;
background-repeat: no-repeat;
margin: 0;
padding: 0;
}
#volumeSlider::-webkit-slider-thumb {
appearance: none;
height: 14px;
width: 14px;
border-radius: 50%;
background: #767676;
border: none;
margin-top: -1px;
}
#volumeSlider::-moz-range-thumb {
height: 14px;
width: 14px;
border-radius: 50%;
background: #767676;
border: none;
}
`;
document.head.appendChild(style);
const playerContainer = document.createElement("div");
playerContainer.id = "player";
playerContainer.innerHTML = `
`;
gameWindow.insertAdjacentElement("afterend", playerContainer);
const playPauseButton = document.getElementById("playPauseButton");
const playlistSwitcher = document.getElementById("playlistSwitcher");
const prevButton = document.getElementById("prevButton");
const nextButton = document.getElementById("nextButton");
const repeatButton = document.getElementById("repeatButton");
const progressBar = document.getElementById("progress-bar");
const volumeSlider = document.getElementById("volumeSlider");
const audio = document.createElement("audio");
audio.id = "audio";
document.body.appendChild(audio);
volumeSlider.value = initialVolume;
const initialVolumePercent = (initialVolume / 9) * 100;
volumeSlider.style.background = `linear-gradient(to right, #16893f ${initialVolumePercent}%, #ddd ${initialVolumePercent}%)`;
audio.volume = getScaledVolume(initialVolume);
repeatButton.style.opacity = isRepeat ? "0.5" : "1.0";
window._spotifyOnYTEnded = function () {
if (isRepeat) {
backendSetSrcAndLoad(playlist.getCurrentSong(), audio, progressBar);
backendPlay(audio);
playPauseButton.src = ASSETS.btnPause;
} else {
playlist.playNext();
updateUI(playlist);
backendSetSrcAndLoad(playlist.getCurrentSong(), audio, progressBar);
backendPlay(audio);
playPauseButton.src = ASSETS.btnPause;
localStorage.setItem("IC_selected_song", playlist.currentSongIndex);
}
};
audio.addEventListener("timeupdate", () => {
const duration = backendGetDuration();
const current = backendGetCurrentTime();
const progress = duration > 0 ? (current / duration) * 100 : 0;
progressBar.value = progress;
progressBar.style.background = `linear-gradient(to right, #16893f ${progress}%, #ddd ${progress}%)`;
});
audio.addEventListener("ended", () => {
window._spotifyOnYTEnded();
});
progressBar.addEventListener("input", () => {
const duration = backendGetDuration();
const seekTime = (progressBar.value / 100) * duration;
backendSeekTo(seekTime);
});
volumeSlider.addEventListener("input", () => {
const volumeStep = parseInt(volumeSlider.value, 10);
const scaled = getScaledVolume(volumeStep);
backendSetVolume(audio, scaled);
const percent = (volumeStep / 9) * 100;
volumeSlider.style.background = `linear-gradient(to right, #16893f ${percent}%, #ddd ${percent}%)`;
localStorage.setItem("IC_music_volume", volumeStep);
});
playPauseButton.addEventListener("click", () => {
const song = playlist.getCurrentSong();
let isPaused = true;
if (isYouTubeSong(song)) {
const state = ytPlayer?.getPlayerState?.();
isPaused = !(state === YT.PlayerState.PLAYING);
} else {
isPaused = audio.paused;
}
if (isPaused) {
backendPlay(audio);
playPauseButton.src = ASSETS.btnPause;
} else {
backendPause(audio);
playPauseButton.src = ASSETS.btnPlay;
}
});
prevButton.addEventListener("click", () => {
playlist.playPrevious();
updateUI(playlist);
backendSetSrcAndLoad(playlist.getCurrentSong(), audio, progressBar);
backendPlay(audio);
playPauseButton.src = ASSETS.btnPause;
localStorage.setItem("IC_selected_song", playlist.currentSongIndex);
});
nextButton.addEventListener("click", () => {
playlist.playNext();
updateUI(playlist);
backendSetSrcAndLoad(playlist.getCurrentSong(), audio, progressBar);
backendPlay(audio);
playPauseButton.src = ASSETS.btnPause;
localStorage.setItem("IC_selected_song", playlist.currentSongIndex);
});
playlistSwitcher.addEventListener("click", () => {
currentPlaylistIndex = (currentPlaylistIndex + 1) % allPlaylists.length;
playlist = new Playlist();
allPlaylists[currentPlaylistIndex].forEach(data => playlist.addSong(data));
playlist.currentSongIndex = 0;
updateUI(playlist);
backendSetSrcAndLoad(playlist.getCurrentSong(), audio, progressBar);
backendPlay(audio);
playPauseButton.src = ASSETS.btnPause;
localStorage.setItem("IC_selected_playlist", currentPlaylistIndex);
localStorage.setItem("IC_selected_song", 0);
});
repeatButton.addEventListener("click", () => {
isRepeat = !isRepeat;
repeatButton.style.opacity = isRepeat ? "0.5" : "1.0";
localStorage.setItem("IC_repeat_mode", isRepeat);
});
updateUI(playlist);
backendSetSrcAndLoad(playlist.getCurrentSong(), audio, progressBar);
backendPlay(audio);
}
setupMusicPlayer();
//#endcode