单击js在webbrowser控件(C#)中生成链接

时间:2012-01-10 15:54:20

标签: c# javascript

我很擅长编码,并通过做一些技巧来学习。

我想这样做,当我打开特定网页时,它会生成链接,我想在生成链接时自动点击它们。

我可以从webbrowser访问html代码,但我不知道如何使用javascript做任何事情。更少我不太了解js。 有没有人可以帮助我做脚本,自动点击这个JS脚本生成的链接(据我所知,它的“click_action”是我感兴趣的......):

    if (!TeamChrome) {
    TeamChrome = {};
}
TeamChrome.currentMaxFeed = {};
TeamChrome.currentFeeds = {};
TeamChrome.feedFlourishFunction = null;

/*
 * getFeedBody
 * 
 * id - the id of the feed, e.g. 1234
 * el_id - the DOM id of the fed element we are putting this into, e.g. feed_1234
 * image - the url of an image icon to append to the feed item
 * message - the content of the feed item
 * action_text - the text of the action item
 * action_link - the url of the action_item to post an Ajax request to, e.g. services/response
 * prize_image - the image of a prize being awarded, if applicable
 * prize_name - the name of a prize being awarded, if applicable
 * source_type - user or system for creator of content
 * home_page - a boolean value specifying if this is going on the home page feed (and thus if we should show flourishes)
 */
TeamChrome.getFeedBody = function(id, el_id, image, message, action_text, action_link, prize_image, prize_name, source_type, home_page) {
    var feedBody = '';
    if (source_type != 'user' && image != '') {
        if(message.indexOf("just changed their outfit! Do you like it?") != -1){
            feedBody += '<div class="avatarSmallHeadshotChangedWrapper"><div class="avatarSmallHeadshotChangedAvatarFeed">';
            if (image != '') {
                feedBody += '<img src="' + image + '"/></div>';
            } else {
                feedBody += '&nbsp;';
            }
        }else{
            feedBody += '<div class="play_feed_item_image">';
            if (image != '') {
                feedBody += '<img src="' + image + '" width="32" height="32" />';
            } else {
                feedBody += '&nbsp;';
            }
        }
        feedBody += '</div>';
    }

    var flourish_message = message.match(/\[\*flourish_gift:(.+)\*\]/g);
    if (flourish_message) {
        if (bootup_complete && home_page) {
            var callback_arg = flourish_message[0].replace(/\[\*flourish_gift:(.+)\*\]/g, '$1');
            flourishGift(document.getElementById('play_feed'), callback_arg);
        }
        message = message.replace(/\[\*flourish_gift:.+\*\]/g, '');
    }
    var flourish_points = message.match(/\[\*flourish_points_(\d+)\*\]/g);
    if (flourish_points) {
        if (bootup_complete && home_page) {
            var callback_arg = flourish_points[0].replace(/\[\*flourish_points_(\d+)\*\]/g, '$1');
            flourishPoints(null, callback_arg);
        }
        message = message.replace(/\[\*flourish_points_(\d+)\*\]/g, '');
    }

    if(message.indexOf("just changed their outfit! Do you like it?") != -1){
       feedBody += '<div class="play_feed_item_text" id="changedAvatarFeedText" style="padding-left:39px">'+message+'</div>';
    }else{
       feedBody += '<div class="play_feed_item_text">'+message+'</div>';
    }

    if (prize_image != null && prize_image != '' && home_page) {
        feedBody += '<div class="clear"></div>';
        feedBody += '<div class="award_wrapper"><img src="' + prize_image + '" style="float:left" class="award_container" /><div class="award_container_text">' + prize_name + '</div></div>';
    }
    if (source_type == 'user') {
        feedBody += '<div onmouseover="showReportExplain(event, this)" onmouseout="hideReportExplain()" onclick="reportFeedItem(\'' + el_id + '\', ' + id + '); logGameAction(\'report_feed\'); return false;" class="play_feed_item_report">!</div>';
    }
    if (action_text != '') {
        callback = 'null';
        callback_arg = 'null';
        var click_action = '';

        var flourish_points = action_text.match(/\[\*flourish_points_(\d+)\*\]/g);
        if (flourish_points) {
            var callback = 'flourishPoints';
            var callback_arg = flourish_points[0].replace(/\[\*flourish_points_(\d+)\*\]/g, '$1');
            action_text = action_text.replace(/\[\*flourish_points_(\d+)\*\]/g, '');
        }

        var flourish_gift = action_text.match(/\[\*flourish_gift:(.+)\*\]/g);
        if (flourish_gift) {
            var callback = 'flourishGift';
            var callback_arg = flourish_gift[0].replace(/\[\*flourish_gift:(.+)\*\]/g, '$1');
            action_text = action_text.replace(/\[\*flourish_gift:(.+)\*\]/g, '');
        }

        var reload_operation = action_link.match(/\[\*reload_(.+)\*\]/g);
        if (reload_operation) {
            var callback = 'reloadGame';
            var callback_arg = reload_operation[0].replace(/\[\*reload_(.+)\*\]/g, '$1');
            action_link = '';//action_link.replace(/\[\*reload_(.+)\*\]/g, '');
        }

        var singleGiftPopup = action_link.match(/\[\*single_gift(.+)\*\]/g);
        if (singleGiftPopup) {
            var callback = 'singleGiftPopup';
            var callback_arg = singleGiftPopup[0].replace(/\[\*single_gift(.+)\*\]/g, '$1');
            action_link = '';
        }

        var learnMorePopup = action_text.match(/\[\*info(.+)\*\]/g);
        if(learnMorePopup){
            var callback = 'learnMorePopup';
            var callback_arg = learnMorePopup[0].replace(/\[\*info:(.+)\*\]/g, '$1');
            action_link = '';
            action_text = 'Learn More!';
        }
        if(learnMorePopup){
            click_action = 'learnMorePopup(event,\'' + callback_arg + '\'); return false;';
        }else{
            click_action = 'ajaxJump(this, ' + id + ', \'' + escape(action_link) + '\', ' + callback + ', \'' + escape(callback_arg) + '\');';
            var addFriendFeed = false;
            if(message.indexOf("needs friends to help them out") != -1){
                    addFriendFeed = true;
            }
            if(addFriendFeed){
                    click_action += "logGameAction('add_friend_from_Feed');";
            }
            click_action += "return false;";
        }

        if (click_action != '') {
            feedBody += '<div id="play_feed_item_action_' + id + '" class="play_feed_item_action clear"><a href="#" onclick="' + click_action + '">'+action_text+'</a></div>';
        }
        //<a href="#" onclick="loadProfile(this, event, 1008642263); return false;">ahahn4201</a> <img src="http://newdest-qa01.playdom.com:7771/images/playdomcom/ranks/icons12x12/rank6.png" class="rankFeedIcon" height="12" width="12"> needs friends to help them out!


        //var singleGiftPopup = action_link.match(/\[\*single_gift(.+)\*\]/g);

    }

    feedBody += '<div style="clear:both"></div>';
    return feedBody;
};

/*
 * addFeed adds a feed item to a given container
 */
TeamChrome.addFeed = function(container_id, item_class, id, timestamp, image, header, message, action_text, action_link, prize_image, prize_name, source_type, home_page, is_heartbeat) {
    // Return if there is no body to the feed item
    if (message == '') return;

    // Reveal the container if it was previously hidden due to being empty
    $('#'+container_id).css('visibility','visible');

    // Create the feed item skeleton
    var feedDiv = document.createElement('div');
    feedDiv.className = item_class;
    feedDiv.id = item_class + '_' + id;

    // Feeds are initially hidden and graphically revealed when fetched via heartbeat
    if (is_heartbeat) {
        feedDiv.style.display = 'none';
    }

    id = parseInt(id);

    // Construct the actual body of the feed item via getFeedBody
    var feedHTML = '';
    if (header) {
        feedHTML += '<div class="play_feed_item_header">' + header + '</div>';
    }
    feedHTML += TeamChrome.getFeedBody(id, feedDiv.id, image, message, action_text, action_link, prize_image, prize_name, source_type, home_page);
    feedDiv.innerHTML = '<div id="feedContent_' + id + '" class="homeFeedSource_' + source_type + '">' + feedHTML + '</div>';

    // Only show the report inappropriate link for user-generated items
    if (source_type == 'user') {
        feedDiv.onmouseover = function() { showReportIcon(this); };
        feedDiv.onmouseout = function() { hideReportIcon(this); };
    }

    // Add the feed to the container and do a graphical reveal
    if ($('#'+container_id).children().length == 0) {
        $('#'+container_id).append(feedDiv);
    } else {
        $('#'+container_id).children().eq(0).before(feedDiv);
    }
    $('#'+feedDiv.id).slideDown('slow');

    // Mark this feed item as the new maximum timestamp so we don't iterate through stale items
    TeamChrome.currentMaxFeed[container_id] = timestamp;
    if (!TeamChrome.currentFeeds[container_id]) {
        TeamChrome.currentFeeds[container_id] = [];
    }
    TeamChrome.currentFeeds[container_id][TeamChrome.currentFeeds[container_id].length] = id;

    // Retire older feed items so that the DOM doesn't get cluttered with elements
    if (TeamChrome.currentFeeds[container_id].length > 23) {
        var oldFeedID = TeamChrome.currentFeeds[container_id].shift();
        var oldFeed = document.getElementById(item_class + '_' + oldFeedID);
        if (oldFeed) {
            oldFeed.parentNode.removeChild(oldFeed);
        }
    }
};

// There is so much additional work involved in adding feed items, that we treat the
// addPriority action as a simple wrapper to the main function
TeamChrome.addPriorityFeed = function(id, timestamp, image, message, action_text, action_link, prize_image, prize_name, home_page, is_heartbeat) {
    TeamChrome.addFeed('play_priority_feed', 'play_priority_feed_item', id, timestamp, image, null, message, action_text, action_link, prize_image, prize_name, 'system', home_page, is_heartbeat);
    var previousBody = $('#play_priority_feed_item_' + id).html();
    previousBody += '<div onclick="clearPriorityFeedItem(' + id + ')" class="play_feed_item_report">X</div>';
    $('#play_priority_feed_item_' + id).html(previousBody);
    $('#play_priority_feed_item_' + id).mouseover(function() { showReportIcon(this); });
    $('#play_priority_feed_item_' + id).mouseout(function() { hideReportIcon(this); });
};
TeamChrome.updateTeamPoints = function(points) {
    $('.team_points_here').text(points);
};

// Deprecated
TeamChrome.lockChrome = function() {
    $('#play_competition_unlocked').hide(); 
    $('#play_competition_locked').show();   
};

// Deprecated
TeamChrome.unlockChrome = function(popup) {
    $('#play_competition_unlocked').show();
    $('#play_competition_locked').hide();   
    if (popup) {
        showUnlockPopup();
    }
};

TeamChrome.popupCallback = function(x, y, height, width) {
    return function(data) {
        createGenericPopup(data, x, y, height, width);
    };
};
TeamChrome.launchPopup = function(action, params, x, y, width, height) {
    var callback = TeamChrome.popupCallback(x, y, height, width);
    $.ajax({
        type: "POST",
        url: action,
        data: params,
        dataType: 'html',
        success: callback
    });
};
TeamChrome.xRelativeToContent = function(pageX, jQueryObj) {
    var left_pos = pageX - (jQueryObj.width()/2) - $('#play_content').offset().left;
    if (left_pos < 10) {
        left_pos = 10;
    }
    if (left_pos + jQueryObj.width() > $('#play_content').width() - 10) {
        left_pos = $('#play_content').width() - jQueryObj.width() - 10;
    }
    return left_pos;
};
TeamChrome.yRelativeToContent = function(pageY, jQueryObj) {
    var top_pos = pageY - $('#play_content').offset().top;
    if (top_pos < 10) {
        top_pos = 10;
    }
    if (top_pos + jQueryObj.height() > $('#play_content').height() - 10) {
        top_pos = $('#play_content').height() - jQueryObj.height() - 10;
    }
    return top_pos;
}

0 个答案:

没有答案