Skip to content

Instantly share code, notes, and snippets.

@easrng
Created December 17, 2021 20:41
Show Gist options
  • Save easrng/554321d2e73e30218ddd38828227d36f to your computer and use it in GitHub Desktop.
Save easrng/554321d2e73e30218ddd38828227d36f to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name fluffyscratch oneclick test
// @namespace helo
// @match https://fluffyscratch.hampton.pw/auth/getKeys/v2
// @grant none
// @version 1.0
// @author -
// @description it does the thing
// ==/UserScript==
let key=new URLSearchParams(location.search).get("localRedirect");
if(key){
let url=localStorage.getItem(key)
localStorage.removeItem(key)
location.replace(url)
}
let comframe=Object.assign(document.createElement("iframe"), {src:"https://scratch.mit.edu/projects/618552781/embed",style:"width:0;height:0;border:0;margin:0;"});
let cancel;
let hasOneClick=false;
document.querySelector("#text").insertAdjacentHTML("afterEnd", `<div id="oneclick">
<img id="avatar">
<p>You are logged in as <b id="username"></b></p>
</div>
<style>
.login.oneclick > :not(h1):not(nav):not(#oneclick) {
display: none;
}
.login:not(.oneclick) #oneclick {
display: none;
}
#avatar {
width: 3.5rem;
height: 3.5rem;
border-radius: 4px;
}
#oneclick p {
margin: 0.75rem 0 0 0;
}
</style>`)
comframe.addEventListener("load", () => {
if(!hasOneClick) cancel=setTimeout(()=>comframe.remove(), 200)
});
window.addEventListener("message", function onMessage(e){
if(e.data.oneClickFluffyScratchLogin){
if(e.data.loaded) {
hasOneClick=true;
if(typeof cancel !== "undefined") clearTimeout(cancel)
console.log("we have 1click")
}
if(typeof e.data.isLoggedIn !== "undefined") {
if(e.data.isLoggedIn) {
document.querySelector("#username").textContent=e.data.username;
document.querySelector("#avatar").src="https://cdn2.scratch.mit.edu/get_image/user/" + e.data.userId+"_90x90.png";
document.querySelector(".login").classList.add("oneclick")
let ogStep1=steps.pop();
steps[0]=()=>{
document.querySelector("#continue").disabled=true;
document.querySelector("#continue").textContent="Loading...";
let key=crypto.getRandomValues(new Uint8Array(8)).join("");
localStorage.setItem(key, JSON.parse(ogStep1.toString().match(/location.href=([^;]+)/)[1]))
comframe.contentWindow.postMessage({
oneClickFluffyScratchLogin: true,
publicCode: document.querySelector("#publicCode").value,
redirect: "https://fluffyscratch.hampton.pw/auth/getKeys/v2?localRedirect="+key
}, "*")
}
}
}
}
})
document.body.appendChild(comframe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment