Skip to content

Instantly share code, notes, and snippets.

@disjukr
Created May 7, 2018 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disjukr/9ef2980a40629d460a536333b88c2f45 to your computer and use it in GitHub Desktop.
Save disjukr/9ef2980a40629d460a536333b88c2f45 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name discord-mini
// @namespace http://0xabcdef.com/discord-mini
// @version 0.0.1
// @description 디스코드 방목록이랑 유저목록 가리고싶엉
// @author JongChan Choi <jong@chan.moe>
// @match https://discordapp.com/channels/*
// @grant none
// ==/UserScript==
(async () => {
await wait('.content');
const guildsScroller = document.querySelector('.guilds.scroller');
const guildsWrapper = document.querySelector('.guilds-wrapper');
const layout = guildsWrapper.nextElementSibling.lastElementChild;
const roomsSideBar = layout.firstElementChild;
const usersSideBar = layout.lastElementChild.querySelector('.content').lastElementChild;
const toggleRoomsButton = button('방목록', toggle(roomsSideBar));
const toggleUsersButton = button('유저목록', toggle(usersSideBar));
guildsScroller.appendChild(toggleRoomsButton);
guildsScroller.appendChild(toggleUsersButton);
function button(textContent, onclick) {
const element = document.createElement('button');
Object.assign(element, { textContent, onclick });
return element;
}
function toggle(element) {
return () => element.style.display = element.style.display === 'none' ? 'initial' : 'none';
}
function wait(selector) {
return new Promise(resolve => {
const id = setInterval(() => {
if (document.querySelector(selector) != null) {
clearInterval(id);
resolve();
}
}, 100);
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment