mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-08-22 02:18:45 -04:00
Add ability to drag controller
This commit is contained in:
@@ -50,3 +50,7 @@
|
|||||||
div.video-wrapper + div.target {
|
div.video-wrapper + div.target {
|
||||||
height: 0;
|
height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.vcs-dragging {
|
||||||
|
cursor: -webkit-grabbing;
|
||||||
|
}
|
||||||
|
45
inject.js
45
inject.js
@@ -98,14 +98,21 @@ chrome.extension.sendMessage({}, function(response) {
|
|||||||
<button data-action="faster">+</button>
|
<button data-action="faster">+</button>
|
||||||
<button data-action="advance" class="rw">»</button>
|
<button data-action="advance" class="rw">»</button>
|
||||||
<button data-action="close" class="hideButton">x</button>
|
<button data-action="close" class="hideButton">x</button>
|
||||||
|
<button data-action="drag" class="dragButton"><></button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
shadow.innerHTML = shadowTemplate;
|
shadow.innerHTML = shadowTemplate;
|
||||||
forEach.call(shadow.querySelectorAll('button'), function(button) {
|
forEach.call(shadow.querySelectorAll('button'), function(button) {
|
||||||
|
if (button.dataset['action'] === 'drag') {
|
||||||
|
button.addEventListener('mousedown', (e) => {
|
||||||
|
runAction(e.target.dataset['action'], document);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
button.onclick = (e) => {
|
button.onclick = (e) => {
|
||||||
runAction(e.target.dataset['action'], document);
|
runAction(e.target.dataset['action'], document);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.speedIndicator = shadow.querySelector('span');
|
this.speedIndicator = shadow.querySelector('span');
|
||||||
@@ -234,11 +241,49 @@ chrome.extension.sendMessage({}, function(response) {
|
|||||||
} else if (action === 'close') {
|
} else if (action === 'close') {
|
||||||
v.classList.add('vsc-cancelled');
|
v.classList.add('vsc-cancelled');
|
||||||
controller.remove();
|
controller.remove();
|
||||||
|
} else if (action === 'drag') {
|
||||||
|
handleDrag(v, controller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleDrag(video, controller) {
|
||||||
|
const parentElement = controller.parentElement,
|
||||||
|
boundingRect = parentElement.getBoundingClientRect(),
|
||||||
|
shadowController = controller.shadowRoot.querySelector('#controller'),
|
||||||
|
dragButton = shadowController.querySelector('.dragButton'),
|
||||||
|
|
||||||
|
maxWidth = video.offsetWidth - shadowController.offsetWidth - 100,
|
||||||
|
maxHeight = video.offsetHeight - shadowController.offsetHeight - 100,
|
||||||
|
|
||||||
|
offsetLeft = boundingRect.left + dragButton.offsetLeft + dragButton.offsetWidth,
|
||||||
|
offsetTop = boundingRect.top + dragButton.offsetTop + dragButton.offsetHeight;
|
||||||
|
|
||||||
|
video.classList.add('vcs-dragging');
|
||||||
|
shadowController.classList.add('dragging');
|
||||||
|
|
||||||
|
const startDragging = (e) => {
|
||||||
|
let newLeft = Math.min(maxWidth, Math.max(0, e.clientX - offsetLeft));
|
||||||
|
let newTop = Math.min(maxHeight, Math.max(0, e.clientY - offsetTop));
|
||||||
|
|
||||||
|
shadowController.style.left = newLeft + 'px';
|
||||||
|
shadowController.style.top = newTop + 'px';
|
||||||
|
}
|
||||||
|
const stopDragging = () => {
|
||||||
|
parentElement.removeEventListener('mousemove', startDragging);
|
||||||
|
parentElement.removeEventListener('mouseup', stopDragging);
|
||||||
|
parentElement.removeEventListener('mouseleave', stopDragging);
|
||||||
|
|
||||||
|
shadowController.classList.remove('dragging');
|
||||||
|
video.classList.remove('vcs-dragging');
|
||||||
|
}
|
||||||
|
|
||||||
|
parentElement.addEventListener('mouseup',stopDragging);
|
||||||
|
parentElement.addEventListener('mouseleave',stopDragging);
|
||||||
|
parentElement.addEventListener('mousemove', startDragging);
|
||||||
|
}
|
||||||
|
|
||||||
var timer;
|
var timer;
|
||||||
var animation = false;
|
var animation = false;
|
||||||
function showController(controller) {
|
function showController(controller) {
|
||||||
|
17
shadow.css
17
shadow.css
@@ -34,6 +34,15 @@
|
|||||||
margin-left: 1em;
|
margin-left: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#controller.dragging {
|
||||||
|
opacity: 0.7;
|
||||||
|
cursor: -webkit-grabbing;
|
||||||
|
}
|
||||||
|
|
||||||
|
#controller.dragging #controls {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: black;
|
color: black;
|
||||||
@@ -67,3 +76,11 @@ button.hideButton {
|
|||||||
margin: 0 2px 0 15px;
|
margin: 0 2px 0 15px;
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button.dragButton {
|
||||||
|
cursor: -webkit-grab;
|
||||||
|
}
|
||||||
|
|
||||||
|
button.dragButton:active {
|
||||||
|
cursor: -webkit-grabbing;
|
||||||
|
}
|
Reference in New Issue
Block a user