I regularly visit a website with a lot of links of the following format:
<a href="SomeURL" title="SomeTitle" id="SomeID">SomeText</a>
Sadly the part SomeText is useless in most cases and I want to replace it with SomeTitle. Therefor I tried my luck with a Greasemonkey-Script (inject Javascript to a webpage). I want to modify all Links on the page.
My goal is this:
<a href="SomeURL" title="SomeTitle" id="SomeID">SomeTitle</a>
I already tried my luck, but since I'm not familiar with javascript this is all I got so far, of course it did not work...
document.links.innerHTML = document.links.title
I hope somebody can help me with this problem. Thanks in advance.
Edit: Thanks for the fast replies, I add a comment to each answer with a feedback, if it solves the problem or not.
Its just strange, that none of these solution have a 100% success-rate. Sometimes I have to reload the page 2-3 times to get the code working. (Not a cache-problem, I swear) I though it maybe have to load the page fully to work, but when I add a timeout before running the code it only works on a few divs and not the entire page. This is just additional information, no further help is needed. Im fine, if I have to reload the page sometimes.
After the document loads:
var theLink = document.getElementById('SomeID');
theLink.innerHTML = theLink.getAttribute('title');
Or in your case all links:
var elements = document.getElementsByTagName('a');
[].forEach.call(elements, function(element) {
element.innerHTML = element.getAttribute('title') || element.innerHTML;
});