Skip to content

Instantly share code, notes, and snippets.

@jahands
Created May 20, 2021 03:21
Show Gist options
  • Save jahands/d6a22b60e708c77936c757c7154b546a to your computer and use it in GitHub Desktop.
Save jahands/d6a22b60e708c77936c757c7154b546a to your computer and use it in GitHub Desktop.
Updates repl name based on url (eg. repl.new/py/python_project)
// ==UserScript==
// @name Replit_New_Namer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Sets the name based on the url when using repl.new. Eg. repl.new/py/my awesome python project
// @author Jacob Hands
// @match https://replit.com/new/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
console.log("hello, world!");
console.log(window.location.href)
const url = new URL(window.location.href)
const name = url.searchParams.get('name')
if(name){
// Apply name
const elems = document.getElementsByClassName('jsx-896142976');
let x = null
for (let i in elems){
if(elems[i].nodeName === 'INPUT'){
x = elems[i]
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
document.onreadystatechange = () => {
if (document.readyState === 'complete') {
// document ready
sleep(500).then(() => {
x.value=name
})
}
};
console.log(x)
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment