Skip to content

Commit

Permalink
Make StickyTeams More Sticky (#4)
Browse files Browse the repository at this point in the history
* Make StickyTeams More Sticky

* Remove Unneeded Permission Scripting
  • Loading branch information
smashedr authored Apr 18, 2024
1 parent 2ca5dfb commit b6ef911
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"description": "Play Dominoes"
}
},
"permissions": ["contextMenus", "scripting", "storage", "tabs"],
"permissions": ["contextMenus", "storage", "tabs"],
"content_scripts": [
{
"matches": ["*://*.playdrift.com/*"],
Expand Down
29 changes: 20 additions & 9 deletions src/js/content-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ function startMutation() {
}
// document.querySelectorAll('button[data-testid="button-continue"]')
if (mutation.target.dataset.testid === 'button-continue') {
console.info('button-continue:', mutation.target)
// console.info('button-continue:', mutation.target)
setTimeout(buttonContinue, 150, mutation.target)
setTimeout(buttonContinue, 250, mutation.target)
}
if (typeof mutation.target.dataset.team !== 'undefined') {
console.debug('Adding Team Click Listener')
console.debug('Adding Listener teamChangeClick')
mutation.target.addEventListener(
'click',
teamChangeClick
Expand Down Expand Up @@ -656,9 +656,9 @@ async function roomKickedChange(before, after) {
*/
async function roomTeamsChanged(before, after) {
console.debug('roomTeamsChanged:', before, after)
if (after.game) {
return console.debug('not sending team change because game active')
}
// if (after.game) {
// return console.debug('not sending team change because game active')
// }
const { options, profile } = await chrome.storage.sync.get([
'options',
'profile',
Expand All @@ -681,16 +681,19 @@ async function roomTeamsChanged(before, after) {
const from = before.teams[pid] ? `Team ${before.teams[pid]}` : 'No Team'
const to = after.teams[pid] ? `Team ${after.teams[pid]}` : 'No Team'
if (options.stickyTeams && player.id === profile.id) {
if (after.teams[pid] !== stickyTeams[currentRoom]) {
console.info('STICKY TEAM INTERCEPT')
if (
stickyTeams[currentRoom] &&
after.teams[pid] !== stickyTeams[currentRoom]
) {
console.info('StickyTeams Intercept')
await selectTeam(currentRoom, stickyTeams[currentRoom])
}
return console.info('Stop Processing on Sticky Teams Event')
}
if (options.playTeamsAudio) {
if (!after.game && options.playTeamsAudio) {
await audio.team.play()
}
if (options.sendTeamsChanged) {
if (!after.game && options.sendTeamsChanged) {
await sendChatMessage(
`${player.username} Changed from ${from} to ${to}`
)
Expand Down Expand Up @@ -755,6 +758,14 @@ async function gameEnd(state) {
if (options.sendGameStart) {
await sendChatMessage(result)
}
// if (
// options.stickyTeams &&
// stickyTeams[currentRoom] &&
// state.teams[profile.id] !== stickyTeams[currentRoom]
// ) {
// console.info('StickyTeams End-of-Game Check')
// await selectTeam(currentRoom, stickyTeams[currentRoom])
// }
}
}

Expand Down

0 comments on commit b6ef911

Please sign in to comment.