Last active
March 22, 2023 13:05
-
-
Save spddl/95c8656ce38b09ec0308b2dfeab10035 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Discord MSG Center | |
// @version 0.3 | |
// @author You | |
// @match https://discord.com/channels/@me | |
// @grant none | |
// ==/UserScript== | |
var queryByAttrNameStartsWith = (contextualSelector = '*', prefix = "") => { | |
const allSel = document.querySelectorAll(contextualSelector) | |
for (let i = 0; i < allSel.length; i++) { | |
const classList = allSel[i].classList | |
for (let ii = 0; ii < classList.length; ii++) { | |
if (classList[ii].startsWith(prefix)) { | |
return classList[ii] | |
} | |
} | |
} | |
return null | |
} | |
function styleWindow() { | |
const dd = document.querySelector("div."+queryByAttrNameStartsWith('div', 'recentMentionsPopout-')) | |
dd.style.width = "95vw" // 35vw | |
dd.style.maxWidth = "90vw" // 600px | |
dd.style.maxHeight = "100vh" // 80vh | |
dd.style.height = "95vh" | |
} | |
;(function() { | |
'use strict' | |
const delay = 3 // sec | |
var button = document.querySelector('[aria-label="Posteingang"]') | |
var waitToToggle = false | |
var callback = (mutationList, observer) => { | |
for (const mutation of mutationList) { | |
if (mutation.attributeName === 'aria-expanded') { | |
if (mutation.target.getAttribute('aria-expanded') === 'true') { // window is open | |
if (waitToToggle) { | |
waitToToggle = false | |
styleWindow() | |
} | |
} else if (waitToToggle) { // window is closed | |
button.click() // open | |
} | |
} | |
} | |
} | |
var MsgCheck = () => { | |
if (location.href === "https://discord.com/channels/@me") { | |
try { | |
if (button === null || !button.isConnected) { | |
button = document.querySelector('[aria-label="Posteingang"]') | |
var observer = new MutationObserver(callback) | |
observer.observe(button, { attributes: true }) | |
window.addEventListener('beforeunload', () => { | |
observer.disconnect() | |
}) | |
} | |
if (button.getAttribute('aria-expanded') == 'false') { // window is closed | |
return | |
} | |
if (document.querySelectorAll("div[data-list-id]").length > 1) { | |
if (document.querySelectorAll("div[data-list-id]")[1].scrollTop !== 0) { // updated only if not scrolled | |
return | |
} | |
} | |
waitToToggle = true | |
button.click() // close | |
} catch(err) { | |
console.log(err) | |
} | |
} | |
} | |
setInterval(() => { | |
MsgCheck() | |
}, delay * 1000) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment