Syncon

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

  1. // ==UserScript==
  2. // @name Syncon
  3. // @namespace syncon
  4. // @description 더블콘이 동시에 재생될 수 있게 전부 불러온 뒤 화면에 보여지게 변경합니다
  5. // @version 0.1.0
  6. // @author Sangha Lee
  7. // @copyright 2024, Sangha Lee
  8. // @license MIT
  9. // @match https://gall.dcinside.com/board/view/*
  10. // @match https://gall.dcinside.com/mgallery/board/view/*
  11. // @match https://gall.dcinside.com/mini/board/view/*
  12. // @match https://gall.dcinside.com/person/board/view/*
  13. // @icon https://nstatic.dcinside.com/dc/m/img/dcinside_icon.png
  14. // ==/UserScript==
  15.  
  16.  
  17. /**
  18. * @param {T[]} array
  19. * @param {number} n
  20. * @returns {T[][]}
  21. */
  22. function* chunks (array, n) {
  23. for (let i = 0; i < array.length; i += n) {
  24. yield array.slice(i, i + n)
  25. }
  26. }
  27.  
  28. function sync () {
  29. for (const $chunk of [
  30. ...chunks([...document.querySelectorAll('.comment_dccon.double video')], 2)
  31. ]) {
  32. const promises = $chunk.map(
  33. /** @returns {Promise<HTMLImageElement>} */
  34. $video => new Promise((resolve, reject) => {
  35. // fuck off autoplay permission, we fully gifing
  36. const $img = document.createElement('img')
  37. $img.classList.add('written_dccon')
  38. $img.src = $video.getAttribute('onmousedown').split("'")[1]
  39.  
  40. if ($video.classList.contains('bigdccon')) {
  41. $img.classList.add('bigdccon')
  42. }
  43.  
  44. $img.addEventListener('load', () => resolve($img))
  45. $img.addEventListener('error', reject)
  46.  
  47. $video.insertAdjacentElement('beforebegin', $img)
  48. $video.remove()
  49. })
  50. )
  51.  
  52. Promise.all(promises)
  53. .then($imgs => $imgs.forEach($img => {
  54. const src = $img.src
  55. $img.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACw='
  56. setTimeout(() => $img.src = src, 100)
  57. }))
  58. }
  59. }
  60.  
  61. new MutationObserver(sync)
  62. .observe(document.querySelector('.comment_wrap'), {
  63. childList: true
  64. })
  65.  
  66. sync()