Jump to content

User:InvalidOS/ShowComments.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by InvalidOS (talk | contribs) at 14:02, 30 October 2019 (stylesheet import). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
importStylesheet('User:InvalidOS/ShowComments.css');

function filterNone()
{
    return NodeFilter.FILTER_ACCEPT;
}

function getCommentInfo()
{
    var comments = [[]];
    // Fourth argument, which is actually obsolete according to the DOM4 standard, is required in IE 11
    // Thanks stack overflow
    var iterator = document.createNodeIterator(document.getElementById("mw-content-text"), NodeFilter.SHOW_COMMENT, filterNone, false);
    var curNode;
    while (curNode = iterator.nextNode())
    {
        var arrayToPush = [];
        arrayToPush[0] = curNode;
        arrayToPush[1] = curNode.textContent;
        comments.push(arrayToPush);
    }
    return comments;
}

(function renderComments()
{
	var commentInfo = getCommentInfo();
	for (x = 0; x < commentInfo.length; x++)
	{
		commentInfo[x][0].OuterHTML = '<span class="commentDisplay">&lt;!--' + commentInfo[x][1] + '--></span>';
	}
}()
);