用Ubiquity快速發佈Plurk訊息-用%l替換網址

image 經常在看到想要分享到Plurk的網頁時,為了複製網址和說明文字而必須操作好幾次,乾脆再修改這個Ubiquity指令,在文字裡用 %l %link 替換當前網頁的網址。命令原始碼如下,訂閱方法請查看下方的相關主題。 範例:plurk shares-cn => %l (The 150 Best Online Flash Games)

  • 原始碼:
  1. /*
  2. * Original author: http://theunfocused.net/moz/ubiquity/verbs/, Blair McBride
  3. * Copied from http://www.plurk.com/user/fortelin
  4. * sample: plurk loves Plurking test.
  5. * plurk loves-cn This is a link %l (Test page).
  6. */
  7. CmdUtils.CreateCommand({
  8. name: "plurk",
  9. takes: {status: noun_arb_text},
  10. homepage: "http://theunfocused.net/moz/ubiquity/verbs/",
  11. author: {name: "Blair McBride", homepage: "http://theunfocused.net/"},
  12. modifier: {name: "Jerry Chien"},
  13. license: "MPL",
  14. preview: function(previewBlock, statusText) {
  15. var previewTemplate = "將要發佈的內容如下: " +
  16. "${status} " +
  17. " 總字數為: ${chars}";
  18. var truncateTemplate = " 後面 ${truncate} " +
  19. "個字將予以刪除!";
  20. var previewData = {
  21. status: statusText.text,
  22. chars: statusText.text.length
  23. };
  24. var previewHTML = CmdUtils.renderTemplate(previewTemplate,
  25. previewData);
  26. if(previewData.chars > 140) {
  27. var truncateData = {
  28. truncate: previewData.chars - 140
  29. };
  30. previewHTML += CmdUtils.renderTemplate(truncateTemplate,
  31. truncateData);
  32. }
  33. previewBlock.innerHTML = previewHTML;
  34. },
  35. execute: function(statusText) {
  36. if(statusText.text.length < 1) {
  37. displayMessage("Plurk 內容不可空白");
  38. return;
  39. }
  40. var _sQualifier = "says";
  41. var _sLang = "tr_ch"; // 預設為繁體中文
  42. var _sText = statusText.text;
  43. var _iIndex = _sText.indexOf(" ");
  44. var found = false;
  45. if (_iIndex > 0) {
  46. var _aQualifiers = ["loves","likes","shares","gives","hates","wants",
  47. "wishes","has","will","wonders","asks","was","feels","thinks","says","is"];
  48. var _sVerb = _sText.substring(0, _iIndex); // 要使用的qualifier
  49. var _iIndex2 = _sVerb.indexOf("-"); // loves, loves-tw, loves-cn, loves-en, 減號後面加語系
  50. if (_iIndex2 > 0) {
  51. var _sVerbLang = _sVerb.substring(_iIndex2+1).toLowerCase();
  52. if (_sVerbLang=="tw") _sLang = "tr_ch";
  53. else _sLang = _sVerbLang;
  54. _sVerb = _sVerb.substring(0, _iIndex2); // loves-cn ==> loves
  55. }
  56. for (var ele in _aQualifiers) {
  57. if (_sVerb==_aQualifiers[ele]) {
  58. found = true;
  59. _sQualifier = _sVerb;
  60. _sText = _sText.substring(_iIndex+1);
  61. break;
  62. }
  63. }
  64. }
  65. // 自動替換目前頁面的網址之處理
  66. var _aKeywords = ["%l", "%link", "%url"]; // 可使用的3種關鍵字串
  67. var _sKeyword = "";
  68. for (var i in _aKeywords) {
  69. _iIndex = _sText.indexOf(_aKeywords[i]);
  70. if (_iIndex >= 0) {
  71. _sKeyword = _aKeywords[i];
  72. break;
  73. }
  74. }
  75. if (_sKeyword != "") {
  76. var _sURL = context.focusedWindow.location.href;
  77. _sText = _sText.replace(_sKeyword, _sURL); // 關鍵字串換成網址
  78. }
  79. var updateUrl = "http://www.plurk.com/TimeLine/addPlurk";
  80. var updateParams = {
  81. uid: 3170067,
  82. qualifier:_sQualifier,
  83. lang:_sLang, // en
  84. content: _sText
  85. };
  86. jQuery.ajax({
  87. type: "POST",
  88. url: updateUrl,
  89. data: updateParams,
  90. dataType: "json",
  91. error: function() {
  92. displayMessage("Plurk 發佈錯誤");
  93. },
  94. success: function() {
  95. displayMessage("Plurk 發佈成?/span>");
  96. }
  97. });
  98. }
  99. });

您可能也會有興趣的類似文章

簡睿

服務於軟體業的資訊老兵。興趣廣泛,學習力佳,樂於分享所知所學。

您可能也會喜歡…

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *