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