function cleanupSearchOptionsLocalStorage() {
    localStorage.removeItem('search-options-songs');
    localStorage.removeItem('search-options-playlists');
}

function migratePlaylistFormat() {
    var playlists = JSON.parse(localStorage['playlists'] || '[]'),
        playlist,
        i = 0;

    for (i = 0; i < playlists.length; i += 1) {
        playlist = playlists[i]; 
        if (playlist.songs !== undefined) {
            playlist.videos = playlist.songs;
            delete playlist.songs;
        }
        if ('beta_youtube_sync' in localStorage) {
            if (playlist.remoteID === undefined) {
                playlist.remoteID = null;
            }
            if (playlist.isPrivate === undefined) {
                playlist.isPrivate = false;
            }
        }
    }

    localStorage['playlists'] = JSON.stringify(playlists);
}

function createBackup() {
    var backups = JSON.parse(localStorage['backups'] || '{}'),
        date = '2011-06-29';

    if (!(date in backups)) {
        backups[date] = JSON.parse(localStorage['playlists'] || '[]'); // Must parse so that later stringify won't doubly stringify
    }

    localStorage['backups'] = JSON.stringify(backups);
}

function migrateThemeSettings() {
    var settings = JSON.parse(localStorage['settings'] || '{}');
    
    if ('theme' in localStorage) {
        settings['theme'] = localStorage['theme'];
        localStorage.removeItem('theme');
    }

    localStorage['settings'] = JSON.stringify(settings);
}

function prefixWithLoggedOut() {
    var playlists = localStorage['playlists'] || '[]';
        settings = localStorage['settings'] || '{}';

    if (localStorage['loggedOut'] === undefined) {
        localStorage['loggedOut'] = '{"playlists":' + playlists + ', "settings":' + settings + '}';

        if (localStorage['settings'] !== undefined) {
            localStorage.removeItem('settings');
        }

        if (localStorage['playlists'] !== undefined) {
            localStorage.removeItem('playlists');
        }
    }
}

createBackup();
cleanupSearchOptionsLocalStorage();
migratePlaylistFormat();
migrateThemeSettings();
prefixWithLoggedOut();

@@ -1,1508 +1,4 @@
-function cleanupSearchOptionsLocalStorage() %7B%0A    localStorage.removeItem('search-options-songs');%0A    localStorage.removeItem('search-options-playlists');%0A%7D%0A%0Afunction migratePlaylistFormat() %7B%0A    var playlists = JSON.parse(localStorage%5B'playlists'%5D %7C%7C '%5B%5D'),%0A        playlist,%0A        i = 0;%0A%0A    for (i = 0; i %3C playlists.length; i += 1) %7B%0A        playlist = playlists%5Bi%5D; %0A        if (playlist.songs !== undefined) %7B%0A            playlist.videos = playlist.songs;%0A            delete playlist.songs;%0A        %7D%0A        if ('beta_youtube_sync' in localStorage) %7B%0A            if (playlist.remoteID === undefined) %7B%0A                playlist.remoteID = null;%0A            %7D%0A            if (playlist.isPrivate === undefined) %7B%0A                playlist.isPrivate = false;%0A            %7D%0A        %7D%0A    %7D%0A%0A    localStorage%5B'playlists'%5D = JSON.stringify(playlists);%0A%7D%0A%0Afunction createBackup() %7B%0A    var backups = JSON.parse(localStorage%5B'backups'%5D %7C%7C '%7B%7D'),%0A        date = '2011-06-29';%0A%0A    if (!(date in backups)) %7B%0A        backups%5Bdate%5D = JSON.parse(localStorage%5B'playlists'%5D %7C%7C '%5B%5D'); // Must parse so that later stringify won't doubly stringify%0A    %7D%0A%0A    localStorage%5B'backups'%5D = JSON.stringify(backups);%0A%7D%0A%0Afunction migrateThemeSettings() %7B%0A    var settings = JSON.parse(localStorage%5B'settings'%5D %7C%7C '%7B%7D');%0A    %0A    if ('theme' in localStorage) %7B%0A        settings%5B'theme'%5D = localStorage%5B'theme'%5D;%0A        localStorage.removeItem('theme');%0A    %7D%0A%0A    localStorage%5B'settings'%5D = JSON.stringify(settings);%0A%7D%0A%0A
 func
@@ -529,109 +529,8 @@
 %0A%7D%0A%0A
-createBackup();%0AcleanupSearchOptionsLocalStorage();%0AmigratePlaylistFormat();%0AmigrateThemeSettings();%0A
 pref

Remove old migration steps