Greasemonkey: Change text on web page?

I used the function:

document.getElementsByTagName('strong')

to get all the text on the page with this type of formatting. HTML looks like this:

<td align="center" valign="bottom"><H1><font size="+4"><strong>TEXT_HERE</strong></font> <br>

I would like to change "TEXT_HERE", perhaps something else, or delete it all together. How can i do this?

Thanks in advance for your help :)

+3
source share
3 answers

With a for loop?

var strongElems = document.getElementsByTagName('strong');
var wantToHide  = true || false;

for (var i=0; i<strongElems.length; i++)
{
  var thisElem = strongElems[i];
  if (wantToHide)
  {
    thisElem.style.display = "none"; // hide it
  }
  else
  {
    thisElem.textContent = "something else"; // change it
  }
}
+7
source
// ==UserScript==
// @name           MyScript
// @namespace      http://example.com
// @description    Example
// @include        *
//
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js
// ==/UserScript==

var shouldHide = false;

$('strong').each(function() {
  if(shouldHide) {
    $(this).hide();
  } else {
    $(this).text("New Text");
  }
});
+1
source

- -, Greasemonkey DumbQuotes. , :

replacements = {
  "old": "new",
  "foo": "bar",
};

, Tomalak. , .

0

All Articles