YouTube Channel Unsubscribe #bookmarklet
I like YouTube, and often subscribe to new channels and unsubscribe after a while. There is a lot of good stuff on YouTube, and a lot of rubbish. YouTube has been smart in making it possible to easily add channels, and in my opinion they have put less thought into making it easy to leave the channels. In the case of multiple channels I would either need to go to each of the channels and remove them one by one, or I would go to My Feeds / My Subscriptions and remove them one by one from there. In both cases I need to modify the subscription settings shown below.
My issue with this is not that it takes a long time, although that is certainly a small factor. Or that having subscription management for a channel is overkill when I just want to leave a channel. Personally I believe that it should be manageable from one page, just push of a button, like subscribing. And it wasn’t, until today.
While examining the code I discovered that all the subscription changes are send using Ajax, with most of the relevant data in the query string, with the exception of the session token which is in the body. A subscribe/unsubscribe message generally contains the following information.:
- Channel Username
- Subscription Identifier
- Subscription Status (
unsubscribe, uploads, all_activity)
- Session Token
And a typical request URL looks like this:
window.subscribeaxc in some places and
gSecureTokens["ajax_subscriptions"] in others. And the main function used to perform the subscriptions events relies on some global variables and form fields, rather than passing the values straight to the function:
All in all it was pretty clear what I would need to do:
- research the variables and functions that already exist on YouTube for reuse
- write a proof of concept bookmarklet based on the research
- pick an existing central location for the subscription management
- write the subscription management bookmarklet containing:
- hidden form
- data access
- integrate it into a central location, the My Subscriptions page
- test it all
- release the bookmarklet
- convert to GreaseMonkey userscript
- write a blog post on my experience
The research didn’t need to be very thorough, as I had most of the answers I felt I needed, so I started writing my POC, which can be used on the page of a channel to unsubscribe. I wrote Unsubscribe From Current YouTube Channel (pastebin.com) in about 30 minutes, it was reasonably simple to interact on this part of the site, the page already had the hidden form elements needed for
onUpdateSubscription to play nice.
Next I started building the hidden form, due to the nature of the obfuscated code I new that I could make 90%, but the last 10% would be trial and error. I got a load of errors on the first run, but these were easily solved. All that remained in the development cycle was to merge the 3 scripts together and finish debugging. And this is the finished product:
Create YouTube Unsubscribe Buttons (pastebin.com)
It has currently been tested in FireFox, Safari and Chrome.
Here are all the links again:
- Unsubscribe From Current YouTube Channel (pastebin.com)
- Create YouTube Unsubscribe Buttons (pastebin.com)
- YouTube Unsubscribe Button (GreaseMonkey)