Skip to content

Commit

Permalink
initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebe11 committed May 19, 2023
1 parent 4c7caca commit 954a32e
Show file tree
Hide file tree
Showing 9 changed files with 5,256 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/web-ext-artifacts
/.phpunit.cache
/node_modules
npm-debug.log
yarn-error.log
/.idea
/.vscode
.DS_Store
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Video Ad Monitor

Firefox browser extension
73 changes: 73 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"use strict";

let currentState = false;

/**
* @param {boolean} state
* @return {Promise}
*/
function setTabState(state) {
return browser.tabs.query({
url: 'https://www.youtube.com/watch?v=*'
})
.then((tabs) => {
tabs.forEach((t) => {
browser.tabs.sendMessage(t.id, {
tabID: t.id,
active: t.active,
state
})
.catch((err) => {
throw err;
});
});

return true;
})
.catch((err) => {
console.error(err);

return false;
});
}

async function buttonClick() {
currentState = !currentState;

let result = await setTabState(currentState);

if (result === false) { return; }

const icon = (currentState === true) ? 'on.png' : 'off.png';

result = browser.browserAction.setIcon({
path: {
48: icon
}
})
.then(() => {
browser.browserAction.setTitle({
title: currentState ? 'on' : 'off'
});
})
.catch((err) => {
console.error(err);
});
}

browser.browserAction.onClicked.addListener(buttonClick);

browser.tabs.onUpdated.addListener((tabID, changeInfo, tab) => {
if (currentState === true && changeInfo.status === 'complete') {
setTimeout(() => {
setTabState(true);
}, 500);
}
}, {
urls: ['*://www.youtube.com/watch?v=*'],
properties: ['status', 'url']
});

browser.runtime.onMessage.addListener((observer) => {
console.log(observer);
});
27 changes: 27 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"manifest_version": 2,
"name": "Video Ad Monitor",
"version": "2.0",
"description": "Mutes the sound during non-skippable ads, closes banners, and clicks the skip now button when present.",
"icons": {
"48": "off.png",
"48": "on.png"
},
"browser_action": {
"default_icon": "off.png",
"default_title": "off"
},
"permissions": [
"tabs"
],
"incognito": "spanning",
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["*://www.youtube.com/*"],
"js": ["video.js"]
}
]
}
Binary file added off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 954a32e

Please sign in to comment.