The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Tunify

TODO: Pull subtitle into page object

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Tunify


-- html

<div id="workspace"></div>



-- script

const generateRandomString = (length) => {
  const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  const values = crypto.getRandomValues(new Uint8Array(length));
  return values.reduce((acc, x) => acc + possible[x % possible.length], "");
}

const codeVerifier  = generateRandomString(64);


const sha256 = async (plain) => {
  const encoder = new TextEncoder()
  const data = encoder.encode(plain)
  return window.crypto.subtle.digest('SHA-256', data)
}


const base64encode = (input) => {
  return btoa(String.fromCharCode(...new Uint8Array(input)))
    .replace(/=/g, '')
    .replace(/\+/g, '-')
    .replace(/\//g, '_');
}


const startLogin = async () => {
  const hashed = await sha256(codeVerifier)
  const codeChallenge = base64encode(hashed);
  console.log(codeChallenge)
  const clientId = 'cd3e61bde252419da1e9b1051947a9a4';
  const redirectUri = 'http://localhost:3300/pages/2zzhu9pt/';
  const scope = 'user-read-playback-state user-read-currently-playing user-modify-playback-state playlist-modify-public playlist-modify-private playlist-read-private user-top-read user-follow-read user-library-read user-library-modify';
  const authUrl = new URL("https://accounts.spotify.com/authorize")
  window.localStorage.setItem('code_verifier', codeVerifier);
  const params =  {
    response_type: 'code',
    client_id: clientId,
    scope,
    code_challenge_method: 'S256',
    code_challenge: codeChallenge,
    redirect_uri: redirectUri,
  }
  authUrl.search = new URLSearchParams(params).toString();
  window.location.href = authUrl.toString();
}


document.addEventListener("DOMContentLoaded", () => {
  if (!localStorage.getItem('access_token')) {
    const newButton = document.createElement("button")
    newButton.innerText = "log in"
    newButton.addEventListener("click", startLogin)
    workspace.appendChild(newButton)
  } else {
    console.log("Ready to go")
  }
})




-- categories
-- Music 

-- metadata
-- date: 2023-12-24 05:10:35
-- id: 2zzdul5y
-- site: aws
-- type: post
-- status: draft