From 4ec4a2d385dbadbee1258046ef9f37a18099f03f Mon Sep 17 00:00:00 2001 From: Apoorv Saxena Date: Fri, 6 Jun 2014 03:54:15 +0530 Subject: [PATCH 1/3] added functionality to allow user to save Video Speed in Chrome Sync Storage via Chrome Extensions's Browser Action and automated the process to apply user saved Video Speed to HTML5 videos --- browser_action.html | 33 +++++++++++++++++++++++ browser_action.js | 64 +++++++++++++++++++++++++++++++++++++++++++++ inject.js | 8 ++++++ manifest.json | 13 ++++++--- 4 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 browser_action.html create mode 100644 browser_action.js diff --git a/browser_action.html b/browser_action.html new file mode 100644 index 0000000..54aabf2 --- /dev/null +++ b/browser_action.html @@ -0,0 +1,33 @@ + + + + + + +
+
+ + 1 + +
+
+ + + \ No newline at end of file diff --git a/browser_action.js b/browser_action.js new file mode 100644 index 0000000..3efcc93 --- /dev/null +++ b/browser_action.js @@ -0,0 +1,64 @@ +(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(common_speed - 0.10); + 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 2ceceb7..cebaedf 100644 --- a/inject.js +++ b/inject.js @@ -12,6 +12,14 @@ chrome.extension.sendMessage({}, function(response) { 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; + } + }); }; tc.videoController.prototype.getSpeed = function() { diff --git a/manifest.json b/manifest.json index 6c24c51..b1b7290 100755 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "HTML5 Video Playback Speed Controller", - "version": "0.1.1", + "version": "0.1.2", "manifest_version": 2, "description": "Lean in and speed up your video learning with handy shortcuts to accelerate, slow-down, and rewind your video via your keyboard.", "homepage_url": "https://github.com/igrigorik/videospeed", @@ -9,12 +9,17 @@ "48": "icons/icon48.png", "128": "icons/icon128.png" }, - "permissions": [ "activeTab" ], + "permissions": [ "activeTab", "storage" ], "content_scripts": [{ "all_frames": true, "matches": [ "http://*/*", "https://*/*"], "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 From 5a7bb9e0a608f112800b1fdce926254ab9a9b23f Mon Sep 17 00:00:00 2001 From: Apoorv Saxena Date: Sat, 7 Jun 2014 01:41:47 +0530 Subject: [PATCH 2/3] keeping the minimum playback video speed to zero --- browser_action.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser_action.js b/browser_action.js index 3efcc93..a7979ba 100644 --- a/browser_action.js +++ b/browser_action.js @@ -27,7 +27,7 @@ } function decrease() { - set_speed(common_speed - 0.10); + set_speed(Math.max(common_speed - 0.10, 0.00)); return common_speed; } From 81d4bc879700117023294bd26c7eeea492119471 Mon Sep 17 00:00:00 2001 From: Apoorv Saxena Date: Sun, 8 Jun 2014 02:59:21 +0530 Subject: [PATCH 3/3] 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