捕获twitter状态时间线更新/无限滚动更新

时间:2010-12-28 17:53:33

标签: twitter krl

我正在使用KRL将元素注入与Jesse Stay的TwitterBook类似的Twitter时间线状态。我遇到的问题是这些元素只与启动书签时当前可见的状态相关联。如果通过Ajax更新的“新推文”或通过无限滚动状态更新添加新状态,则这些新状态不会受到影响。

是否可以通过KRL轮询新状态或感知Twitter状态更新事件,以便仅将元素注入新添加的状态?

1 个答案:

答案 0 :(得分:3)

示例发布于

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

适用于Facebook流,但概念是相同的

  • 创建setTimeout无限循环以查找流项目
  • 仅选择未标记为已处理的流项目
  • 流程项目
  • 冲洗并重复

来自帖子的代码示例

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);
      |>;
    }
  }
}
相关问题