Valentine's Day single How do I get 12 roses (JavaScript) _javascript skills after I knock out the code?

Source: Internet
Author: User
Tags sendmsg

No more nonsense to say, first show you the effect of the picture:

Summary, this article is to introduce a brush star (inside the Flash) script, used to hang machine brush the stars. In the tanabata is to brush the rose, so it is not the title party, let me take everyone together to brush the stars!

First, send a message

Look at the request and simulate sending yourself

$.post ("Http://ing.cnblogs.com/ajax/ing/Publish",   //Address
 json.stringify ({"Content": Content, "Publicflag": 1}),//parameter, JSON format string
 function (Result) {          //callback
  Console.log ("...)". Send success, then judge whether there are Stars ");
  Result && result. Issuccess && Judgestar (content)
 }, "json");            The returned content is converted to a JS object

Second, judge just sent the news whether there are lucky flash

Still is to look at the picture to speak, follow do

The request address is: Http://ing.cnblogs.com/ajax/ing/GetIngList? inglisttype=all&pageindex=1&pagesize=30&tag=&_=1440087133884

By name Knowable (and indeed so), you can choose the type (my, I respond to, new response, mention me, reply me, whole station), page number, per page quantity. The last one is the timestamp.

We simulate the request:

$.ajax ({
   URL: http://ing.cnblogs.com/ajax/ing/GetIngList?) inglisttype=all&pageindex=1&pagesize=3&tag=&_= "+ (+new Date),
   type:" Get ",
   dataType:" Text ",
   success:function (Result) {
    //processing logic <br>    //window.doc=$ (result); Can look at the console to see what the Ghost
   }
  });

The reason for using dataType: "Text" is because:

The return is a piece of HTML code, using $ (result) in the console can be seen is divided into 3 parts, we need to find just sent part, and to determine whether there is a lucky flash. I only choose to get the first 3 to judge, if there are more than 3 people just with me brush flash, then I can not find ... So you can make a little bit more per page.

This is the code that I find and judge if there are stars:

var Feeddiv = $ (Result)-eq (2);
    var Msgspan = Feeddiv.find ("span:contains (' + msg + ')");
    This is actually not rigorous, especially in the big night to find all of their own ...
    if (Msgspan.length > 0) {
     console.log ("...)". Find the sent Flash, start to judge ");
    else {
     Console.log ("...... ...) Failed to find sent Flash, possibly script error ");
    }
    var id = msgspan.attr ("id"). Match (/body_ (\d+) $/) [1];
    if (Msgspan.next ("Img.ing_icon_lucky"). Length > 0) {
     console.log ("...). Lucky Flash +1 "the Stars");
    else {
     //did not find the stars, it seems bad luck. Then just delete the article!!!
    }

Three, delete just that no star of the "waste" flash

For as long as the Stars (Rose), it is useless to throw away ...

This I also do not send a diagram, directly on the code:

Delete
The Flash function delmsg (ID) {
 console.log ("...)". No stars, delete the Flash, id as "+ ID";
 Return $.post ("Http://ing.cnblogs.com/ajax/ing/del", Json.stringify ({ingid:id}));
}

Iv. Summary

Can get "star", really with face, I brush 6 minutes, brush one afternoon only more than 10.

Now is 12 point 43, I am very disturbed. My company computer hang this script has been brushed, I look at home no way, do not know if tomorrow will be small black house ... Let's go to the park early tomorrow morning.

And do not know is not the browser card owners, and occasionally a few have no stars, it also did not erase ...

Here's the complete code:

function Memeda (input) {var times = 0;
 Shuaxingxing (input);
  function shuaxingxing (content) {sendmsg (content);
  SetInterval (function () {sendmsg (content);
 }, 1000 * 60 * 6 + 100); ///Send Flash message function sendmsg (content) {Console.log ("
  ....................................................................");
  times++;
  Console.log ("Current time:" + new Date (). tolocaletimestring () + "first" + Times + "Send Flash"); Console.log (".......)
  Send Flash "); Return $.post ("Http://ing.cnblogs.com/ajax/ing/Publish", Json.stringify ({"Content": Content, "Publicflag": 1}), function () {}, "JSON"). Done (the function (result) {Console.log .....
    Judge whether there are stars "); Result && result.
 Issuccess && Judgestar (content)}); //Determine if there is a Star function Judgestar (msg) {$.ajax ({url: "Http://ing.cnblogs.com/ajax/ing/GetIngList?) inglisttype=all&pageindex=1&pagesize=3&tag=&_= "+ (+new Date), type:" Get ", DataType:" Text ", suc Cess:function (Result) {VAR feeddiv = $ (Result)-eq (2);
    var Msgspan = Feeddiv.find ("span:contains (' + msg + ')"); if (Msgspan.length > 0) {console.log ("...)".
    Find the sent Flash, start to judge "); else {Console.log (....... ...)
    Failed to find sent Flash, possibly script error ");
    The var id = msgspan.attr ("id"). Match (/body_ (\d+) $/) [1]; if (Msgspan.next ("Img.ing_icon_lucky"). Length > 0) {console.log ("...).
    Lucky Flash +1 "the Stars");
    else {delmsg (ID);
 }
   }
  }); ///Remove Flash function delmsg (ID) {Console.log ("...)".
  No stars, delete the Flash, id as "+ ID";
 Return $.post ("Http://ing.cnblogs.com/ajax/ing/del", Json.stringify ({ingid:id}));
 }
}

Above is the Valentine's Day single How I received 12 bunches of roses after knocking the code, I hope you like it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.