Guest User

Wykop - filmy inline zamiast overlaya

a guest
Oct 7th, 2026
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | Fixit | 0 0
  1. // ==UserScript==
  2. // @name Wykop - filmy inline zamiast overlaya
  3. // @namespace https://wykop.pl/
  4. // @version 1.4
  5. // @description Odtwarza embedy wewnątrz posta (na pełną szerokość) zamiast w overlayu, z przyciskiem zamykania
  6. // @match https://wykop.pl/*
  7. // @run-at document-idle
  8. // @grant GM_addStyle
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. GM_addStyle(`
  15. section.embed-preview { display: none !important; }
  16. .wk-hidden-multimedia { display: none !important; }
  17. .media:has(.wk-inline-embed) {
  18. width: 100% !important;
  19. max-width: none !important;
  20. overflow: visible !important;
  21. }
  22. .wk-inline-embed {
  23. display: block;
  24. margin: 8px 0;
  25. max-width: none;
  26. }
  27. .wk-inline-bar {
  28. display: flex;
  29. justify-content: flex-end;
  30. margin-bottom: 4px;
  31. }
  32. .wk-inline-close {
  33. cursor: pointer;
  34. font-size: 12px;
  35. line-height: 1;
  36. padding: 4px 10px;
  37. border-radius: 4px;
  38. border: 1px solid rgba(128, 128, 128, 0.5);
  39. background: rgba(128, 128, 128, 0.15);
  40. color: inherit;
  41. }
  42. .wk-inline-close:hover {
  43. background: rgba(220, 50, 50, 0.85);
  44. color: #fff;
  45. border-color: transparent;
  46. }
  47. .wk-inline-video {
  48. position: relative;
  49. background: #000;
  50. width: 100%;
  51. }
  52. .wk-inline-video iframe {
  53. position: absolute;
  54. top: 0; left: 0;
  55. width: 100%;
  56. height: 100%;
  57. border: 0;
  58. }
  59. `);
  60.  
  61. // Szerokość użytkowa posta (blok treści minus paddingi)
  62. function getPostWidth(wrapper) {
  63. const item = wrapper.closest('section.item');
  64. if (item) {
  65. const el = item.querySelector(':scope > .content') || item;
  66. const cs = getComputedStyle(el);
  67. const w = el.getBoundingClientRect().width
  68. - (parseFloat(cs.paddingLeft) || 0)
  69. - (parseFloat(cs.paddingRight) || 0);
  70. if (w > 200) return w;
  71. }
  72. const host = wrapper.parentElement;
  73. const hw = host ? host.getBoundingClientRect().width : 0;
  74. return hw > 200 ? hw : 480;
  75. }
  76.  
  77. function sizeWrapper(wrapper) {
  78. const w = Math.floor(getPostWidth(wrapper));
  79. wrapper.style.setProperty('width', w + 'px', 'important');
  80. const video = wrapper.querySelector('.wk-inline-video');
  81. if (video) video.style.setProperty('height', Math.round(w * 9 / 16) + 'px', 'important');
  82. }
  83.  
  84. window.addEventListener('resize', () => {
  85. document.querySelectorAll('.wk-inline-embed').forEach(sizeWrapper);
  86. });
  87.  
  88. function closeInline(wrapper, multimedia) {
  89. const frame = wrapper.querySelector('iframe');
  90. if (frame) frame.src = 'about:blank'; // zatrzymaj odtwarzanie
  91. wrapper.remove();
  92. if (multimedia) multimedia.classList.remove('wk-hidden-multimedia');
  93. }
  94.  
  95. let lastEmbed = null;
  96. let lastTimer = null;
  97.  
  98. document.addEventListener('click', (e) => {
  99. const embed = e.target.closest('.multimedia .embed');
  100. if (!embed) return;
  101. lastEmbed = embed;
  102. clearTimeout(lastTimer);
  103. lastTimer = setTimeout(() => { lastEmbed = null; }, 3000);
  104. }, true);
  105.  
  106. function handleOverlay(overlay) {
  107. const iframe = overlay.querySelector('iframe');
  108. if (!iframe || !lastEmbed) return;
  109.  
  110. const src = iframe.getAttribute('src');
  111. const multimedia = lastEmbed.closest('.multimedia');
  112. lastEmbed = null;
  113. clearTimeout(lastTimer);
  114. if (!multimedia || !multimedia.parentElement) return;
  115.  
  116. const closeBtn = overlay.querySelector('header button');
  117. if (closeBtn) closeBtn.click();
  118.  
  119. const prev = multimedia.parentElement.querySelector('.wk-inline-embed');
  120. if (prev) prev.remove();
  121.  
  122. const wrapper = document.createElement('div');
  123. wrapper.className = 'wk-inline-embed';
  124. wrapper.addEventListener('click', (ev) => ev.stopPropagation());
  125.  
  126. const bar = document.createElement('div');
  127. bar.className = 'wk-inline-bar';
  128. const btn = document.createElement('button');
  129. btn.type = 'button';
  130. btn.className = 'wk-inline-close';
  131. btn.textContent = '✕ Zamknij film';
  132. btn.addEventListener('click', (ev) => {
  133. ev.preventDefault();
  134. ev.stopPropagation();
  135. closeInline(wrapper, multimedia);
  136. });
  137. bar.appendChild(btn);
  138.  
  139. const video = document.createElement('div');
  140. video.className = 'wk-inline-video';
  141. const newFrame = document.createElement('iframe');
  142. newFrame.src = src;
  143. newFrame.allowFullscreen = true;
  144. newFrame.setAttribute('allow', 'autoplay; encrypted-media; fullscreen');
  145. newFrame.setAttribute('scrolling', 'no');
  146. video.appendChild(newFrame);
  147.  
  148. wrapper.appendChild(bar);
  149. wrapper.appendChild(video);
  150.  
  151. multimedia.classList.add('wk-hidden-multimedia');
  152. multimedia.insertAdjacentElement('afterend', wrapper);
  153. sizeWrapper(wrapper);
  154. }
  155.  
  156. new MutationObserver((mutations) => {
  157. for (const m of mutations) {
  158. for (const node of m.addedNodes) {
  159. if (node.nodeType !== 1) continue;
  160. const overlay = node.matches?.('section.embed-preview')
  161. ? node
  162. : node.querySelector?.('section.embed-preview');
  163. if (overlay) handleOverlay(overlay);
  164. }
  165. }
  166. }).observe(document.body, { childList: true, subtree: true });
  167. })();
Advertisement
Add Comment
Please, Sign In to add comment