I am trying to write Google extension. The problem is i want to mute/turn off sound in tab/all tabs when script find phrase.
Eg.: You click on random video on Youtube. When in descibtion is "License granted to YouTube", then mute this tab.
Also it doesnt work when visit a page for a first time i have to reload it. :( 4th day of learning programming.
//smh which turn off sound of all tabs - sometimes work
function turn_Off_Sound() {
chrome.tabs.query({url: []}, function (tabs) {
for (var i = 0; i < tabs.length; i++) {
var mutedInfo = tabs[i].mutedInfo;
if (mutedInfo) chrome.tabs.update(tabs[i].id, {"muted": true});
}
});
};
//trying to find a phrase
var xpathResult = document.evaluate("(//text()[contains(., 'License granted to YouTube')][1])", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
var node = xpathResult.singleNodeValue;
//not found
if (node == null){
alert("Not found.");
}else {
//found
alert("I find it, give me a hug!");
turn_Off_Sound(); //trying to mute tabs
};
{
"manifest_version": 2,
"name": "Mute tabs when find a phrase",
"version": "0.0.1",
"content_scripts": [ {
"js": [ "script.js" ],
"matches": [ "*://*/*"],
"run_at": "document_end"
} ],
"permissions": [
"contextMenus",
"tabs",
"activeTab",
"storage",
"http://www.google.com/",
"https://ajax.googleapis.com/"],
}
}
<html>
<head></head>
<body>
<h1>We're running a Chrome extension!</h1>
<h1>License granted to YouTube</h1>
</body>
</html>