rlsaj
rlsaj

Reputation: 735

Javascript to grab Javascript (more) comments within <head>

I originally received help in this thread: Javascript to grab Javascript comments within <head>.

Where I wanted to use Greasemonkey/Javascript to grab a comment from within tags.

<html>
    <head>
    <!-- 12036,2011-11-29/11:02 -->
    <title>Products & Services</title>

The answer I received in the thread above grabbed the number "12036" and displayed this as an overlay on my page. Now I want to grab the second part (the date) ie "2011-11-29" and also display this as an overlay.

What do I need to add/change from the following to grab the date?

var commentNode = [].slice.call(document.head.childNodes).filter(function(node) {
        return node.nodeType == 8;
      })[0],
id = commentNode.data.match(/^\s*(\d+)/)[1];

var elem = document`.createElement('div');
elem.id = 'id-display';

elem.appendChild(document.createTextNode(id));

document.body.appendChild(elem);

Upvotes: 0

Views: 54

Answers (1)

Barmar
Barmar

Reputation: 781096

Replace the id = ... line with:

id = commentNode.data.match(/,(.*?)\s/)[1];

Go to regular-expressions.info to learn about regular expressions.

Upvotes: 1

Related Questions