Syncon

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

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==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()