NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Lynda.com video plugin // @namespace http://tampermonkey.net/ // @version 0.4 // @description video large captions resized, download video link, captions contorls // @author @_wad1m // @match *://www.lynda.com/* // @grant none // @require http://code.jquery.com/jquery-latest.js // ==/UserScript== // 0.1 - Increase text video captions size and make more readable // 0.2 - Fix fullscreen layout bug // 0.3 - Fetch video link and add download button // 0.4 - Add captions controls ( change size , toogle visability ) var $PLUGIN_VERSION = "Lynda.com video plugin V 0.4"; // default variables var _lynd_default_variables = { _lynd_captions_size : 1.5, _lynd_captions_visible : true }; // Local storage function _lynd_local_storage_init() { if (typeof(Storage) !== "undefined") { // Apply default values to local storage for( var key in _lynd_default_variables ) { if( localStorage.getItem( key ) === null ) localStorage.setItem( key, _lynd_default_variables[ key ] ); } } } function _lynd_local_storage( variable, value ) { // GET if (typeof value === 'undefined') { if (typeof(Storage) !== "undefined") return localStorage.getItem( variable ); else return _lynd_default_variables[ variable ]; } // SET else { if (typeof(Storage) !== "undefined") localStorage.setItem( variable, value ); else _lynd_default_variables[ variable ] = value; } } // scan for captions added to page function _lynd_styleVideo() { // read style variables var cap_size = parseFloat( _lynd_local_storage('_lynd_captions_size' ) ); var sv_cap_size = Math.round( cap_size * 100 ) + "%"; var sv_cap_height = ( cap_size * 50 ) + "px"; var sv_cap_visibile = _lynd_local_storage('_lynd_captions_visible' ) == 'false' ? 'hidden' : 'visible'; // apply style $('span.mejs-captions-text') .css("color", "rgb(255, 255, 255)") .css("line-height", sv_cap_height ) .css("padding", "10px") .css("background-color", "rgb(0, 0, 0)") .css("font-size", sv_cap_size ) .css("box-shadow", "0 0 0 5px black") .css("visibility", sv_cap_visibile ); // fix fullscreen layout bug $('video.player').css('margin-top', '0'); // call the function each second setTimeout( _lynd_styleVideo, 1000 ); } var _lynd_pluginContainer; function _lynd_createPluginContainer() { _lynd_pluginContainer = $('<div class="_lynd_pluginContainer">'); $('div#sidebar-container').parent().parent().prepend( _lynd_pluginContainer ); $("._lynd_pluginContainer").attr('style', "margin: 10px 0;padding: 10px;background: white;border-radius: 7px;box-shadow: 0 0 5px 1px rgba(0,0,0,.07);"); var style = 'margin-bottom:15px;padding-bottom:8px;border-bottom:1px solid #E0E0E0'; _lynd_pluginContainer.prepend( $('<div style="' + style + '">' + $PLUGIN_VERSION + '</div>') ); } var _lynd_downloadButton; function _lynd_createDownloadButton() { _lynd_downloadButton = $('<a>'); _lynd_pluginContainer.append( _lynd_downloadButton ); } function _lynd_updateDownloadButton(){ var link = $('video.player').attr('src'); if( link === undefined ) { _lynd_downloadButton.text("Press play to capture video link..."); _lynd_downloadButton.attr("href", ""); } else { _lynd_downloadButton.text(" > DOWNLOAD LINK < "); _lynd_downloadButton.attr("href", link ); } // call this function each 5 second setTimeout( _lynd_updateDownloadButton, 5000 ); } var _lynd_captionsControls; var _lynd_captions_size_label; var _lynd_captions_display_toogle; function _lynd_createCaptionsControls() { // make container _lynd_captionsControls = $('<div class="_lynd_captionsControls">'); _lynd_pluginContainer.append( _lynd_captionsControls ); // captions size function function change_capt_size( value ) { var val = parseFloat( value ); // limit caption size value between 25 % and 250 % val = val < 0.25 ? 0.25 : ( val > 2.50 ? 2.50 : val ); // save value to local storage _lynd_local_storage('_lynd_captions_size', val ); // display caption size on page _lynd_captions_size_label.text( Math.round( val * 100 ) + "%" ); } // info label _lynd_captionsControls.append( $('<br/><a> Change captions size</a>') ); // button to make captions smaller var button = $('<button style="padding:10px; margin: 5px">[ - ]</button>'); _lynd_captionsControls.append( button ); button.on( 'click', function() { var value = parseFloat( _lynd_local_storage('_lynd_captions_size' ) ) - 0.25; change_capt_size( value ); }); // label to display captions size var _lynd_captions_size_label = $("<a class='_lynd_captions_size_label'></a>"); _lynd_captionsControls.append( _lynd_captions_size_label ); // display caption size default value / saved value from local storage change_capt_size( _lynd_local_storage('_lynd_captions_size' ) ); // button to make captions larger button = $('<button style="padding:10px; margin: 5px">[ + ]</button>'); _lynd_captionsControls.append( button ); button.on( 'click', function() { var value = parseFloat( _lynd_local_storage('_lynd_captions_size' ) ) + 0.25; change_capt_size( value ); }); // caption cisibility function function change_capt_visability( value ) { _lynd_local_storage('_lynd_captions_visible', value ); } // read checkbox default status var status = _lynd_local_storage('_lynd_captions_visible') == 'true' ? ' checked ' : ''; // make checkbox _lynd_captions_display_toogle = $('<p><input class="_lynd_captions_display_toogle" type="checkbox" '+status+'>. Captions are visible</p>'); _lynd_captionsControls.append( _lynd_captions_display_toogle ); _lynd_captionsControls.on('click', function() { change_capt_visability( $('._lynd_captions_display_toogle').prop("checked") === true ? 'true' : 'false' ); }); } (function() { 'use strict'; _lynd_styleVideo(); _lynd_local_storage_init(); _lynd_createPluginContainer(); _lynd_createDownloadButton(); _lynd_updateDownloadButton(); _lynd_createCaptionsControls(); })();