// ==UserScript== // @id www.dailymotion.com-42e0c072-f078-4276-8f84-952524d36896@http://foobar.com/baz // @name Dailymotion: "Included By" Feature // @version 0.9.9 // @namespace http://foobar.com/baz // @author David Toso // @description Show all playlists that include the current video // @include http://www.dailymotion.com/video/* // @require http://code.jquery.com/jquery-1.9.1.min.js // @grant GM_xmlhttpRequest // @run-at document-end // @downloadURL https://update.greasyfork.icu/scripts/3422/Dailymotion%3A%20%22Included%20By%22%20Feature.user.js // @updateURL https://update.greasyfork.icu/scripts/3422/Dailymotion%3A%20%22Included%20By%22%20Feature.meta.js // ==/UserScript== (function($){ // Wait for element given by selector to become available var waitFor = function(selector, cb) { if ($(selector).get(0)) return cb(); else setTimeout(function(){ waitFor(selector, cb); }, 200); }; // interate pair-wise through the given list var iter_pairwise = function(list, pair_cb) { var pair = [], i=0; while (i 1), obj.has_more); // returns: list, priorPages?, subsequentPages? } }); }; // determine your username if logged in var myUser; $('div.dm_login_info a.media-block').each(function(){ $(this).attr('href').replace(/^\/(.*)/, function(_m, _usr) { myUser = _usr; }); }); // fix tab styles (Dailymotion just plain broke this for all users) $('head').append(''); // Render a single playlist preview inside the given elem var display_playlist_preview = function(elem, playlist, preview) { var ownerStyle = (myUser === playlist.owner) ? 'color: white; background-color: #0079B8; ' : 'color: #42AEDC'; elem.append( ''+ ''+ ''+ '
'+ ''+preview.title+''+ ''+playlist.title+'
'+ 'by '+playlist.owner+'
'+ (playlist.size ? playlist.size+' video'+(playlist.size > 1 ? 's' : '') : '')+'
').children('table').fadeIn(1000); }; // Add playlist preview to container var add_playlist_preview = function(container, pl_entry) { if (pl_entry == undefined) return; container.append('
'); getPlaylistDetails(pl_entry.id, pl_entry.name, pl_entry.owner, function(playlist, preview){ display_playlist_preview($('#myPlaylists_pl_'+playlist.playlist_id), playlist, preview); }); }; // Add prev/next page navigation link var add_navigation = function(container, elem, video_id, label, pageNo, loadingElem, prevElem, nextElem) { elem.append(''+label+'').css({ "font-family": "arial", "font-size": "13px" }); $('a',elem).click(function() { render_playlists_page(container, video_id, parseInt(pageNo), loadingElem, prevElem, nextElem); }); }; // Render a page of playlists previews var render_playlists_page = function(container, video_id, pageNo, loadingElem) { // display loading indicator loadingElem.html('

Loading...

'); // get pageNo of full lists of playlists which include this video getPlaylists(video_id, pageNo, function(list, canGoPrev, canGoNext){ // panel layout container.find('.myPlaylists_loading').remove(); container.find('.myPlaylists_listing').remove(); container.append(''); var listing = $('.myPlaylists_listing'); // navigation interface $('.myPlaylists_navigation').remove(); var navStyle = 'width: 595px; height: 15px; position: relative; top: 5px;'; listing.before('
'); listing.after('
'); var prevElem = container.find('.myPlaylists_goBack'), nextElem = container.find('.myPlaylists_goForward'); if (canGoPrev) add_navigation(container, prevElem, video_id, ' previous', parseInt(pageNo) - 1, loadingElem, prevElem, nextElem); if (canGoNext) add_navigation(container, nextElem, video_id, 'next ', parseInt(pageNo) + 1, loadingElem, prevElem, nextElem); // add playlist previews in two columns of 5 videos each iter_pairwise(list, function(left, right) { var li = $('
  • '); listing.append(li); add_playlist_preview(li, left); add_playlist_preview(li, right); }); }); }; // when the video tabs are availale... waitFor('.pl_video_tabs ul.mo_tabs', function(){ // find tabs & corresponding panels var tabs = $('.pl_video_tabs ul.mo_tabs'); var panels = $('.pl_video_tabs'); // add new 'Included By' tab, and corresponding panel (myPanel) tabs.append('
  • Included By
  • '); panels.append(''); var myPanel = $('#tab_myplaylists_content'); // add title to new panel & loading message myPanel.append('

    All playlists which include this video

    '); myPanel.append('

    '); // get the video id for the current page! var video_id; $('link[rel="canonical"]').eq(0).attr('href').replace(/\/video\/([^_]+)/, function (_m, _vid) { video_id = _vid; }); // render the first page of playlist previews render_playlists_page(myPanel, video_id, 1, $('.myPlaylists_loading')); // highlight 'Add To' tab if we've already got the video in our playlists $('#tab_addto_content').remove(); $('.pl_video_tabs').append('
    '); unsafeWindow.Pl_Video_TabAddto.reloadAddto(); waitFor('#tab_addto_content form input[type="checkbox"]', function(){ $('#tab_addto_content form input[type="checkbox"]').each(function(){ var ii = $(this); if ((""+ii.prop('checked')) == "true") { $('#tab_addto > a').css({ color: 'green', 'font-weight': 'bold' }); return false; } }); $('#tab_addto_content').hide(); $('#tab_infos_content').show(); }); }); // waitfor })(jQuery);