Skip to content

fixing it such that it only sets the playback speed when focus is rem…#6

Open
maximilianmordig wants to merge 1 commit intointOrfloat:masterfrom
maximilianmordig:master
Open

fixing it such that it only sets the playback speed when focus is rem…#6
maximilianmordig wants to merge 1 commit intointOrfloat:masterfrom
maximilianmordig:master

Conversation

@maximilianmordig
Copy link

…oved or enter is hit

addSpeedInput();

function ensureSpeedNotChanged() {
/* sometimes playbackRate is set back to 1.0 by spotify's code so timeout just ensures it goes the speed the user desires */
Copy link

@faf0 faf0 Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* sometimes playbackRate is set back to 1.0 by spotify's code so timeout just ensures it goes the speed the user desires */
/* sometimes Spotify's code resets playbackRate to 1.0, so ensure that the speed matches the user's setting after every timeout */

try {
document.getElementsByClassName('now-playing-bar__right')[0].appendChild (input); /* make our input exist on page */
debugLog("Added speed input");
}catch{
Copy link

@faf0 faf0 Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}catch{
} catch {

function addSpeedInput() { /* adds speed input next to playing bar */
debugLog("Adding speed input");
try {
document.getElementsByClassName('now-playing-bar__right')[0].appendChild (input); /* make our input exist on page */
Copy link

@faf0 faf0 Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
document.getElementsByClassName('now-playing-bar__right')[0].appendChild (input); /* make our input exist on page */
document.getElementsByClassName('volume-bar')[0].appendChild(input); /* add input to page */

fixes #7

input.oninput = function(e){ /* What happens when we change the number in our input box element */
validateAndChangeSpeed(); /* We call our function */
input.onkeypress = function(e){ /* What happens when we change the number in our input box element */
if(e.code == "Enter") {
Copy link

@faf0 faf0 Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(e.code == "Enter") {
if (e.code === "Enter") {

if(!isNaN(val)){ /* check if val is a number */
changeSpeed(val);
var val = parseFloat( value || (input.value / 100));
if(!isNaN(val) && (val != lastSpeed)){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!isNaN(val) && (val != lastSpeed)){
if (!isNaN(val) && (val !== lastSpeed)) {

lastSpeed = val;
setStoredSpeed(val);
/* val is clamped to range 0.0625 - 16.0 https://stackoverflow.com/a/32320020 */
if (VideoElementsMade[i].playbackRate != val) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (VideoElementsMade[i].playbackRate != val) {
if (VideoElementsMade[i].playbackRate !== val) {

Copy link

@faf0 faf0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! lgtm

// locally cache the speed, so getStoredSpeed does not need to be called repetitively
var lastSpeed = getStoredSpeed() || 1.0; /* if stored speed is null make lastSpeed 1.0 */

function setStoredSpeed(value){ /* Sets variable in the site's cookie along-side spotify's stuff */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function setStoredSpeed(value){ /* Sets variable in the site's cookie along-side spotify's stuff */
function setStoredSpeed(value){ /* Stores speed in the site's localStorage alongside Spotify's stuff */

@TrickyPatrick
Copy link

@faf0 hey sorry for this but the extension is broken and I'm not sure OP is still around ... I saw you edited it and I was wondering if you could sort of fix it. My twitter: @LaBonnePrune to talk in a better way

@faf0
Copy link

faf0 commented Mar 20, 2021

@TrickyPatrick , taking the conversation to #7

faf0 added a commit to faf0/spotitySpeedExtension that referenced this pull request Mar 20, 2021
Fixes intOrfloat#7

Cleans up code and only only sets playback speed on certain events:
intOrfloat#6
@faf0
Copy link

faf0 commented Mar 20, 2021

@maximilianmordig , based on your PR, I created another PR with the changes I suggested and a fix for Spotify's recent DOM change: #8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants