Browser extension to watch YouTube videos without the distracting cruft around it, in the full window.
Browse Source

Ignore pages inside frames, refactor.

tags/v1.1.1
Gerben 7 years ago
parent
commit
05f1e8b154
1 changed files with 12 additions and 8 deletions
  1. +12
    -8
      background.js

+ 12
- 8
background.js View File

@@ -50,21 +50,26 @@ browser.webRequest.onBeforeRequest.addListener(


// Show the pageAction button if looking at a video (either with or without cruft).
browser.webNavigation.onCommitted.addListener(function (details) {maybeShowPageAction(details.tabId, details.url);});
browser.webNavigation.onHistoryStateUpdated.addListener(function (details) {maybeShowPageAction(details.tabId, details.url);});
browser.webNavigation.onCommitted.addListener(handleNavigation);
browser.webNavigation.onHistoryStateUpdated.addListener(handleNavigation);

function maybeShowPageAction(tabId, url) {
var matchEmbeddable = url.match(embeddableUrlPattern);
var matchCruft = url.match(cruftedUrlPattern);
function handleNavigation(details) {
// Ignore pages inside frames.
if (details.frameId !== 0)
return;

// Check if the page is a youtube video (either with or without cruft)
var matchEmbeddable = details.url.match(embeddableUrlPattern);
var matchCruft = details.url.match(cruftedUrlPattern);
if (matchEmbeddable || matchCruft) {
browser.pageAction.show(tabId);
// Show the pageAction button.
browser.pageAction.show(details.tabId);
// In Chrome|ium, listeners stay across page changes, in Firefox they don't. So check first.
if (!browser.pageAction.onClicked.hasListener(handlePageAction))
browser.pageAction.onClicked.addListener(handlePageAction);
}
}


// Enable/Disable cinema mode when the pageAction button is clicked.
function handlePageAction(tab) {
var matchEmbeddable = tab.url.match(embeddableUrlPattern);
@@ -78,4 +83,3 @@ function handlePageAction(tab) {
if (newUrl)
browser.tabs.update(tab.id, {url: newUrl});
}


Loading…
Cancel
Save