Greasy Fork is available in English.

Discussions » Creation Requests

How to remove scripts contains

§
Posted: 31-03-2017
Edited: 31-03-2017

How to remove scripts contains

example
script type="text/javascript"
/*

§
Posted: 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.

§
Posted: 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

§
Posted: 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
§
Posted: 04-04-2017
Edited: 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).

§
Posted: 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

Post reply

تسجيل الدخول إلى مرحلة ما بعد الرد.