D
D
Dmitry Kinash2018-04-12 10:30:15
JavaScript
Dmitry Kinash, 2018-04-12 10:30:15

How to remove a script from a web page?

There is one site (more precisely, not even one) that you need to work with, but which decided to pursue an aggressive policy of displaying ads. A script is inserted in the body of the page (a script tag with the path to the internal js page specified in src), which, when the page is loaded using document.write, opens the ad.yandex.ru page in it, indicating the current location for the redirect. If I were an ordinary resident of the Russian Federation or the BR, then there were no problems. But I live in Ukraine, where all Yandex IPs are blocked by all providers.
Disabling the execution of all scripts leads to the inoperability of the site (authorization and all that). If you see the address of a specific "advertising script" in the source code and block it with something like adBlock, then you can use the site for some time. But when creating a new session (as well as after some time of browsing through the pages), the address of the "advertising script" changes and the site again throws at the stub the impossibility of opening Yandex in Ukraine.
I ask for help in writing a script for Tampermonkey/Greasemonkey. The essence of the idea is to cut out the launch of the "advertising script" from the DOM structure - it will be the second one in the header.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Kornilov, 2018-04-12
@Dementor

document.scripts[1].remove();
You can just from the console.

A
Anton fon Faust, 2018-04-12
@bubandos

The easiest option is to override document.write.

// ==UserScript==
// @name         override document.write
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://tampermonkey.net/index.php?version=4.5&ext=dhdg&updated=true
// @grant        none
// @include *
// ==/UserScript==
(function() {
    'use strict';
    window.document.write = function() {return false;};
    // Your code here...
})();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question