Created
September 1, 2013 18:43
-
-
Save francois2metz/6406387 to your computer and use it in GitHub Desktop.
Patch for send-to-xbmc firefox addon; https://addons.mozilla.org/en-US/firefox/addon/send-to-xbmc/?src=search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- main.js 2013-09-01 20:41:15.706575531 +0200 | |
+++ main.js 2013-09-01 20:40:42.162575694 +0200 | |
@@ -12,19 +12,44 @@ | |
var data = require("sdk/self").data; | |
var pageMod = require("sdk/page-mod"); | |
var panel; | |
+ | |
+var mediasSupported = ['mp3', 'mp4', 'mkv', 'pls', 'avi', 'webm', 'flv', 'wmv', 'asf', 'flac', 'mka', 'm4a', 'aac', 'ogg']; | |
+ | |
exports.main = function() { | |
var cm = require("sdk/context-menu"); | |
+ | |
+ // context menu to send stuff to xbmc from links | |
+ var context = ['a[href*="youtu"]', 'a[href^="/watch"]']; | |
+ mediasSupported.forEach(function(ext) { | |
+ context.push('a[href*=".'+ ext +'"]'); | |
+ }); | |
+ | |
cm.Item({ | |
label: "Send to XBMC", | |
- context: cm.SelectorContext('a[href*="youtu"],a[href^="/watch"],a[href*=".mp4"],a[href*=".mkv"],a[href*=".mp3"],a[href*=".pls"]'), | |
+ context: cm.SelectorContext(context.join(',')), | |
image: data.url('xbmc_logo.ico'), | |
contentScript: 'self.on("click", function (node, data) {' + | |
' self.postMessage({url:node.href,pathname:node.pathname});' + | |
'});', | |
onMessage: function(data) { | |
- parseUrl(data.url,data.pathname); | |
+ parseUrl(data.url, data.pathname); | |
+ } | |
+ }); | |
+ | |
+ // context menu to send to xbmc from a video or audio element | |
+ cm.Item({ | |
+ label: "Send to XBMC", | |
+ context: cm.SelectorContext('video,audio'), | |
+ image: data.url('xbmc_logo.ico'), | |
+ contentScript: 'self.on("click", function (node, data) {' + | |
+ ' self.postMessage({url:node.src,pathname:node.src});' + | |
+ '});', | |
+ onMessage: function(data) { | |
+ parseUrl(data.url, data.pathname); | |
} | |
- }); | |
+ }); | |
+ | |
+ // add youtube script on youtube | |
pageMod.PageMod({ | |
include: "*.youtube.com", | |
contentScriptFile: data.url("youtube.js"), | |
@@ -57,6 +82,7 @@ | |
}).show(); | |
} | |
} | |
+ | |
function parseUrl(url,pathname){ | |
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/; | |
var match = url.match(regExp); | |
@@ -72,16 +98,18 @@ | |
} | |
var ext = pathname.split('.').pop(); | |
//Supported extensions | |
- if(['mp3','mp4','mkv','pls','avi'].indexOf(ext) >= 0){ | |
+ if(mediasSupported.indexOf(ext) >= 0) { | |
sendToXBMC(url); | |
return; | |
} | |
displayMessage('Error','The following url is not supported: '+url,'error'); | |
} | |
+ | |
function sendYouTube(ytid){ | |
var url = 'plugin://plugin.video.youtube/?action=play_video&videoid='+ytid; | |
sendToXBMC(url); | |
} | |
+ | |
function sendToXBMC(fileurl){ | |
if(!prefs.xbmcip || prefs.xbmcip == ''){ | |
displayMessage('Error','You have to set up your XBMC address first in the Addon Settings','error'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment