Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 534 Vote(s) - 3.36 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Javascript - Search through the HTML of a site and replace it?

#1
Well, just like my title says.
Is it possible to search through a whole page's HTML/CSS, and then replacing certain strings using JavaScript?

I tried to make something on my own but I'm doing it wrong.

var i, sig = document.getElementsByClassName('signaturecontainer');
for (i = 0; i < sig.length; i++)
{
var str = sig[i].innerHTML;
var n = str.replace(/< div style='250px;overflow:scroll;'/g, "< div > style='height:100%'");
}

Why I want to replace the string instead of using .innerHTML and just editing is due to that the div I want to change does not have an ID/Class.

This is what the line(s) I need changed:
><div class="after_content">

<!-- edit note -->
<blockquote class="postcontent lastedited">

Last edited by X; Today at <span class="time">06:32 AM</span>.


</blockquote>
<!-- / edit note -->



<div style="height:250px;overflow: auto;"> // <--- This one.
<blockquote class="signature restore"><div class="signaturecontainer">text here</div></blockquote>
</div>

</div>
Reply

#2
We'll no it is not impossible, with JavaScript you can parse an HTML document by locating the tags is that you are trying to change. For example

<div id="getThisChanged">change this text</div>

By executing this next line of JavaScript, you can change the text inside of the tag

document.getElementById('getThisChanged').innerHTML("text is now changed");

The text will be changed to "text is now changed"
Reply

#3
This line will give trouble:

var new = str.replace(/< div style='250px;overflow:scroll;'/g, "< div > style='height:100%'");

- `new` is a reserved word. Change it to newstr, or whatever.
- Your regex pattern is unlikely to find anything: what it's searching for is not valid CSS
- The string you want to insert is not valid HTML/CSS. It should probably be `<div style='height:100%;'>`

It occurs to me that if you're just tweaking the styling then this is a clumsy way to go. You can change the styling directly with Javascript.

var i, sig = document.getElementsByClassName('signaturecontainer');
for (i = 0; i < sig.length; i++)
{
sig[i].parentNode.style.height = "100%";
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through