Skip to content

Commit

Permalink
Auto refresh the page on toggling the extension if the current tab is…
Browse files Browse the repository at this point in the history
… 'youtube'

Signed-off-by: Agix <anik.edu@gmail.com>
  • Loading branch information
animeshk committed Sep 17, 2017
1 parent 6c6df31 commit ba852a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions js/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ function removeURLParameters(url, parameters) {

var tabIds = new map();

function reloadTab() {
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var pattern = /\.youtube\./;
var url = tabs[0].url;

if (pattern.test(url))
chrome.tabs.reload();
});
}

function sendMessage(tabId) {
if (tabIds.contains(tabId)) {
chrome.tabs.sendMessage(tabId, {url: tabIds.value(tabId)});
Expand All @@ -95,8 +105,8 @@ function processRequest(details) {
function enableExtension() {
chrome.browserAction.setIcon({
path : {
128 : "img/icon128.png"
38 : "img/icon38.png",
128 : "img/icon128.png",
38 : "img/icon38.png"
}
});
chrome.tabs.onUpdated.addListener(sendMessage);
Expand All @@ -116,7 +126,6 @@ function disableExtension() {
chrome.tabs.onUpdated.removeListener(sendMessage);
chrome.webRequest.onBeforeRequest.removeListener(processRequest);
tabIds.clear();

}

function saveSettings(disabled) {
Expand All @@ -135,6 +144,7 @@ chrome.browserAction.onClicked.addListener(function() {

disabled = !disabled;
saveSettings(disabled);
reloadTab();
});
});

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Youtube Audio",
"version": "0.0.2",
"version": "0.0.2.2",
"manifest_version": 2,
"description": "Stream only Audio on Youtube",
"offline_enabled": true,
Expand Down

0 comments on commit ba852a9

Please sign in to comment.