Skip to content

Instantly share code, notes, and snippets.

@Pmmlabs
Last active March 12, 2016 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pmmlabs/55481d3cb8ad7d1a0101 to your computer and use it in GitHub Desktop.
Save Pmmlabs/55481d3cb8ad7d1a0101 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @id chromecast@vkopt
// @name Chromecast для VkOpt
// @version 1.0
// @namespace https://greasyfork.org/users/23
// @author Pmmlabs@github
// @description Плагин Chromecast для VkOpt
// @include *vk.com*
// @run-at document-end
// @noframes
// @grant none
// ==/UserScript==
if (!window.vkopt_plugins) vkopt_plugins = {};
(function () {
var PLUGIN_ID = 'chromecast';
vkopt_plugins[PLUGIN_ID] = {
onError: function () {
topMsg('<b>Chromcast error</b>', 2, '#FFB4A3');
},
cast: function (url) {
chrome.cast.requestSession(function (session) {
var mediaInfo = new chrome.cast.media.MediaInfo(url);
mediaInfo.contentType = 'video/mp4';
// mediaInfo.contentType = 'audio/mpeg';
// mediaInfo.contentType = 'image/jpeg';
var request = new chrome.cast.media.LoadRequest(mediaInfo);
request.autoplay = true;
session.loadMedia(request, function () {
}, vkopt_plugins[PLUGIN_ID].onError);
}, vkopt_plugins[PLUGIN_ID].onError);
},
init: function() {
AjCrossAttachJS('https://www.gstatic.com/cv/js/sender/v1/cast_sender.js', 'chromecast');
},
vidActLinks: function (video_data, links_array) {
var best_url = links_array[links_array.length-1];
window['__onGCastApiAvailable'] = function (loaded, errorInfo) {
if (loaded) {
var applicationID = chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID;
var sessionRequest = new chrome.cast.SessionRequest(applicationID);
var apiConfig = new chrome.cast.ApiConfig(sessionRequest, function () {
}, function () {
});
chrome.cast.initialize(apiConfig,
function (message) {
//document.getElementById('castButton').disabled = false;
}, vkopt_plugins[PLUGIN_ID].onError);
}
};
return '<a onclick="vkopt_plugins[\''+PLUGIN_ID+'\'].cast(\''+best_url+'\')">Chromecast</a>';
}
};
if (window.vkopt_ready) vkopt_plugin_run(PLUGIN_ID);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment