讨论 » 创建请求

How to remove scripts contains

§
发布于:2017-03-31
编辑于:2017-03-31

How to remove scripts contains

example
script type="text/javascript"
/*

§
发布于:2017-04-03

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.

§
发布于:2017-04-04

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

§
发布于:2017-04-04

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.

woxxom管理员
§
发布于:2017-04-04
编辑于:2017-04-04

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).

§
发布于:2017-04-06

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

发布留言

登录以发布留言。