<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[בקשת code review... סקריפט המרת וידיאו ב-iframe]]></title><description><![CDATA[<p dir="rtl">תגובה: <a href="/topic/6498/%D7%A9%D7%99%D7%AA%D7%95%D7%A3-%D7%A1%D7%A7%D7%A8%D7%99%D7%A4%D7%98-%D7%9C%D7%94%D7%A1%D7%A8%D7%AA-%D7%90%D7%9C%D7%9E%D7%A0%D7%98-%D7%9E%D7%99%D7%93-%D7%9C%D7%90%D7%97%D7%A8-%D7%A9%D7%A0%D7%95%D7%A6%D7%A8">שיתוף: סקריפט להסרת אלמנט מיד לאחר שנוצר</a></p>
<p dir="rtl">קוד זה מבוסס על <a href="https://netfree.link/injection-script/video-send.js" target="_blank" rel="noopener noreferrer nofollow ugc">סקריפט</a> שנכתב (כנראה על ידי <a class="plugin-mentions-user plugin-mentions-a" href="/user/dovid" aria-label="Profile: dovid">@<bdi>dovid</bdi></a>?) עבור נטפרי. הייעוד של הסקריפט הוא לזהות וידיאו חסום בדף ולהמיר כל אלמנט <code>video</code> חסום שנמצאה בלחצן "שלח בקשה לבדיקה". דרך הפעולה הוא על ידי טעינת הוידיאו בתוך iframe (זה גורם לקבלת דף חסימה), והכנסת ה-iframe לתוך הדף במיקום וגודל המדוייק של אלמנט הוידיאו המקורי.<br />
בקוד המקורי היו ארבע בעיות שניסיתי לתקן:</p>
<ul>
<li>לפעמים הקוד לא הצליח לזהות חסימה של וידיאו</li>
<li>לפעמים ה-<code>iframe</code> היתה מכסה שטח הרבה יותר גדול מהודיאו המקורי.</li>
<li>כאשר מקור הוידיאו היתה ב-http לא היתה אפשרות להטעין אותו בתוך iframe בדפים לא מאובטחים.</li>
<li>לפעמים ה-iframe היתה מוסתרת על ידי אלמנטים אחרים</li>
</ul>
<p dir="rtl">דוגמאות לדפים בהם הסקריפט נכשלה: <a href="https://www.hidabroot.org/article/1129130" target="_blank" rel="noopener noreferrer nofollow ugc">1</a>, <a href="https://www.hidabroot.org/video/213277" target="_blank" rel="noopener noreferrer nofollow ugc">2</a>, <a href="https://www.filamentgroup.com/lab/scrollbars" target="_blank" rel="noopener noreferrer nofollow ugc">3</a>, <a href="https://webkit.org/blog/9528/webgpu-and-wsl-in-safari" target="_blank" rel="noopener noreferrer nofollow ugc">4</a>, <a href="https://ladaat.co/archives/33735" target="_blank" rel="noopener noreferrer nofollow ugc">5</a> (נכון לעכשיו אפשר לבדוק, למי שנמצא בנטפרי, הסקריפט הזה מוזרק בברירת מחדל לכל הדפים)</p>
<p dir="rtl">ישבתי די הרבה זמן על הקוד הזה... (נסיתי כמה דרכים עד שהחלטתי שזה לכאורה הכי טוב)<br />
אשמח לביקורות</p>
<p dir="rtl">נ. ב. <a class="plugin-mentions-user plugin-mentions-a" href="/user/dovid" aria-label="Profile: dovid">@<bdi>dovid</bdi></a> אני לא מנסה להתנצח או להראות לכולם ראו! הצלחתי לכתוב משהו יותר טוב!. רק שעבדתי על זה די  קשה, ואני מאמין שעדיין אפשר לשפר את זה יותר. לכן אני מבקש ביקורות. אני מקווה שבסוף כל משתמשי נטפרי יהנו משיפור זה.</p>
<pre><code>(function () {
    var config = {
        attributes: false,
        childList: true,
        subtree: true
    };

    var observer = new MutationObserver(
        function (mutationsList) {
            for (let mutation of mutationsList)
                for (let el of mutation.addedNodes)
                    if (el.tagName == "VIDEO") el.addEventListener("error", function (e) {
                        addButton(this)
                    }, true);
        }
    );

    observer.observe(document, config);

    var vs = document.querySelectorAll("video");
    for (let v of vs) {

        // `HTMLMediaElement.error` doesn't get set when the video source is set in a child `source` element
        // https://stackoverflow.com/a/34239064/8997905
        // https://stackoverflow.com/a/20704999/8997905
        // https://stackoverflow.com/a/46508971/8997905
        // https://stackoverflow.com/questions/9175415

        if (v.error || v.networkState == 3) addButton(v);
        v.addEventListener("error", function (e) {
            console.trace(e);
            addButton(v);
        }, true);
    }

    function addButton(videoElement) {
        if (videoElement.buttonAdded) return; // don't run twice on error event - some pages seem to cause 2 errors
        videoElement.buttonAdded = 1;
        var src = new URL(videoElement.currentSrc);
        if (src.protocol == "blob:") return;
        src.protocol = document.location.protocol; // load http video over https

        var parent = videoElement.parentNode;
        var newNode = document.createElement("iframe");

        // getComputedStyle will only return a percentage when display is none
        // https://stackoverflow.com/a/8406724/8997905
        videoElement.style.display = "none";

        newNode.src = src.toString();
        newNode.style.border = "none";
        newNode.style.background = "#fff";
        newNode.style.zIndex = 9;

        function setProps(iframe) {
            [
                "position",
                "top",
                "left",
                "bottom",
                "right",
                "height",
                "max-height",
                "max-width",
                "min-height",
                "width",
                "min-width",
                "max-width",
                "padding",
                "margin"
            ].map(prop =&gt; newNode.style[prop] = window.getComputedStyle(videoElement)[prop]);
            if (newNode.style.position == "static") newNode.style.position = "relative";
        }

        setProps(newNode);
        setInterval(() =&gt; setProps(newNode), 3000);
        parent.appendChild(newNode);

        // mejs will overlay an error message when an error is detected, remove it.

        for (let overlay of document.querySelectorAll(".mejs__overlay.mejs__layer, .mejs-overlay.mejs-layer")) {
            for (let childElm of overlay.children) {
                if (childElm.classList.contains("mejs__overlay-error") || childElm.classList.contains("mejs-overlay-error"))
                    overlay.remove();
            }
        }
    }
})();
</code></pre>
]]></description><link>https://tchumim.com/topic/6522/בקשת-code-review-סקריפט-המרת-וידיאו-ב-iframe</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Nov 2026 02:36:18 GMT</lastBuildDate><atom:link href="https://tchumim.com/topic/6522.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 14 Sep 2019 19:54:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Thu, 19 Sep 2019 16:17:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a> תנסה את הקוד הבא:</p>
<pre><code>var btn = document.querySelector("button");
btn.addEventListener('click', function(){
  console.log(123);
  btn.outerHTML = btn.outerHTML;
});
</code></pre>
<p dir="rtl">האירוע יקרה רק פעם ראשונה, זה שיטה לסלק מאזינים של אלמנט להשים את הouterHTML שלו בעצמו.</p>
]]></description><link>https://tchumim.com/post/76551</link><guid isPermaLink="true">https://tchumim.com/post/76551</guid><dc:creator><![CDATA[dovid]]></dc:creator><pubDate>Thu, 19 Sep 2019 16:17:49 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Thu, 19 Sep 2019 16:05:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dovid" aria-label="Profile: dovid">@<bdi>dovid</bdi></a> אמר ב<a href="/post/76548">בקשת code review... סקריפט המרת וידיאו ב-iframe</a>:</p>
<blockquote>
<p dir="rtl">לי ברור שכן, ברגע שהאלמנט מנותק מהדום הוא מפסיק לחלוטין את ה"עבודה".</p>
</blockquote>
<p dir="rtl">התכוונתי לפתרון הראשון, אם אתה רק מחליף את ה-outerHTML, זה נשאר אותו node.</p>
]]></description><link>https://tchumim.com/post/76550</link><guid isPermaLink="true">https://tchumim.com/post/76550</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Thu, 19 Sep 2019 16:05:12 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Thu, 19 Sep 2019 16:00:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a> אמר ב<a href="/post/76547">בקשת code review... סקריפט המרת וידיאו ב-iframe</a>:</p>
<blockquote>
<p dir="rtl">אגב, יש עוד בעיה שעוד לא מצאתי לה פתרון, ב<a href="https://developers.google.com/web/updates/2019/09/nic77" target="_blank" rel="noopener noreferrer nofollow ugc">דף זה</a> הדפדפן מסרב להטעין את האייפרים בגלל <code>X-Frames-Options</code>.</p>
</blockquote>
<p dir="rtl">אפשר במקרה זה לשים ישר html כמו a פשוט לשליחת פניה, אבל זה מקרי קצה.</p>
]]></description><link>https://tchumim.com/post/76549</link><guid isPermaLink="true">https://tchumim.com/post/76549</guid><dc:creator><![CDATA[dovid]]></dc:creator><pubDate>Thu, 19 Sep 2019 16:00:28 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Thu, 19 Sep 2019 15:59:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a> אמר ב<a href="/post/76547">בקשת code review... סקריפט המרת וידיאו ב-iframe</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dovid" aria-label="Profile: dovid">@<bdi>dovid</bdi></a> אני חושש שזה יגרום לבעיות, כי יש עדיין error handler על ה-node של הוידיאו, האם זה יבוטל אוטומטית?</p>
</blockquote>
<p dir="rtl">לי ברור שכן, ברגע שהאלמנט מנותק מהדום הוא מפסיק לחלוטין את ה"עבודה".</p>
]]></description><link>https://tchumim.com/post/76548</link><guid isPermaLink="true">https://tchumim.com/post/76548</guid><dc:creator><![CDATA[dovid]]></dc:creator><pubDate>Thu, 19 Sep 2019 15:59:01 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Thu, 19 Sep 2019 15:53:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dovid" aria-label="Profile: dovid">@<bdi>dovid</bdi></a> אני חושש שזה יגרום לבעיות, כי יש עדיין error handler על ה-node של הוידיאו, האם זה יבוטל אוטומטית?<br />
גם אני עושה כל שלוש שניות העתקה חוזרת של המאפיינים, בגלל בעיה <a href="https://tchumim.com/post/76132">שציינתי למעלה</a>.<br />
<strong>עריכה</strong> אני רואה ש@magicode הוריד את זה... באמת לא היה פתרון אלגנטי...<br />
אולי כך:</p>
<pre><code>videoElement.after(newNode);
</code></pre>
<p dir="rtl">אגב, יש עוד בעיה שעוד לא מצאתי לה פתרון, ב<a href="https://developers.google.com/web/updates/2019/09/nic77" target="_blank" rel="noopener noreferrer nofollow ugc">דף זה</a> הדפדפן מסרב להטעין את האייפרים בגלל <code>X-Frames-Options</code>.</p>
<p dir="rtl">ועוד בעיה מצאתי בזכות ההפניה לאתר זה, שחכתי להוסיף למערך התכונות שצריך להעתיק את התכונה <code>float</code>... (שם הוידיאו מקבל <code>float: right</code> והאייפרים עומד בצד שמאל)</p>
]]></description><link>https://tchumim.com/post/76547</link><guid isPermaLink="true">https://tchumim.com/post/76547</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Thu, 19 Sep 2019 15:53:53 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Thu, 19 Sep 2019 15:46:44 GMT]]></title><description><![CDATA[<p dir="rtl">או אולי תקני יותר:</p>
<pre><code>parent.replaceChild(newNode, videoElement);
</code></pre>
]]></description><link>https://tchumim.com/post/76546</link><guid isPermaLink="true">https://tchumim.com/post/76546</guid><dc:creator><![CDATA[dovid]]></dc:creator><pubDate>Thu, 19 Sep 2019 15:46:44 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Thu, 19 Sep 2019 15:33:51 GMT]]></title><description><![CDATA[<p dir="rtl">ראיתי ש@magicode אימץ את הקוד שלך.<br />
אבל <a class="plugin-mentions-user plugin-mentions-a" href="/user/shraga" aria-label="Profile: shraga">@<bdi>shraga</bdi></a> הראה לי את הדף הזה <a href="https://developers.google.com/web/updates/2019/06" target="_blank" rel="noopener noreferrer nofollow ugc">https://developers.google.com/web/updates/2019/06</a><br />
הוידאו שמה ללא parent אישי, אלא ממש חלק מתוכן הדף ממילא הappend מוסיף רחוק מאוד מהמיקום המקורי (כאיבר אחרון במיכל).<br />
לכן אני חושב שצריך</p>
<pre><code>videoElement.outerHTML = newNode.outerHTML;
</code></pre>
]]></description><link>https://tchumim.com/post/76545</link><guid isPermaLink="true">https://tchumim.com/post/76545</guid><dc:creator><![CDATA[dovid]]></dc:creator><pubDate>Thu, 19 Sep 2019 15:33:51 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Sun, 15 Sep 2019 16:57:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dovid" aria-label="Profile: dovid">@<bdi>dovid</bdi></a> אמר ב<a href="/post/76168">בקשת code review... סקריפט המרת וידיאו ב-iframe</a>:</p>
<blockquote>
<p dir="rtl">ההתנצלות הזו קצת מעליבה אותי, אני לא הייתי בחיים בא בטענה על מישהו ש"מעיז" לשפר קוד שלי.</p>
</blockquote>
<p dir="rtl">סליחה...</p>
<p dir="rtl">תודה על ההערות</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dovid" aria-label="Profile: dovid">@<bdi>dovid</bdi></a> אמר ב<a href="/post/76168">בקשת code review... סקריפט המרת וידיאו ב-iframe</a>:</p>
<blockquote>
<p dir="rtl">כי לא שאפתי מייד לשלמות</p>
</blockquote>
<p dir="rtl">אני מסכים לגמרי שלא צריך שלמות מיד. רק מה, הסיבה שבכלל שמתי לב לסקריפט היתה כי זה שיבש דפים. אולי כדאי להשבית את הסקריפט עד שלפחות הוא לא ישבש דפים.</p>
]]></description><link>https://tchumim.com/post/76175</link><guid isPermaLink="true">https://tchumim.com/post/76175</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Sun, 15 Sep 2019 16:57:18 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Sun, 15 Sep 2019 15:31:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/yossiz" aria-label="Profile: yossiz">@<bdi>yossiz</bdi></a> אמר ב<a href="/post/76098">בקשת code review... סקריפט המרת וידיאו ב-iframe</a>:</p>
<blockquote>
<p dir="rtl">נ. ב. <a class="plugin-mentions-user plugin-mentions-a" href="/user/dovid" aria-label="Profile: dovid">@<bdi>dovid</bdi></a> אני לא מנסה להתנצח או להראות לכולם ראו! הצלחתי לכתוב משהו יותר טוב!. רק שעבדתי על זה די  קשה, ואני מאמין שעדיין אפשר לשפר את זה יותר. לכן אני מבקש ביקורות. אני מקווה שבסוף כל משתמשי נטפרי יהנו משיפור זה.</p>
</blockquote>
<p dir="rtl">ההתנצלות הזו קצת מעליבה אותי, אני לא הייתי בחיים בא בטענה על מישהו ש"מעיז" לשפר קוד שלי.<br />
ההערות שלך נכונות ולקחתי אותם בחשבון (לא היה לי פתרון וגם לא נלחצתי כי לא שאפתי מייד לשלמות - עד היום היה צריך הקלטה למי שלא יודע לחפש את הכתובת בקונסול).<br />
הפתרון שלך מצויין. אני חשבתי על כיוון של יצירת דיב עם אותם הגדרות של הוידאו ולהעביר את הוידאו לתוכו אבל אפילו לא ניסיתי את זה כי היה לי תחושה שניתוק מהDOM והחזרה אליו יעוררו את האירוע שוב ושוב - אולי אני טועה.</p>
]]></description><link>https://tchumim.com/post/76168</link><guid isPermaLink="true">https://tchumim.com/post/76168</guid><dc:creator><![CDATA[dovid]]></dc:creator><pubDate>Sun, 15 Sep 2019 15:31:56 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Sun, 15 Sep 2019 09:14:07 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://www.vishay.com/videos/mosfets/trenchfet174-mosfets-in-automotive-applications.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.vishay.com/videos/mosfets/trenchfet174-mosfets-in-automotive-applications.html</a></p>
<p dir="rtl">כאן יש בעיה אחרת - אלמנט הוידיאו יש לו <code>left-margin: -999999</code>, עד שלוחצים על <img src="https://tchumim.com/assets/plugins/nodebb-plugin-emoji/emoji/android/25b6.png?v=cf1b4e11576" class="not-responsive emoji emoji-android emoji--arrow_forward" style="height:23px;width:auto;vertical-align:middle" title=":arrow_forward:" alt="▶" /> ואז הוא מקבל <code>left-margin: 0</code>. מכיון שה-iframe נוצר לפני הלחיצה על <img src="https://tchumim.com/assets/plugins/nodebb-plugin-emoji/emoji/android/25b6.png?v=cf1b4e11576" class="not-responsive emoji emoji-android emoji--arrow_forward" style="height:23px;width:auto;vertical-align:middle" title=":arrow_forward:" alt="▶" /> ממילא הוא יורש את ההגדרה של <code>left-margin: -999999</code>.</p>
<p dir="rtl"><strong>פתרון אפשרי:</strong> להאזין לשינויי attributes על הוידיאו ולפעול בהתאם.</p>
]]></description><link>https://tchumim.com/post/76132</link><guid isPermaLink="true">https://tchumim.com/post/76132</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Sun, 15 Sep 2019 09:14:07 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Sun, 15 Sep 2019 08:59:28 GMT]]></title><description><![CDATA[<p dir="rtl">עוד מקרה,<br />
<a href="https://www.vishay.com/videos/capacitorsconnectors/estaspring-connection-8211-product-overview.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.vishay.com/videos/capacitorsconnectors/estaspring-connection-8211-product-overview.html</a><br />
כאן אלמנט הוידיאו לא זורק שגיאה, מכיון שעוד לא קיים <code>src</code>, זאת מכיון שיש שגיאה קודמת של קריאת AJAX.<br />
מה הפתרון?</p>
<p dir="rtl"><strong>עריכה:</strong> לכאורה אין פתרון, כי גם אם נצליח לזהות את מצב החסימה, עדיין איננו יודעים מהו ה-<code>src</code> של הוידיאו כדי לשלוח פניה</p>
<p dir="rtl"><strong>עריכה2:</strong> פתחו את החסימה, מתברר שה-<code>src</code> של הוידיאו הוא <code>blob</code>... לכאורה במקרה כזה אין דרך אוטומטית לחלץ את ה-URL המקורי של הוידיאו, נכון?</p>
]]></description><link>https://tchumim.com/post/76130</link><guid isPermaLink="true">https://tchumim.com/post/76130</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Sun, 15 Sep 2019 08:59:28 GMT</pubDate></item><item><title><![CDATA[Reply to בקשת code review... סקריפט המרת וידיאו ב-iframe on Sun, 15 Sep 2019 07:35:02 GMT]]></title><description><![CDATA[<p dir="rtl">בעיה שמצאתי,<br />
<a href="https://www.apple.com/mac-pro" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.apple.com/mac-pro</a><br />
אם לוחצים על:<br />
<img src="/assets/uploads/files/1568532565760-b3f31271-49b1-4141-a780-93f041508bdf-image.png" alt="b3f31271-49b1-4141-a780-93f041508bdf-image.png" class=" img-fluid img-markdown" /><br />
יש שם סרטון שמכוסה על ידי הודעת שגיאה, הודעת השגיאה עולה על גבי אלמנט הוידיאו וה-iframe של נטפרי (גם אם ניתן לו z-index גבוה), מכיון שהם <code>position: static</code> והודעת השגיאה הוא <code>position: absolute</code>.</p>
<p dir="rtl">התיקון לכאורה הוא להוסיף אחרי שורה 59:</p>
<pre><code>if (newNode.style.position == "static") newNode.style.position = "relative";
</code></pre>
<p dir="rtl">האם זה יגרום לתופעת לוואי לא רצויות?</p>
]]></description><link>https://tchumim.com/post/76126</link><guid isPermaLink="true">https://tchumim.com/post/76126</guid><dc:creator><![CDATA[yossiz]]></dc:creator><pubDate>Sun, 15 Sep 2019 07:35:02 GMT</pubDate></item></channel></rss>