It’s been a very productive lunch break! I got a lot of the CSS doing what I wanted it to. I’m still cleaning some things up but I’m getting much closer to having something ready to release!
I also said we’d talk about user avatars. Right now there is no API for getting user avatars. Instead what I’ve done is devised a caching system that users the browsers local storage. As you browse the Plex Forums there is a small script that is scraping user avatars and storing the username and the image url in a map inside your browser. When it comes time to display an image for most recently commented there is no url on the page. So what I do is take the username of that individual and check it against the browser cache. I get the url and I insert that in the img tag. If there is no image it will display some default image which I’ve yet to determine. It’s an easy way to keep track of images until I can convince Plex to get me an API. In my testing it’s working well enough- I picked up almost 500 username to image url mappings in a minute or two of browsing. Since the cache is persistent between sessions this data will build up and then always be usable. Cache size should never get above 5MB as the browser API I’m using won’t allow it. I’ll be posting a the initial browser extension shortly using this caching code so anyone who wants to use the plugin will have an image cache created by the time I release the actual GUI changes.
Here’s the code snippet:
//Setup local storage so we can store a map of usernames and avatars
var localstorage = window['localStorage'];
var profilePhotos = document.getElementsByClassName('ProfilePhoto');
for(var i = 0; i < profilePhotos.length; i++) {
var imgUrl = profilePhotos*.src;
var username = profilePhotos*.alt;
localstorage[username] = imgUrl;
}