开发者

Capturing twitter status timeline updates/infinite scroll updates

开发者 https://www.devze.com 2023-02-02 01:02 出处:网络
I\'m using KRL to inject elements into twitter timeline statuses similar to Jesse Stay\'s TwitterBook.The problem I开发者_如何学JAVA have is that these elements are only associated with statuses that

I'm using KRL to inject elements into twitter timeline statuses similar to Jesse Stay's TwitterBook. The problem I开发者_如何学JAVA have is that these elements are only associated with statuses that are currently visible when the bookmarklet is initiated. If a new status is added through the 'new tweet' updated via Ajax or through status updates via infinite scroll, these new statuses are untouched.

Is there a way to either poll for new statuses or sense a twitter status update event via KRL in order to inject elements only into those newly added statuses?


The example posted at

http://kynetxappaday.wordpress.com/2010/12/25/day-21-modifying-facebook-stream-with-kynetx/

works with the Facebook stream but the concept is the same

  • create setTimeout infinite loop to look for stream items
  • only select stream items not marked as processed
  • process stream items
  • rinse and repeat

Code example from post

ruleset a60x512 {
  meta {
    name "MikeGrace-status-update-translator"
    description <<
      MikeGrace-status-update-translator
    >>
    author "Mike Grace"
    logging on
  }

  global {
    datasource insult:HTML <- "http://www.pangloss.com/seidel/Shaker/index.html?" cachable for 1 second;
  }
  rule find_status_updates_by_mike_grace {
    select when pageview ".*"
    {
      notify("Starting to look for status upates by Mike Grace","");
      emit <|

        // get app object to raise web events
        app = KOBJ.get_application("a60x512");

        // function that finds FB status updates by Mike Grace
        function findMikeGrace() {

          // loop through each stream item on the page that hasn't been processed already by the app
          $K("li[id^=stream_story]:not(li[kfbt])").each(function() {
            var currentStreamItem = this;
            // grab the current stream item posters name
            var name = $K(currentStreamItem).find(".actorName").text();

            // mark the stream item as being processed to reduce future processing times
            $K(currentStreamItem).attr("kfbt","y");

            // is the stream item by the perpetrator?
            if (name == "Michael Grace") {

              // strikethrough the original update
              $K(currentStreamItem).find(".messageBody").wrap("<strike />");

              // get selector to return translation of status update
              var returnSelector = $K(currentStreamItem).attr("id");
              returnSelector = "li#"+returnSelector+" .messageBody";

              // raise web event to get translation for non geeks
              app.raise_event("get_insult", {"returnSelector":returnSelector});

            } // end of checking name

          }); // end of looping through unprocessed stream items

          // call myself again later to process new items on the page
          setTimeout(function() {
            findMikeGrace();
          }, 9000);
        }

        // start the process of finding the perpetrator
        findMikeGrace();
      |>;
    }
  }

  rule get_insult {
    select when web get_insult
    pre {
      selector = event:param("returnSelector");
      insulter = datasource:insult("#{selector}");
      foundInsult = insulter.query("font");
      singleInsult = foundInsult[0];
    }
    {
      emit <|
        console.log(singleInsult);
        $K(selector).parent().after("<br/>"+singleInsult);
      |>;
    }
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号