mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-22 02:18:45 -04:00
updated functionality to save video speed via existing control panel video
This commit is contained in:
@@ -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>
|
|
@@ -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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
})();
|
|
21
inject.js
21
inject.js
@@ -8,18 +8,17 @@ chrome.extension.sendMessage({}, function(response) {
|
|||||||
this.video = target;
|
this.video = target;
|
||||||
this.initializeControls();
|
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) {
|
chrome.storage.sync.get('speed', function(storage) {
|
||||||
target.playbackRate = storage.speed;
|
var speed = storage.speed ? storage.speed : '1.00';
|
||||||
});
|
target.playbackRate = speed;
|
||||||
chrome.storage.onChanged.addListener(function(storage) {
|
this.speedIndicator.textContent = speed;
|
||||||
if(storage.speed) {
|
}.bind(this));
|
||||||
target.playbackRate = storage.speed.newValue;
|
|
||||||
}
|
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() {
|
tc.videoController.prototype.getSpeed = function() {
|
||||||
|
@@ -16,10 +16,5 @@
|
|||||||
"css": [ "inject.css" ],
|
"css": [ "inject.css" ],
|
||||||
"js": [ "inject.js" ]
|
"js": [ "inject.js" ]
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"browser_action": {
|
|
||||||
"default_icon": "icons/icon16.png",
|
|
||||||
"default_title": "Video Playback Speed Controller",
|
|
||||||
"default_popup": "browser_action.html"
|
|
||||||
}
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user