Skip to content

Commit

Permalink
fix chrome injection extension
Browse files Browse the repository at this point in the history
  • Loading branch information
dexterleng committed Jan 8, 2021
1 parent c2424df commit 53328fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 45 deletions.
2 changes: 1 addition & 1 deletion common/gameConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const config = {
PLAYER_SPEED: 1200,
PLAYER_CHAT_TIMEOUT: 5000, // 5s

MAP_IMAGE: './images/bg.png',
MAP_IMAGE: 'https://raw.githubusercontent.com/juxd/discord-spatial-layer/master/public/images/bg.png',

NEUTRAL_FACE: './images/tile000.png',
HAPPY_FACE: './images/tile002.png',
Expand Down
48 changes: 4 additions & 44 deletions extension/src/js/inject.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import nengiConfig from '../../../common/nengiConfig'
import main from '../../../client/runClient'

console.log(nengiConfig)
const SECRET_KEY_FORM_ID = 'secret-key-form'
import UI from '../../../client/runClient'

let container;

Expand All @@ -22,45 +18,9 @@ let container;
container.style.top = '60%'
container.style.backgroundColor = 'white'

container.insertAdjacentHTML('beforeend', renderSecretKeyForm())

// const canvas = document.createElement('canvas');
// canvas.id = 'game-canvas';
// canvas.style.height = '100%';
// canvas.style.width = '100%';
// canvas.style.backgroundColor = 'red';
const ui = new UI(container);
ui.start();

body.appendChild(container)
// container.appendChild(canvas)
}())

function renderSecretKeyForm() {
return `
<form id="${SECRET_KEY_FORM_ID}">
<label for="secret-key">Secret Key:</label><br>
<input type="text" id="secret-key" name="secret-key"><br>
<input type="submit" value="Submit">
</form>
`
}

function handleSecretKeyFormSubmit(e) {
const secretKey = document.getElementById('secret-key').value

const canvas = '<canvas id=\'main-canvas\' style="height: 100%; width: 100%"></canvas>'
container.innerText = ''
container.insertAdjacentHTML('beforeend', canvas)

main(secretKey)
}

document.addEventListener('submit', e => {
e.preventDefault()

const form = e.target
const formId = form.getAttribute('id')

if (formId === SECRET_KEY_FORM_ID) {
handleSecretKeyFormSubmit(e)
}
}, false)
}())

0 comments on commit 53328fa

Please sign in to comment.