Posts tagged ‘JavaScript’

Modifying the Facebook Live Feed with Greasemonkey and jQuery

My wife recently expressed to me that she didn’t care for some of the events appearing in the Facebook Live Feed, namely the ones relating to her friends adding other people as friends or becoming fans of pages, because they tended to flood her feed and crowd out other events she was actually interested in.

Unfortunately, Facebook doesn’t provide any filtering for the feed outside of either entire applications or entire people. Upon inspecting the markup for the feed, I found that content was styled such that it was easy to refer to entire entries using CSS selectors. I then recalled that the Firefox web browser, which she uses, has available for it an extension called Greasemonkey that enables you to execute custom JavaScript for a specified set of web pages. I poked around for existing Greasemonkey user scripts to handle the task, but most seemed to try to do too much and I had trouble finding any that supported custom filtering of the Live Feed.

It had been a while since I looked at Greasemonkey, but apparently it’s gained some nice features since. One of these is the @require tag, which allows you to pull in a remote JavaScript file that Greasemonkey will smartly cache locally to be reused. I used this to add the jQuery library to my script using the copy hosted on Google AJAX Library APIs, at which point removing the feed entries my wife didn’t want only required a few lines of code.

I’ve pushed the user script to a github repository if you’d like to download it. I’ve made it extensible such that removing other entries by phrase only requires adding entries to an array at the top. If you have any improvements to make, please feel free to fork it. Enjoy!

More SWFUpload

So I ran into a little issue with SWFUpload. The user reporting the issue was using the latest version of IE6 on Windows XP. When they clicked a button set to call selectFiles on the SWFUpload instance in use, IE would display a JavaScript error stating something to the effect of, “Exception thrown and not caught.” When I actually checked the contents of the exception instance, the actual problem was reported as “Invalid function name.”

Working my way backward through the chain of execution, I could see that IE recognized selectFiles. At this point, I thought to check the Adobe Flash Player version to ensure that it matched the version of the SWFUpload Flash component that I was running. Sure enough, it was outdated. Once I installed version 9 and restarted IE, everything worked as expected.

I haven’t tried this on IE7 under a pre-9 Flash Player version (and in fact I’m not entirely certain you can get an older version of Flash Player that will run under IE7), so this may or may not also be possible under IE7 as well as IE6. If you want to test for the issue, simply catch any exception thrown when called selectFiles and alert the user accordingly.

SWFUpload

One of the tasks I was recently given at my job involved examining issues with a browser-based batch file upload component. The component that was being used, iBULC, required a separate installation of proprietary software on the client-side, had a rather clunky browser interface, and proved difficult to troubleshot. Rather than expending effort to get iBULC to work properly, I went in search of a new solution. That new solution is SWFUpload.

SWFUpload is a small file upload solution that supports selection and uploading of multiple files, all while exposing a flexible event-driven API to allow you to handle events on the client-side in whatever manner suits your needs. It has two components, a Flash file (supports Flash 8 and 9) and a JavaScript include. A little HTML and JavaScript allows you to include these two components in your application and define handler functions to intercepts whatever events might be relevant to your interface. I was amazed at how quickly I was able to get a solution working. The examples and bundled documentation are quite good.

I only experienced two issues with SWFUpload in the process of completing my task. The first was that ampersands were being HTML encoded in the POST request being sent by the SWFUpload Flash component to my PHP script on the server side for intercepting uploaded files. This caused PHP to be unable to parse the POST parameters correctly. Luckily, the issue had already been reported and a quick fix in the JavaScript component resolved the problem.

The other issue was in the Flash component not properly sending cookie values to the PHP script, even with the JavaScript plugin for handling cookies enabled. Apparently this issue is most likely due to a known bug in the Flash player for Firefox. The only method I was able to use to circumvent the issue required including cookie data as POST parameters and checking for them there in the server-side script. Obviously this is a quick-and-dirty solution and I hope I eventually get to apply a more proper solution.

One outside issue unrelated to SWFUpload that I also ran into in the process of completing this task was an odd error in Internet Explorer. Even though the page using SWFUpload ran fine in Firefox, IE consistently returned the error “Internet Explorer cannot open the Internet site, Operation aborted.” For whatever reason, IE apparently doesn’t like it when you try to run JavaScript within <script> tags inside a table if the JavaScript isn’t contained within a function. An obscure bug, but an annoying one nonetheless. Moving the offending JavaScript to its own function appeared to fix the problem.

Outside of those issues, I was quite happy with the results. I was able to put the new solution together within an afternoon, it uses the native OS interface for multiple file selection, and it allows me to respond to the events that occur in the file upload process however might be necessary. I’d definitely recommend that you check SWFUpload out if you’re in need of a similar solution.