Skip to content

Commit

Permalink
Merge branch 'release-0.10.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
puddingspudding committed Oct 3, 2020
2 parents e3c5012 + 1ba2214 commit 80aa47f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
31 changes: 24 additions & 7 deletions contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
const STATUS_KEY = "video-volume-status-per-website";

let store = chrome.storage || window.storage;
let runtime = chrome.runtime || window.runtime;

runtime.onMessage.addListener(function(volume) {
let host = window.location.host;
data = {};
data[STORAGE_KEY + '_' + host] = Math.round(volume);
saveVolumne(data);
});

lock = false;
function setVolume() {
let host = window.location.host;
let key = STATUS_KEY + '_' + host;
let websiteKey = STORAGE_KEY + '_' + host;

store.local.get([key, MAX_VOL_STORAGE_KEY, websiteKey, STORAGE_KEY], function(data) {

var videoTags = Array.from(document.getElementsByTagName("video"));
Expand Down Expand Up @@ -59,12 +68,13 @@
return;
}
videoTags[i].onvolumechange = function (argument) {
if (argument.target.muted || argument.target.paused) {
return;
}
lock = true;
var key = {};
key[STORAGE_KEY + '_' + host] = Math.round(argument.target.volume * 100)
store.local.set(key, function() {
lock = false;
});
saveVolumne(key);
}
}
for (var i in audioTags) {
Expand All @@ -75,18 +85,25 @@
return;
}
audioTags[i].onvolumechange = function (argument) {
if (argument.target.muted || argument.target.paused) {
return;
}
lock = true;
var key = {};
key[STORAGE_KEY + '_' + host] = Math.round(argument.target.volume * 100)
store.local.set(key, function() {
lock = false;
});
key[STORAGE_KEY + '_' + host] = Math.round(argument.target.volume * 100);
saveVolumne(key);
}
}

});
}

function saveVolumne(data) {
store.local.set(data, function() {
lock = false;
});
}

function parseHostFromURL(url) {
var parser = document.createElement('a');
parser.href = url;
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" : "Persistent Video/Audio Volume",
"version" : "0.10.0",
"version" : "0.10.1",
"manifest_version" : 2,
"description" : "Saves video and audio volume",
"permissions": ["storage", "tabs", "<all_urls>"],
Expand Down
9 changes: 8 additions & 1 deletion popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const STATUS_KEY = "video-volume-status-per-website";

let store = chrome.storage || window.storage;
let tbs = chrome.tabs || window.tabs;
let runtime = chrome.runtime || window.runtime;


document.addEventListener('DOMContentLoaded', function() {

Expand All @@ -29,7 +31,11 @@ document.addEventListener('DOMContentLoaded', function() {
maxGlobalText.textContent = volume + '%';
}

var currentTab;


tbs.query({active: true, currentWindow: true}, function(tabs) {
currentTab = tabs[0];
host = parseHostFromURL(tabs[0].url);
let key = STATUS_KEY + '_' + host;
store.local.get(key, function(data) {
Expand All @@ -45,7 +51,7 @@ document.addEventListener('DOMContentLoaded', function() {

store.local.get(STORAGE_KEY + '_' + host, function(data) {
var volume = data[STORAGE_KEY + '_' + host];
if (!volume) {
if (isNaN(volume)) {
volume = 50;
}
websiteSlider.value = volume;
Expand Down Expand Up @@ -76,6 +82,7 @@ document.addEventListener('DOMContentLoaded', function() {
store.local.set(key, function() {
setWebsiteLabel(websiteSlider.value);
});
tbs.sendMessage(currentTab.id, websiteSlider.value);
});

status.addEventListener('change', () => {
Expand Down

0 comments on commit 80aa47f

Please sign in to comment.