Syncon

더블콘이 동시에 재생될 수 있게 전부 불러온 뒤 화면에 보여지게 변경합니다

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Syncon
// @namespace   syncon
// @description 더블콘이 동시에 재생될 수 있게 전부 불러온 뒤 화면에 보여지게 변경합니다
// @version     0.1.0
// @author      Sangha Lee
// @copyright   2024, Sangha Lee
// @license     MIT
// @match       https://gall.dcinside.com/board/view/*
// @match       https://gall.dcinside.com/mgallery/board/view/*
// @match       https://gall.dcinside.com/mini/board/view/*
// @match       https://gall.dcinside.com/person/board/view/*
// @icon        https://nstatic.dcinside.com/dc/m/img/dcinside_icon.png
// ==/UserScript==


/**
 * @param {T[]} array 
 * @param {number} n
 * @returns {T[][]} 
 */
function* chunks (array, n) {
    for (let i = 0; i < array.length; i += n) {
        yield array.slice(i, i + n)
    }
}

function sync () {
    for (const $chunk of [
        ...chunks([...document.querySelectorAll('.comment_dccon.double video')], 2)
    ]) {
        const promises = $chunk.map(
            /** @returns {Promise<HTMLImageElement>} */
            $video => new Promise((resolve, reject) => {
                // fuck off autoplay permission, we fully gifing
                const $img = document.createElement('img')
                $img.classList.add('written_dccon')
                $img.src = $video.getAttribute('onmousedown').split("'")[1]

                if ($video.classList.contains('bigdccon')) {
                    $img.classList.add('bigdccon')   
                }

                $img.addEventListener('load', () => resolve($img))
                $img.addEventListener('error', reject)

                $video.insertAdjacentElement('beforebegin', $img)
                $video.remove()
            })
        )

        Promise.all(promises)
            .then($imgs => $imgs.forEach($img => {
                const src = $img.src
                $img.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACw='
                setTimeout(() => $img.src = src, 100)
            }))
    }
}

new MutationObserver(sync)
    .observe(document.querySelector('.comment_wrap'), {
        childList: true
    })

sync()