Greasy Fork

heiseTickerKommentare11

this is not a good idea 'cos all the article pages of the day must be loaded in background to get this little text...

目前为 2016-12-09 提交的版本。查看 最新版本

// ==UserScript==
// @name             heiseTickerKommentare11
// @version          0.1.1
// @author           _leBluem_
// @description      this is not a good idea 'cos all the article pages of the day must be loaded in background to get this little text...
// @info             but its fun to see ;)
// @grant            none
// @namespace        https://greasyfork.org/de/scripts/25552-heisetickerkommentare10/
// @match            http://www.heise.de/newsticker/*
// @match            https://www.heise.de/newsticker/*
// ==/UserScript==

(function() {
    // add "Kommentare laden" link to date that calls GetComments
    $("h4.published.archiv_woche_published").each(function(){
        var s = '<font size="1">&nbsp;<a href="#" onclick="GetComments(this);return false;">Kommentare laden</a></font>';
        $(this).append(s);
    });

    // find all comments for this day
    window.GetComments = function GetComments(e){
        // <archiv_woche_published><font><a>
        var ulist=$(e).parent().parent().next().children();

        // clear all previous loaded comments
        $('span[id*="plugin-page-"]').each(function(){
            $(this).remove();
        });

        // make a span-tag to hold the comments-tag
        var urls = [];
        var j = 0;
        $(ulist).each(function(){
            if ( $(this).find('a').attr('href') ) {
                urls.push($(this).find('a').attr('href'));
                // #plugin-page-0 .. #plugin-page-1 .. #plugin-page-2 ..
                $(this).append('<font size="1"><span id="plugin-page-' + j++ + '"></span></font>');
            }
        });
        // make the span-tag actually load the comments-tag
        if ( urls.length > 0 ) {
            for (var i = 0; i<= urls.length; i++) {
                // var re = new RegExp(/Kommentare lesen(.*)\(([^)]+)\)/); // does not compute anywhere
                $("#plugin-page-"+i).load(urls[i] + " div.link_forum_beitrag.news p a");
            }
        }
    };
})();