-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixing it such that it only sets the playback speed when focus is rem… #6
base: master
Are you sure you want to change the base?
Conversation
…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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* 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{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (VideoElementsMade[i].playbackRate != val) { | |
if (VideoElementsMade[i].playbackRate !== val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you! lgtm
@@ -33,10 +37,13 @@ var code = ` | |||
function getStoredSpeed(){ /* Gets stored speed between refreshes*/ | |||
return localStorage.getItem('speed'); | |||
} | |||
|
|||
// 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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 */ |
@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 |
@TrickyPatrick , taking the conversation to #7 |
Fixes intOrfloat#7 Cleans up code and only only sets playback speed on certain events: intOrfloat#6
@maximilianmordig , based on your PR, I created another PR with the changes I suggested and a fix for Spotify's recent DOM change: #8 |
…oved or enter is hit