mirror of
				https://github.com/krateng/maloja.git
				synced 2025-11-04 03:27:05 -05:00 
			
		
		
		
	Fixed week pulse view on start page
This commit is contained in:
		
							parent
							
								
									d07ca92252
								
							
						
					
					
						commit
						88cbce33e2
					
				@ -2,10 +2,18 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
chrome.tabs.onUpdated.addListener(onTabUpdated);
 | 
					chrome.tabs.onUpdated.addListener(onTabUpdated);
 | 
				
			||||||
chrome.tabs.onRemoved.addListener(onTabRemoved);
 | 
					chrome.tabs.onRemoved.addListener(onTabRemoved);
 | 
				
			||||||
chrome.tabs.onActivated.addListener(onTabChanged);
 | 
					 | 
				
			||||||
chrome.runtime.onMessage.addListener(onPlaybackUpdate);
 | 
					chrome.runtime.onMessage.addListener(onPlaybackUpdate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var patterns = [
 | 
				
			||||||
 | 
						"https://music.youtube.com",
 | 
				
			||||||
 | 
						"http://music.youtube.com"
 | 
				
			||||||
 | 
					];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function onTabUpdated(tabId, changeInfo, tab) {
 | 
					function onTabUpdated(tabId, changeInfo, tab) {
 | 
				
			||||||
 | 
						if (changeInfo.status !== "complete") {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	console.log("Update")
 | 
						console.log("Update")
 | 
				
			||||||
	chrome.tabs.get(tabId,party)
 | 
						chrome.tabs.get(tabId,party)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -14,26 +22,19 @@ function onTabRemoved() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function onTabChanged(activeInfo) {
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function party(tab) {
 | 
					function party(tab) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var patterns = [
 | 
					 | 
				
			||||||
		"https://music.youtube.com",
 | 
					 | 
				
			||||||
		"http://music.youtube.com"
 | 
					 | 
				
			||||||
	];
 | 
					 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	importantPage = false
 | 
						importantPage = false
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	for (var i=0;i<patterns.length;i++) {
 | 
						for (var i=0;i<patterns.length;i++) {
 | 
				
			||||||
		if (tab.url.startsWith(patterns[i])) {
 | 
							if (tab.url.startsWith(patterns[i])) {
 | 
				
			||||||
			importantPage = true
 | 
								importantPage = true
 | 
				
			||||||
			
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	if (importantPage) {
 | 
						if (importantPage) {
 | 
				
			||||||
		window.setTimeout(function(){chrome.tabs.executeScript(tab.id,{"file":"contentScript.js"})},1000); // youtube for some reason decides to not update the artist immediately
 | 
							window.setTimeout(function(){chrome.tabs.executeScript(tab.id,{"file":"contentScript.js"})},1000); // youtube for some reason decides to not update the artist immediately
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -65,21 +66,21 @@ function startPlayback(artist,title,seconds) {
 | 
				
			|||||||
	// CASE 1: Resuming playback of previously played title
 | 
						// CASE 1: Resuming playback of previously played title
 | 
				
			||||||
	if (artist == currentArtist && title == currentTitle && !currentlyPlaying) {
 | 
						if (artist == currentArtist && title == currentTitle && !currentlyPlaying) {
 | 
				
			||||||
		console.log("Resuming playback")
 | 
							console.log("Resuming playback")
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		// Already played full song
 | 
							// Already played full song
 | 
				
			||||||
		while (alreadyPlayed > currentLength) {
 | 
							while (alreadyPlayed > currentLength) {
 | 
				
			||||||
			alreadyPlayed = alreadyPlayed - currentLength
 | 
								alreadyPlayed = alreadyPlayed - currentLength
 | 
				
			||||||
			scrobble(currentArtist,currentTitle,currentLength)
 | 
								scrobble(currentArtist,currentTitle,currentLength)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		setUpdate()
 | 
							setUpdate()
 | 
				
			||||||
		currentlyPlaying = true
 | 
							currentlyPlaying = true
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	// CASE 2: New track is being played
 | 
						// CASE 2: New track is being played
 | 
				
			||||||
	else if (artist != currentArtist || title != currentTitle) {
 | 
						else if (artist != currentArtist || title != currentTitle) {
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		//first inform ourselves that the previous track has now been stopped for good
 | 
							//first inform ourselves that the previous track has now been stopped for good
 | 
				
			||||||
		stopPlayback(artist,title)
 | 
							stopPlayback(artist,title)
 | 
				
			||||||
		//then initialize new playback
 | 
							//then initialize new playback
 | 
				
			||||||
@ -97,25 +98,25 @@ function startPlayback(artist,title,seconds) {
 | 
				
			|||||||
// the artist and title arguments are not attributes of the track being stopped, but of the track active now
 | 
					// the artist and title arguments are not attributes of the track being stopped, but of the track active now
 | 
				
			||||||
// they are here to recognize whether the playback has been paused or completely ended / replaced
 | 
					// they are here to recognize whether the playback has been paused or completely ended / replaced
 | 
				
			||||||
function stopPlayback(artist,title) {
 | 
					function stopPlayback(artist,title) {
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	//CASE 1: Playback just paused OR CASE 2: Playback ended
 | 
						//CASE 1: Playback just paused OR CASE 2: Playback ended
 | 
				
			||||||
	if (currentlyPlaying) {
 | 
						if (currentlyPlaying) {
 | 
				
			||||||
		d = setUpdate()
 | 
							d = setUpdate()
 | 
				
			||||||
		alreadyPlayed = alreadyPlayed + d
 | 
							alreadyPlayed = alreadyPlayed + d
 | 
				
			||||||
		console.log(d + " seconds played since last update, " + alreadyPlayed + " seconds played overall")
 | 
							console.log(d + " seconds played since last update, " + alreadyPlayed + " seconds played overall")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
	// Already played full song
 | 
						// Already played full song
 | 
				
			||||||
	while (alreadyPlayed > currentLength) {
 | 
						while (alreadyPlayed > currentLength) {
 | 
				
			||||||
		alreadyPlayed = alreadyPlayed - currentLength
 | 
							alreadyPlayed = alreadyPlayed - currentLength
 | 
				
			||||||
		scrobble(currentArtist,currentTitle,currentLength)
 | 
							scrobble(currentArtist,currentTitle,currentLength)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
		
 | 
					 | 
				
			||||||
	currentlyPlaying = false
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	
 | 
						currentlyPlaying = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	//ONLY CASE 2: Playback ended
 | 
						//ONLY CASE 2: Playback ended
 | 
				
			||||||
	if (artist != currentArtist || title != currentTitle) {
 | 
						if (artist != currentArtist || title != currentTitle) {
 | 
				
			||||||
		if (alreadyPlayed > currentLength / 2) {
 | 
							if (alreadyPlayed > currentLength / 2) {
 | 
				
			||||||
@ -148,7 +149,7 @@ function ostopPlayback(artist,title) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function ostartPlayback(artist,title,seconds) {
 | 
					function ostartPlayback(artist,title,seconds) {
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	console.log("Playback started!")
 | 
						console.log("Playback started!")
 | 
				
			||||||
	if (artist == currentArtist && title == currentTitle && !currentlyPlaying) {
 | 
						if (artist == currentArtist && title == currentTitle && !currentlyPlaying) {
 | 
				
			||||||
		console.log("Still previous track!")
 | 
							console.log("Still previous track!")
 | 
				
			||||||
@ -160,7 +161,7 @@ function ostartPlayback(artist,title,seconds) {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
			alreadyPlayed = alreadyPlayed - currentLength
 | 
								alreadyPlayed = alreadyPlayed - currentLength
 | 
				
			||||||
			alreadyScrobbled = false
 | 
								alreadyScrobbled = false
 | 
				
			||||||
			
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		d = new Date()
 | 
							d = new Date()
 | 
				
			||||||
		t = Math.floor(d.getTime()/1000)
 | 
							t = Math.floor(d.getTime()/1000)
 | 
				
			||||||
@ -176,21 +177,21 @@ function ostartPlayback(artist,title,seconds) {
 | 
				
			|||||||
			delta = t - lastUpdate
 | 
								delta = t - lastUpdate
 | 
				
			||||||
			console.log("Since the last update, " + delta + " seconds of music have been played")
 | 
								console.log("Since the last update, " + delta + " seconds of music have been played")
 | 
				
			||||||
			alreadyPlayed = alreadyPlayed + delta
 | 
								alreadyPlayed = alreadyPlayed + delta
 | 
				
			||||||
			
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		console.log("The previous track was played for " + alreadyPlayed + " seconds, that's " + Math.floor(alreadyPlayed/currentLength * 100) + "% of its length.")
 | 
							console.log("The previous track was played for " + alreadyPlayed + " seconds, that's " + Math.floor(alreadyPlayed/currentLength * 100) + "% of its length.")
 | 
				
			||||||
		if (alreadyPlayed > currentLength/2 && !alreadyScrobbled) {
 | 
							if (alreadyPlayed > currentLength/2 && !alreadyScrobbled) {
 | 
				
			||||||
			console.log("Enough to scrobble: " + currentArtist + " - " + currentTitle)
 | 
								console.log("Enough to scrobble: " + currentArtist + " - " + currentTitle)
 | 
				
			||||||
			scrobble(currentArtist,currentTitle)
 | 
								scrobble(currentArtist,currentTitle)
 | 
				
			||||||
			
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else if (alreadyScrobbled) {
 | 
							else if (alreadyScrobbled) {
 | 
				
			||||||
			console.log("We already scrobbled this track tho.")
 | 
								console.log("We already scrobbled this track tho.")
 | 
				
			||||||
			alreadyScrobbled = false
 | 
								alreadyScrobbled = false
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
		console.log("But now, new track!")
 | 
							console.log("But now, new track!")
 | 
				
			||||||
		d = new Date()
 | 
							d = new Date()
 | 
				
			||||||
		t = Math.floor(d.getTime()/1000)
 | 
							t = Math.floor(d.getTime()/1000)
 | 
				
			||||||
@ -219,8 +220,8 @@ function scrobble(artist,title,seconds) {
 | 
				
			|||||||
			xhttp.send("artist=" + artiststring + "&title=" + titlestring + "&duration=" + seconds + "&key=" + APIKEY)
 | 
								xhttp.send("artist=" + artiststring + "&title=" + titlestring + "&duration=" + seconds + "&key=" + APIKEY)
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function setUpdate() {
 | 
					function setUpdate() {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ from utilities import clock
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from htmlmodules import module_scrobblelist, module_pulse, module_artistcharts_tiles, module_trackcharts_tiles
 | 
					from htmlmodules import module_scrobblelist, module_pulse, module_artistcharts_tiles, module_trackcharts_tiles
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		
 | 
					
 | 
				
			||||||
def instructions(keys):
 | 
					def instructions(keys):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# get start of week
 | 
						# get start of week
 | 
				
			||||||
@ -18,40 +18,40 @@ def instructions(keys):
 | 
				
			|||||||
	clock()
 | 
						clock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# artists
 | 
						# artists
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	topartists_total = module_artistcharts_tiles()
 | 
						topartists_total = module_artistcharts_tiles()
 | 
				
			||||||
	topartists_year = module_artistcharts_tiles(since="year")
 | 
						topartists_year = module_artistcharts_tiles(since="year")
 | 
				
			||||||
	topartists_month = module_artistcharts_tiles(since="month")
 | 
						topartists_month = module_artistcharts_tiles(since="month")
 | 
				
			||||||
	topartists_week = module_artistcharts_tiles(since=weekstart)
 | 
						topartists_week = module_artistcharts_tiles(since=weekstart)
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	clock("Artists")
 | 
						clock("Artists")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# tracks
 | 
						# tracks
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	toptracks_total = module_trackcharts_tiles()
 | 
						toptracks_total = module_trackcharts_tiles()
 | 
				
			||||||
	toptracks_year = module_trackcharts_tiles(since="year")
 | 
						toptracks_year = module_trackcharts_tiles(since="year")
 | 
				
			||||||
	toptracks_month = module_trackcharts_tiles(since="month")
 | 
						toptracks_month = module_trackcharts_tiles(since="month")
 | 
				
			||||||
	toptracks_week = module_trackcharts_tiles(since=weekstart)
 | 
						toptracks_week = module_trackcharts_tiles(since=weekstart)
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	clock("Tracks")
 | 
						clock("Tracks")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# scrobbles
 | 
						# scrobbles
 | 
				
			||||||
	html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True,earlystop=True)
 | 
						html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True,earlystop=True)
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	clock("Scrobbles")
 | 
						clock("Scrobbles")
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	# stats
 | 
						# stats
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	#(amount_day,amount_month,amount_year,amount_total) = database.get_scrobbles_num_multiple(("today","month","year",None))
 | 
						#(amount_day,amount_month,amount_year,amount_total) = database.get_scrobbles_num_multiple(("today","month","year",None))
 | 
				
			||||||
	#amount_month += amount_day
 | 
						#amount_month += amount_day
 | 
				
			||||||
	#amount_year += amount_month
 | 
						#amount_year += amount_month
 | 
				
			||||||
	#amount_total += amount_year
 | 
						#amount_total += amount_year
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	amount_day = database.get_scrobbles_num(since="today")
 | 
						amount_day = database.get_scrobbles_num(since="today")
 | 
				
			||||||
	scrobbles_today = "<a href='/scrobbles?since=today'>" + str(amount_day) + "</a>"
 | 
						scrobbles_today = "<a href='/scrobbles?since=today'>" + str(amount_day) + "</a>"
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	amount_month = database.get_scrobbles_num(since="month")
 | 
						amount_month = database.get_scrobbles_num(since="month")
 | 
				
			||||||
	scrobbles_month = "<a href='/scrobbles?since=month'>" + str(amount_month) + "</a>"
 | 
						scrobbles_month = "<a href='/scrobbles?since=month'>" + str(amount_month) + "</a>"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -60,25 +60,25 @@ def instructions(keys):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	amount_total = database.get_scrobbles_num()
 | 
						amount_total = database.get_scrobbles_num()
 | 
				
			||||||
	scrobbles_total = "<a href='/scrobbles'>" + str(amount_total) + "</a>"
 | 
						scrobbles_total = "<a href='/scrobbles'>" + str(amount_total) + "</a>"
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	clock("Amounts")
 | 
						clock("Amounts")
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	# pulse
 | 
						# pulse
 | 
				
			||||||
	dt = datetime.utcnow()
 | 
						dt = datetime.utcnow()
 | 
				
			||||||
	first_month = [dt.year-1,dt.month+1]
 | 
						first_month = [dt.year-1,dt.month+1]
 | 
				
			||||||
	dt_firstweek = dt - timedelta(11*7) - timedelta((6-dt.weekday()))
 | 
						dt_firstweek = dt - timedelta(11*7) - timedelta((tod.weekday() + 1) % 7)
 | 
				
			||||||
	first_week = [dt_firstweek.year,dt_firstweek.month,dt_firstweek.day]
 | 
						first_week = [dt_firstweek.year,dt_firstweek.month,dt_firstweek.day]
 | 
				
			||||||
	dt_firstday = dt - timedelta(6)
 | 
						dt_firstday = dt - timedelta(6)
 | 
				
			||||||
	first_day = [dt_firstday.year,dt_firstday.month,dt_firstday.day]
 | 
						first_day = [dt_firstday.year,dt_firstday.month,dt_firstday.day]
 | 
				
			||||||
	first_year = [dt.year - 9]
 | 
						first_year = [dt.year - 9]
 | 
				
			||||||
	if first_month[1] > 12: first_month = [first_month[0]+1,first_month[1]-12]
 | 
						if first_month[1] > 12: first_month = [first_month[0]+1,first_month[1]-12]
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	html_pulse_days = module_pulse(max_=7,since=first_day,step="day",trail=1)
 | 
						html_pulse_days = module_pulse(max_=7,since=first_day,step="day",trail=1)
 | 
				
			||||||
	html_pulse_weeks = module_pulse(max_=12,since=first_week,step="week",trail=1)
 | 
						html_pulse_weeks = module_pulse(max_=12,since=first_week,step="week",trail=1)
 | 
				
			||||||
	html_pulse_months = module_pulse(max_=12,since=first_month,step="month",trail=1)	
 | 
						html_pulse_months = module_pulse(max_=12,since=first_month,step="month",trail=1)
 | 
				
			||||||
	html_pulse_years = module_pulse(max_=10,since=first_year,step="year",trail=1)
 | 
						html_pulse_years = module_pulse(max_=10,since=first_year,step="year",trail=1)
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	
 | 
					
 | 
				
			||||||
	#html_pulse_week = module_pulse(max_=7,since=weekstart,step="day",trail=1)
 | 
						#html_pulse_week = module_pulse(max_=7,since=weekstart,step="day",trail=1)
 | 
				
			||||||
	#html_pulse_month = module_pulse(max_=30,since=[dt.year,dt.month],step="day",trail=1)
 | 
						#html_pulse_month = module_pulse(max_=30,since=[dt.year,dt.month],step="day",trail=1)
 | 
				
			||||||
	#html_pulse_year = module_pulse(max_=12,since=[dt.year],step="month",trail=1)
 | 
						#html_pulse_year = module_pulse(max_=12,since=[dt.year],step="month",trail=1)
 | 
				
			||||||
@ -100,6 +100,5 @@ def instructions(keys):
 | 
				
			|||||||
	"KEY_PULSE_MONTHS":html_pulse_months,"KEY_PULSE_YEARS":html_pulse_years,"KEY_PULSE_DAYS":html_pulse_days,"KEY_PULSE_WEEKS":html_pulse_weeks,
 | 
						"KEY_PULSE_MONTHS":html_pulse_months,"KEY_PULSE_YEARS":html_pulse_years,"KEY_PULSE_DAYS":html_pulse_days,"KEY_PULSE_WEEKS":html_pulse_weeks,
 | 
				
			||||||
	#"KEY_PULSE_YEAR":html_pulse_year,"KEY_PULSE_MONTH":html_pulse_month,"KEY_PULSE_WEEK":html_pulse_week
 | 
						#"KEY_PULSE_YEAR":html_pulse_year,"KEY_PULSE_MONTH":html_pulse_month,"KEY_PULSE_WEEK":html_pulse_week
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
					 | 
				
			||||||
	return (replace,pushresources)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return (replace,pushresources)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user