3

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

有没有办法通过 KRL 轮询新状态或感知 twitter 状态更新事件,以便仅将元素注入那些新添加的状态?

4

1 回答 1

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);
      |>;
    }
  }
}
于 2010-12-28T17:58:36.100 回答