updated functionality to save video speed via existing control panel video

This commit is contained in:
Apoorv Saxena
2014-06-08 02:59:21 +05:30
parent 5a7bb9e0a6
commit 81d4bc8797
4 changed files with 11 additions and 114 deletions

View File

@@ -1,33 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
#mainPopup {
padding: 5px;
height: 20px;
width: 120px;
font-family: Helvetica, Ubuntu, Arial, sans-serif;
}
.tc-controls button {
color: black !important;
background: white !important;
font-weight: bold !important;
margin: 0 2px !important;
border-radius: 5px !important;
padding: 3px 8px !important;
font-size: 15px !important;
line-height: 15px !important;
}
</style>
</head>
<body>
<div id="mainPopup">
<div class="tc-controls">
<button data-control="decrease" id="decrease-video-speed">-</button>
<span id="current-video-speed">1</span>
<button data-control="increase" id="increase-video-speed">+</button>
</div>
</div>
<script type="text/javascript" src="browser_action.js"></script>
</body>
</html>

View File

@@ -1,64 +0,0 @@
(function () {
var video_speed = (function () {
var common_speed;
function set_speed(speed) {
speed = parseFloat(Math.round(speed * 100) / 100);
chrome.storage.sync.set({'speed': speed});
common_speed = speed;
}
function initialize(callback) {
chrome.storage.sync.get('speed', function (storage) {
if (storage.speed) {
common_speed = storage.speed;
} else {
set_speed(1.00);
}
callback(common_speed);
});
}
function increase() {
set_speed(common_speed + 0.10);
return common_speed;
}
function decrease() {
set_speed(Math.max(common_speed - 0.10, 0.00));
return common_speed;
}
return {
initialize: initialize,
increase: increase,
decrease: decrease
};
})();
var current_speed = document.getElementById('current-video-speed'),
speed_controls = document.getElementsByTagName('button');
speed_controls.forEach = Array.prototype.forEach;
video_speed.initialize(function (speed) {
current_speed.innerHTML = speed.toFixed(2);
});
speed_controls.forEach(function (speed_control) {
speed_control.addEventListener('click', function (event) {
var speed, control = event.target.attributes['data-control'].value;
if (control === 'increase') {
speed = video_speed.increase();
} else {
speed = video_speed.decrease();
}
current_speed.innerHTML = speed.toFixed(2);
});
});
})();

View File

@@ -8,18 +8,17 @@ chrome.extension.sendMessage({}, function(response) {
this.video = target;
this.initializeControls();
this.speedIndicator.textContent = this.getSpeed();
this.video.addEventListener('ratechange', function(event) {
this.speedIndicator.textContent = this.getSpeed();
}.bind(this));
chrome.storage.sync.get('speed', function(storage) {
target.playbackRate = storage.speed;
});
chrome.storage.onChanged.addListener(function(storage) {
if(storage.speed) {
target.playbackRate = storage.speed.newValue;
}
});
var speed = storage.speed ? storage.speed : '1.00';
target.playbackRate = speed;
this.speedIndicator.textContent = speed;
}.bind(this));
this.video.addEventListener('ratechange', function(event) {
var speed = this.getSpeed();
this.speedIndicator.textContent = speed;
chrome.storage.sync.set({'speed': speed});
}.bind(this));
};
tc.videoController.prototype.getSpeed = function() {

View File

@@ -16,10 +16,5 @@
"css": [ "inject.css" ],
"js": [ "inject.js" ]
}
],
"browser_action": {
"default_icon": "icons/icon16.png",
"default_title": "Video Playback Speed Controller",
"default_popup": "browser_action.html"
}
]
}