Discussões » Solicitações de Criação

How to remove scripts contains

§
Publicado em: 31/03/2017
Editado em: 31/03/2017

How to remove scripts contains

example
script type="text/javascript"
/*

§
Publicado em: 03/04/2017

Your script must run before other scripts. Read this. Then just grab all script tags document.getElementsByTagName('script'), loop through them and remove/edit the ones you don't need. Loop in reversed order because removing script tags will mess with indexes.

§
Publicado em: 04/04/2017

Firstly thank you ...
If I do document-start var a = document.getElementsByTagName ('script'); Returns 0 if I do document-end it returns 30 ok that part now how do I get what's inside the scripts

§
Publicado em: 04/04/2017

My bad. There are no <script> elements at document-start so you need to add a listener. Like this:

// ==UserScript==
// @name        __TEST
// @namespace   tithen-firion
// @include     *
// @version     1
// @run-at      document-start
// ==/UserScript==

window.addEventListener('beforescriptexecute', function(e) {

  // if you want to stop whole <script>
  if(e.target.innerHTML.search(/var .*?=window;/) {
    e.preventDefault();
    e.stopPropagation();
  }

  // if you want to change part of a code
  e.target.innerHTML= e.target.innerHTML.replace(/bla bla bla/, 'bla bla');
}, true);

e.target.innerHTML is content of <script> tag.

woxxomMod
§
Publicado em: 04/04/2017
Editado em: 04/04/2017

The OP uses Chrome which doesn't implement beforescriptexecute:

The beforescriptexecute/afterscriptexecute events have been removed from the specification (https://github.com/whatwg/html/pull/1103), and they will not be implemented in Chrome.

Because of this, uBlock origin extra extension fetches the page html via XHR, deletes the scripts, then rewrites the page using document.write (source code).

§
Publicado em: 06/04/2017

I use Opera it does not work signal ... but in firefox worked very well but it seems that the other scripts stop again thanks for answering me

Enviar resposta

Entre para publicar uma resposta.