【问题标题】:Capturing twitter status timeline updates/infinite scroll updates捕获 twitter 状态时间线更新/无限滚动更新
【发布时间】:2010-12-29 01:59:28
【问题描述】:

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

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

【问题讨论】:

    标签: twitter krl


    【解决方案1】:

    示例发布于

    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);
          |>;
        }
      }
    }
    

    【讨论】:

    • 我认为这将是我需要去的方向。只是想如果我可以拦截 twitter 更新事件,它可能是比无限循环更好的选择。感谢您的帮助!
    • 你能用 watch() 动作做这样的事情吗?
    • watch() 适用于“新推文”,但看起来不适用于无限滚动。我现在将执行 Mike 的建议。谢谢大家!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 1970-01-01
    • 2012-03-13
    • 2016-03-12
    • 2012-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多