Skip to content

Commit

Permalink
Merge pull request #2 from croque-scp/limit-context
Browse files Browse the repository at this point in the history
Fix delete buttons interfering with message composer
  • Loading branch information
rossjrw authored Mar 6, 2022
2 parents 3c9f0c1 + 1879dc7 commit 04619fa
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions delete-applications.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ For installation instructions, see https://scpwiki.com/usertools
// @include https://www.wikidot.com/account/messages*
// ==/UserScript==

let deleteButtonsContainer

class Message {
constructor(messageElement) {
this.selector = messageElement.querySelector("input[type=checkbox]")
Expand Down Expand Up @@ -99,6 +101,15 @@ function deleteMessages(ids) {
confirmModal.show()
}

function shouldShowDeleteButtons(hash) {
return ["", "#/inbox"].includes(hash)
}

function toggleDeleteButtons() {
deleteButtonsContainer.style.display =
shouldShowDeleteButtons(location.hash) ? "" : "none"
}

/**
* Iterate the next page of messages.
*
Expand All @@ -113,7 +124,7 @@ async function nextPage(messageElement) {
if (nextButton.textContent.trim() !== "next »") return false

// Wait until the next page has finished loading
await new Promise((resolve, reject) => {
await new Promise(resolve => {
const observer = new MutationObserver(() => {
observer.disconnect()
resolve()
Expand Down Expand Up @@ -145,13 +156,18 @@ addEventListener("load", () => {
`.replace(/\s+/g, " ")
deleteAllButton.addEventListener("click", () => deleteApplications(true))

// Insert the button
const buttonLocation = document.getElementById("message-area").parentElement
buttonLocation.style.display = "flex"
buttonLocation.style.flexDirection = "column"
buttonLocation.style.alignItems = "flex-end"

const deleteButtonsContainer = document.createElement("span")
deleteButtonsContainer = document.createElement("div")
deleteButtonsContainer.style.textAlign = "right"
deleteButtonsContainer.append(deletePageButton, " ", deleteAllButton)
toggleDeleteButtons()

const buttonLocation = document.getElementById("message-area").parentElement
buttonLocation.prepend(deleteButtonsContainer)
})

// Detect clicks to messages and inbox tabs and hide/show buttons as appropriate
addEventListener("click", () => {
setTimeout(() => {
toggleDeleteButtons()
}, 500)
})

0 comments on commit 04619fa

Please sign in to comment.