Skip to content

Instantly share code, notes, and snippets.

@fluks
Last active February 3, 2023 17:14
Show Gist options
  • Save fluks/51d7b3a3548cb00ac3468398e6452e4e to your computer and use it in GitHub Desktop.
Save fluks/51d7b3a3548cb00ac3468398e6452e4e to your computer and use it in GitHub Desktop.
Open Dlive sticker to a new tab with middle mouse button
// ==UserScript==
// @name Dlive
// @description Open sticker on dlive with middle mouse button to a new tab
// @version 1
// @grant none
// @include /^https:\/\/dlive.tv\/.+$/
// @run-at document-end
// ==/UserScript==
'use strict';
function addClickHandler(elem) {
elem.addEventListener('mousedown', (e) => {
if (e.button === 1)
window.open(elem.src);
});
}
function dlive(chat) {
chat.querySelectorAll('.emote-img').forEach(e => addClickHandler(e));
const o = new MutationObserver((mutationList) => {
for (const m of mutationList) {
const sticker = m.addedNodes[0].querySelector('.emote-img');
if (sticker)
addClickHandler(sticker);
}
});
o.observe(chat, { childList: true, attributes: true, subtree: true, });
}
const chatBody = document.querySelector('#chat-body');
if (chatBody) {
dlive(chatBody);
}
else {
const o = new MutationObserver((mutationList) => {
for (const m of mutationList) {
const chat = m.addedNodes[0].querySelector('#chat-body');
if (chat) {
dlive(chat);
}
}
});
o.observe(document.body, { childList: true, attributes: true, subtree: true, });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment