NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name JVChat x WebM
// @namespace JVChat x WebM
// @version 1.0.1
// @description Affiche les WebM directement sur JVChat, pour ne pas avoir besoin de cliquer sur le lien
// @author xRock
// @match https://*.jeuxvideo.com/forums/42-*
// @match https://*.jeuxvideo.com/forums/1-*
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @updateURL https://openuserjs.org/install/xRock/JVChat_x_WebM.meta.js
// @license MIT
// ==/UserScript==
/* globals $:false */
const storageKey = "jvchat-x-webm"
let configuration = {
autoplay: false
}
// Sauvegarde de la configuration
const saveConfig = () => {
const config = JSON.stringify(configuration)
localStorage.setItem(storageKey, config)
}
// Chargement de la configuration
const loadConfig = () => {
let config = JSON.parse(localStorage.getItem(storageKey) || "{}")
for (const key in config) {
if (config.hasOwnProperty(key) && configuration.hasOwnProperty(key)) {
configuration[key] = config[key]
}
}
document.getElementById("jvchat-webm-autoplay-checkbox").checked = configuration.autoplay
}
// Sleep
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds));
}
// Scroll
const scroll = () => {
const element = document.getElementById("jvchat-main")
element.scrollTop = 50000
}
const notInQuote = (elem) => {
if (elem.parentNode.classList.contains("blockquote-jv")) {
return false
} else if (elem.parentNode.parentNode.classList.contains("blockquote-jv")) {
return false
} else if (elem.parentNode.parentNode.parentNode.classList.contains("blockquote-jv")) {
return false
} else {
return true
}
}
addEventListener("jvchat:newmessage", function (event) {
// Déclaration de variables utiles
const message = document.querySelector(`.jvchat-message[jvchat-id="${event.detail.id}"]`)
const text = message.querySelector(".txt-msg").textContent.toLowerCase().trim()
// Si le message contient un ".webm", le script s'exécute
if (text.includes(".webm")) {
// On récupère tous les liens du message
const aElements = message.querySelector(".txt-msg").getElementsByTagName("a")
// On vérifie tous les liens pour voir s'ils sont des liens de webm :
for (const elem of aElements) {
const link = elem.getAttribute("href")
if (link.includes(".webm")) {
$('<div class="webm-embed"></div>').insertAfter(elem)
const div = document.querySelectorAll(".webm-embed")[document.querySelectorAll(".webm-embed").length - 1]
new MutationObserver((mutationsList) => { mutationsList.forEach((muta) => { if (muta.target.classList[0] === "webm-embed") { sleep(500).then(() => { scroll() })}})}).observe(div, {childList: true, attributes: true, subtree: true})
$(div).html(`<video controls ${configuration.autoplay && notInQuote(elem) ? "autoplay" : ""} style="display: inline-block;" src="${link}">Your browser does not support the <code>video </code> element.</video>`) // ajoute un video player pour le webm
}
// On ramène la page en bas du défilement pour ne pas à avoir à scroll à la main
}
}
})
addEventListener("jvchat:activation", function (event) {
const css = `<style type="text/css" id="jvchat-vocaroo-css">.text-enrichi-forum iframe{margin-bottom:0!important;}</style>`
document.head.insertAdjacentHTML("beforeend", css)
const HTML = `<div class="jvchat-config-option" id="jvchat-webm-autoplay"><label><input id="jvchat-webm-autoplay-checkbox" type="checkbox"><span id="jvchat-webm-autoplay-span"> Lancement auto des WEBM</span></label><p>Lance automatiquement les WEBM lorsqu'ils sont chargés.</p></div>`
document.getElementById("jvchat-max-width").insertAdjacentHTML("afterend", HTML)
loadConfig()
document.getElementById("jvchat-webm-autoplay-checkbox").addEventListener("change", () => {
configuration.autoplay = document.getElementById("jvchat-webm-autoplay-checkbox").checked
if (!configuration.autoplay) {
for (const video of document.querySelectorAll("video")) {
video.pause()
}
}
saveConfig()
})
})