Skip to content

Commit

Permalink
Added addon for firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
puddingspudding committed Dec 1, 2017
1 parent f9ad4b0 commit ca785a6
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 29 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [Persistent Video Volume](https://chrome.google.com/webstore/detail/persistent-video-volume/ppoliijncpdcgddmfibmgnjhegceaadj)
# Persistent Video Volume

![Logo](pvv.png)
[![Google Chrome Webstore](https://developer.chrome.com/webstore/images/ChromeWebStore_Badge_v2_206x58.png)](https://chrome.google.com/webstore/detail/persistent-video-volume/ppoliijncpdcgddmfibmgnjhegceaadj)[![Firefox Addons](https://addons.cdn.mozilla.net/static/img/addons-buttons/AMO-button_1.png)](https://addons.mozilla.org/de/firefox/addon/persistent-video-volume/)

## Use cases

Expand All @@ -9,4 +9,4 @@

# Credits

- Icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/)
- Icons made by [Smashicons](https://www.flaticon.com/authors/smashicons) from [www.flaticon.com](https://www.flaticon.com/) is licensed by [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/)
10 changes: 5 additions & 5 deletions contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
const STORAGE_KEY = "video-volume";
const STATUS_KEY = "video-volume-status-per-website";

let store = chrome.storage || window.storage;
function setVolume() {
let host = window.location.host;
let key = STATUS_KEY + '_' + host;
chrome.storage.local.get(key, function(data) {
store.local.get(key, function(data) {
if (key in data && !data[key]) {
return;
}
Expand All @@ -14,14 +15,14 @@
return;
}

chrome.storage.local.get(STORAGE_KEY, function(data) {
store.local.get(STORAGE_KEY, function(data) {
if (!data || !(STORAGE_KEY in data)) {
return;
}
for (var x = 0; x < videoTags.length; x++) {
videoTags[x].volume = data[STORAGE_KEY] / 100;
}
});
});
});
}

Expand All @@ -32,6 +33,5 @@
}

setVolume();
window.setInterval(setVolume, 1000);
window.setInterval(setVolume, 1000);
})();

Binary file added icon16.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 icon32.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 icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name" : "Persistent Video Volume",
"version" : "0.2.0",
"version" : "0.3.0",
"manifest_version" : 2,
"description" : "Sets video volume for all website to the same level",
"permissions": ["storage", "tabs", "<all_urls>"],
"icons": {
"48": "icon48.png",
"128": "icon128.png"
},
"content_scripts": [
Expand All @@ -15,7 +16,11 @@
}
],
"browser_action": {
"default_popup": "popup.html"
"default_popup": "popup.html",
"default_icon": {
"16": "icon16.png",
"32": "icon32.png"
}
}

}
}
12 changes: 5 additions & 7 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<body>
<div class="mdc-layout-grid mdc-layout-grid--align-left">
<div class="mdc-layout-grid__inner">

<div class="mdc-layout-grid__cell mdc-layout-grid__cell--align-middle mdc-layout-grid__cell--span-3-phone">
<div class="mdc-slider mdc-slider--discrete mdc-slider--discrete" tabindex="0" role="slider" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" aria-label="Select Value">
<div class="mdc-slider__track-container">
Expand Down Expand Up @@ -50,13 +50,11 @@
</div>
</div>
</div>
</div>
</div>
</div>

<script src="material-components-web.min.js"></script>

<script>window.mdc.autoInit();</script>
<script src="popup.js"></script>

</body>
</html>
</html>
26 changes: 15 additions & 11 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// init material design components
window.mdc.autoInit();

const STORAGE_KEY = "video-volume";
const STATUS_KEY = "video-volume-status-per-website";

let store = chrome.storage || window.storage;
let tbs = chrome.tabs || window.tabs;
document.addEventListener('DOMContentLoaded', function() {
const slider = new mdc.slider.MDCSlider(document.querySelector('.mdc-slider'));

Expand All @@ -10,41 +15,41 @@ document.addEventListener('DOMContentLoaded', function() {
var text = document.getElementById("volume-value-label");

var setLabel = function(volume) {
text.innerHTML = volume + '%';
text.innerHTML = escape(volume) + '%';
}

slider.listen('MDCSlider:change', () => {
var key = {};
key[STORAGE_KEY] = slider.value;
chrome.storage.local.set(key, function() {
store.local.set(key, function() {
setLabel(slider.value);
});
});
status.addEventListener('change', () => {
let enabled = status.checked;
slider.disabled = !enabled;
chrome.tabs.query({active: true}, function(tabs) {
tbs.query({active: true}, function(tabs) {
let host = parseHostFromURL(tabs[0].url);
let key = {};
key[STATUS_KEY + '_' + host] = enabled;
chrome.storage.local.set(key);
store.local.set(key);
});
});
chrome.tabs.query({active: true}, function(tabs) {

tbs.query({active: true}, function(tabs) {
let host = parseHostFromURL(tabs[0].url);
let key = STATUS_KEY + '_' + host;
chrome.storage.local.get(key, function(data) {
store.local.get(key, function(data) {
if (key in data) {
slider.disabled = !data[key];
status.checked = data[key];
} else {
status.checked = true;
}
});
});
});
chrome.storage.local.get(STORAGE_KEY, function(data) {

store.local.get(STORAGE_KEY, function(data) {
var volume = data[STORAGE_KEY];
if (!volume) {
volume = 0;
Expand All @@ -60,4 +65,3 @@ document.addEventListener('DOMContentLoaded', function() {
}

});

0 comments on commit ca785a6

Please sign in to comment.