Possibility to block and entire <script>block?
cryothic opened this issue · 3 comments
cryothic commented
Is it possible to block an entire <script> block like this?
If I add a block like this:
<script type="javascript/blocked"> (function(){ alert("loaded"); })() </script>
it isn't executed. But when I call .unblock()
this whole block disappears.
We're working with a CMS where we don't know what scripts the author will add to a page.
elbywan commented
Hey @cryothic,
Is it possible to block an entire <script> block like this?
Unfortunately no, yett
is meant to block script blocks having a src
attribute and will not restore a script contents when unblocking.
cryothic commented
Hi Julien,
I downloaded your project, and made some changes by setting the
.textContent from the cached script to the newly created script when
unblocking.
It seems to work for me now.
Great package! We're using Umbraco CMS, so we don't control all scripts our
customers add to a site. This way, we can block some scripts when the uses
didn't gave their consent.
Thank you!
…On Tue, Jul 11, 2023 at 10:17 AM Julien Elbaz ***@***.***> wrote:
Hey @cryothic <https://github.com/cryothic>,
Is it possible to block an entire <script> block like this?
Unfortunately no, yett is meant to block script blocks having a src
attribute and will not restore a script contents when unblocking.
—
Reply to this email directly, view it on GitHub
<#42 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADFEAZEFQNMVI4YBVNUMTQ3XPUDYHANCNFSM6AAAAAAZ5PHOFM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
cryothic commented
Hi there,
Sorry for the (very) late response. I had switched work-machine, forgot
about your email, and just now found it.
I'm not that familiair with GIT, and Gmail doesn't allow me to send the .js
file (or a zip with the js file in it).
So I'm doing this the old fashioned way.
What worked for me was:
unblock.js
after the loop through the attributes (around line 78 in my script), I've
added:
// ipsis - only add a source attribute when there was a source
if (script.src !== '') {
scriptNode.setAttribute('src', script.src)
}
// ipsis - add textContent, if there was any
if (script.textContent !== '') {
scriptNode.textContent = script.textContent
}
Also a screenshot of the surrounding code:
[image: image.png]
This seems to work for me.
Greetings,
Jeroen
…On Tue, Aug 29, 2023 at 7:59 AM Muhammad Tayyab ***@***.***> wrote:
@cryothic <https://github.com/cryothic> can you please send me your
updated code
—
Reply to this email directly, view it on GitHub
<#42 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADFEAZEX5W7VEIFYVC4YSB3XXWANPANCNFSM6AAAAAAZ5PHOFM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>