200809271507用Ubiquity快速發佈 Plurk 訊息-改良版

2008/09/28 修改2:

動詞後面可以加-tw, -cn, -en等變更語系為繁體中文、簡體中文與英文。如:plurk loves-cn 動詞變簡體的愛。另外,原來日文用的語系代碼是ja,因此用plurk says-jp 就能發送日文訊息了。

程式請直接點http://220.134.115.15/files/ubq/ubq_jerry.js另存新檔檢視,不再張貼了。


先前的第一版只能用「說」來張貼簡訊,在這個改良版裡加入了指定Qualifier的參數,格式變成:「plurk Qualifier Message」,Qualifier與Message之間以一個空白隔開,若未指定Qualifier則預設為 says。Qualifier只能是Plurk認識的"loves","likes","shares","gives","hates","wants","wishes","has","will","asks","was","feels","thinks","says","is"這幾種。更新方法與第一版相同。

/*
* Copied from http://www.plurk.com/user/fortelin
* sample: plurk loves Plurking test.
*/
CmdUtils.CreateCommand({
  name: "plurk",
  takes: {status: noun_arb_text},
  homepage: "http://theunfocused.net/moz/ubiquity/verbs/",
  author: {name: "Blair McBride", homepage: "http://theunfocused.net/"},
  modifier: {name: "Forte Lin"},
  license: "MPL",
  preview: function(previewBlock, statusText) {
    var previewTemplate = "將要發佈的內容如下:
" +      
                          "${status}

" +
                          " 總字數為: ${chars}";
    var truncateTemplate = "
後面 ${truncate} " +
                           "個字將予以刪除!";
    var previewData = {
      status: statusText.text,
      chars: statusText.text.length
    };
    var previewHTML = CmdUtils.renderTemplate(previewTemplate,
                                                    previewData);
    if(previewData.chars > 140) {
      var truncateData = {
        truncate: previewData.chars - 140
      };
      previewHTML += CmdUtils.renderTemplate(truncateTemplate,
                                                   truncateData);
    }
    previewBlock.innerHTML = previewHTML;
  },
  execute: function(statusText) {
    if(statusText.text.length < 1) {
      displayMessage("Plurk 內容不可空白");
      return;
    }
    var _sQualifier = "says";
    var _sText = statusText.text;
    var _iIndex = _sText.indexOf(" ");
    var found = false;
    if (_iIndex > 0) {
      var _aQualifiers = ["loves","likes","shares","gives","hates","wants",
        "wishes","has","will","asks","was","feels","thinks","says","is"];
      var _sVerb = _sText.substring(0, _iIndex);
      for (var ele in _aQualifiers) {
        if (_sVerb==_aQualifiers[ele]) {
          found = true;
          _sQualifier = _sVerb;
          break;
        }
      }
    }
    if (found) {
      _sText = _sText.substring(_iIndex+1);
    }

    var updateUrl = "http://www.plurk.com/TimeLine/addPlurk";
    var updateParams = {
      uid: 3170067,
      qualifier:_sQualifier,
      lang:"tr_ch",  // en
      content: _sText
    };
    jQuery.ajax({
      type: "POST",
      url: updateUrl,
      data: updateParams,
      dataType: "json",
      error: function() {
        displayMessage("Plurk 發佈錯誤");
      },
      success: function() {
        displayMessage("Plurk 發佈成功");
      }
    });
  }
});

回應
挺不賴地~贊助一下
服務於軟體業的資訊老兵。興趣廣泛,學習力佳,好奇心強。
噗浪/互動式留言板
累積 | 今日
loading......
關鍵字
Re:[使用svchost viewer檢視你電...],By 科技與資訊研究所 於2008-11-11
Re:[【部落格更新】 增加中央氣象局衛星雲圖],By ~平淡生活~ 於2008-11-04
Re:[【部落格更新】 增加中央氣象局衛星雲圖],By ~平淡生活~ 於2008-10-07
Re:[標籤雲-翻譯自wikipedia],By 4664-1946~1964嬰兒潮、Baby Boomers 於2008-07-22
Re:[標籤雲-翻譯自wikipedia],By 4664-1946~1964嬰兒潮、Baby Boomers 於2008-07-22
熱門搜尋書籤
有朋自遠方來~

website counter
台灣部落格列表 PageRank
[此功能已終止服務]
    沒有新回應!





Powered by Xuite