Created
March 30, 2011 21:39
-
-
Save davidillsley/895367 to your computer and use it in GitHub Desktop.
Firefox Jetpack which shows a widget on YouTube watch pages
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
const widgets = require("widget"); | |
var ytWidgets = {} | |
function ytEventOccurred(data){ | |
if(data.event == "load"){ | |
ytWidgets[data.url] = widgets.Widget({ | |
label: "YT Button", | |
contentURL: "http://www.youtube.com/favicon.ico" | |
}); | |
}else{ | |
ytWidgets[data.url].destroy(); | |
delete ytWidgets[data.url]; | |
} | |
} | |
function ytOnAttach(worker) { | |
worker.on('message', ytEventOccurred); | |
} | |
var pageMod = require("page-mod"); | |
pageMod.PageMod({ | |
include: "http://www.youtube.com/watch*", | |
contentScriptWhen: 'ready', | |
contentScript: [ | |
"postMessage({'url':document.URL,'event':'load'});", | |
"window.addEventListener('unload',function(){postMessage({'url':document.URL,'event':'unload'});},false);" | |
], | |
onAttach: ytOnAttach | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment