1

Is there a chrome extension could modify html automatically?

For example, here is an annoying header.

<header class="top-bar js-top-bar top-bar__network _fixed">

I would like chrome delete this header during rendering page.

Is there a chrome extension could do this job?

AutoReplaceHTML seems to be an option, although it does not support https.

Here is my TamperMonkey settings.

enter image description here

When I save the script, load an page, nothing has happened, the element to be deleted is still there.

enter image description here

If I copy & paste all this code, "Invalid" error shows up.

enter image description here

1 Answer 1

2

Yes, TamperMonkey is designed just for stuff like this. By default it doesn't do anything, but you can create custom scripts that will be run when opening websites that you specify. Here is an example script that will delete the element from your example:

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @grant        none
// @include        http://*
// @include        https://*
// ==/UserScript==

(function() {
    'use strict';

    var elems = document.getElementsByClassName('top-bar__network');
    elems[0].parentNode.removeChild(elems[0]);
})();
6
  • Thanks for your answer. Should I save this as a chrome extension, something like this?
    – JJJohn
    Commented Sep 23, 2019 at 11:28
  • no. First install TamperMonkey from the link. Then click the TamperMonkey extension icon --> create new script --> paste my code --> save --> done :)
    – Joakim
    Commented Sep 23, 2019 at 11:30
  • Thanks again. When I save the script, load an page, nothing has happened, the element to be deleted is still there. I've uploaded new screen shots
    – JJJohn
    Commented Sep 23, 2019 at 12:18
  • make sure to also copy the first lines of the code I provided, which specifies that the script should run on all websites. In other words, replace all the existing code with all the code I provided. After you get it working, you're free to narrow it down to the specific websites you want it to run on.
    – Joakim
    Commented Sep 23, 2019 at 13:26
  • If I copy & paste all that code, "Invalid" error shows up.
    – JJJohn
    Commented Sep 23, 2019 at 14:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .