From 81d4bc879700117023294bd26c7eeea492119471 Mon Sep 17 00:00:00 2001 From: Apoorv Saxena Date: Sun, 8 Jun 2014 02:59:21 +0530 Subject: [PATCH] updated functionality to save video speed via existing control panel video --- browser_action.html | 33 ----------------------- browser_action.js | 64 --------------------------------------------- inject.js | 21 +++++++-------- manifest.json | 7 +---- 4 files changed, 11 insertions(+), 114 deletions(-) delete mode 100644 browser_action.html delete mode 100644 browser_action.js diff --git a/browser_action.html b/browser_action.html deleted file mode 100644 index 54aabf2..0000000 --- a/browser_action.html +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - -
-
- - 1 - -
-
- - - \ No newline at end of file diff --git a/browser_action.js b/browser_action.js deleted file mode 100644 index a7979ba..0000000 --- a/browser_action.js +++ /dev/null @@ -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); - }); - }); - -})(); \ No newline at end of file diff --git a/inject.js b/inject.js index cebaedf..255d811 100644 --- a/inject.js +++ b/inject.js @@ -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() { diff --git a/manifest.json b/manifest.json index b1b7290..825f091 100755 --- a/manifest.json +++ b/manifest.json @@ -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" - } + ] } \ No newline at end of file