在<head>中抓取Javascript(更多)注释

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

本文关键字:更多 Javascript 注释 head 抓取      更新时间:2023-09-26

我最初在这个线程中收到帮助:Javascript在

中抓取Javascript注释。

我想使用Greasemonkey/Javascript从标签内抓取注释。

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

我在上面的帖子中收到的答案抓取了数字"12036",并将其作为覆盖显示在我的页面上。现在我想抓取第二部分(日期),即"2011-11-29",并将其显示为叠加。

我需要从下面添加/更改什么来获取日期?

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);

id = ...行替换为:

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

进入regular-expressions.info了解正则表达式