Created
April 7, 2010 05:37
-
-
Save bwskyer/358575 to your computer and use it in GitHub Desktop.
同步18个微博客的精简版脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//版本日志: | |
// V0.02 | |
// 2010.05.27 修正Dii的信息同步,同时修正了腾讯微博的同步,利用最新的心情同步到腾讯微博方式, | |
// 请自行到空间个人中心进行设置,同时去掉了以前的滔滔代码。 | |
// V0.01 | |
// 2010.04.07 发布信息时同步包括Twitter,腾讯微博在内的18个微博客。 | |
// 其中嘀咕、做啥、开心网、人人网(校内)、9911、搜狐、新浪、鲜果联播、Plurk是利用的Follow5的5步大同插件。 | |
// 网易邮箱我个人在使用,所以未用F5的工具同步,其他的均由代码完成。 | |
// 具体使用方法和介绍请查看作者博客:http://bwskyer.com | |
const TWEET_MAXLEN = 140; | |
const TWEET_SHORT_URL_MAX_LENGTH = 17; | |
const URL_SHORTENER_API = 'http://knb.im/api.php?url='; | |
var multiServiceUpdater = { | |
registeredServices: [ | |
{ selector: '#WS', method: 'updateWS' }, | |
{ selector: '#163', method: 'update163' }, | |
{ selector: '#QQ', method: 'updateQQ' }, | |
{ selector: '#F5', method: 'updateF5' }, | |
{ selector: '#DII', method: 'updateDii' }, | |
{ selector: '#LEIHOU', method: 'updateLeihou' }, | |
{ selector: '#RENJIAN', method: 'updateRenjian' }, | |
{ selector: '#TWITTER', method: 'updateTwitter' }, | |
{ selector: '#TEST', method: 'updateTest' }, | |
], | |
parseActions: function(finalStatusText) { | |
var actions = []; | |
for (var i = 0; i < this.registeredServices.length; i++) { | |
var service = this.registeredServices[i]; | |
if (!service.selector) continue; | |
if (finalStatusText.indexOf(' ' + service.selector) != -1) { | |
finalStatusText = finalStatusText.replace(new RegExp(' ' + service.selector), ''); | |
actions.push(service.selector); | |
} | |
} | |
if (actions.length == 0) { | |
for (var i = 0; i < this.registeredServices.length; i++) { | |
var service = this.registeredServices[i]; | |
if (!service.selector) continue; | |
if ('#TEST' == service.selector) continue; | |
actions.push(service.selector); | |
} | |
} | |
return { 'status': finalStatusText, 'actions': actions }; | |
}, | |
updateStatus: function(finalStatusText) { | |
var result = this.parseActions(finalStatusText); | |
this.processUpdate(result.status, result.actions); | |
}, | |
processUpdate: function(finalStatusText, actions) { | |
if (actions.length <= 0) return; // no action to be processed | |
var action = actions.shift(); | |
var thisObj = this; | |
var cb = function() { | |
// process the next action | |
thisObj.processUpdate(finalStatusText, actions); | |
}; | |
for (var i = 0; i < this.registeredServices.length; i++) { | |
var service = this.registeredServices[i]; | |
if (!service.selector) continue; | |
if (action == service.selector) { | |
this[service.method](finalStatusText, cb); | |
return; | |
} | |
} | |
displayMessage('Unknown action: ' + action); | |
if (cb) cb(); | |
}, | |
updateTest: function(finalStatusText, cb) { | |
displayMessage("Test service updated: " + finalStatusText); | |
if (cb) cb(); | |
}, | |
updateTwitter: function(finalStatusText, cb) { | |
var updateUrl = "http://yegle.net/api/statuses/update.json"; | |
var updateParams = { | |
source: "ubiquity", | |
status: finalStatusText | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "json", | |
error: function() { | |
displayMessage("[Twitter] Failed to update the status: Not logged in?"); | |
}, | |
success: function() { | |
displayMessage("[Twitter] Status updated: " + finalStatusText); | |
}, | |
complete: function(XMLHttpRequest, textStatus) { | |
if (cb) cb(); | |
}, | |
}); | |
}, | |
updateRenjian: function(finalStatusText, cb) { | |
var updateUrl = "http://api.renjian.com/statuses/update.json"; | |
var updateParams = { | |
source: "bwskyer.com", | |
text: finalStatusText | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "json", | |
error: function() { | |
displayMessage("[Renjian] Failed to update the status: Not logged in?"); | |
}, | |
success: function() { | |
displayMessage("[Renjian] Status updated: " + finalStatusText); | |
}, | |
complete: function(XMLHttpRequest, textStatus) { | |
if (cb) cb(); | |
}, | |
}); | |
}, | |
updateLeihou: function(finalStatusText, cb) { | |
var updateUrl = "http://leihou.com/statuses/update.json"; | |
var updateParams = { | |
source: "ubiquity", | |
status: finalStatusText | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "json", | |
error: function() { | |
displayMessage("[Leihou] Failed to update the status: Not logged in?"); | |
}, | |
success: function() { | |
displayMessage("[Leihou] Status updated: " + finalStatusText); | |
}, | |
complete: function(XMLHttpRequest, textStatus) { | |
if (cb) cb(); | |
}, | |
}); | |
}, | |
updateDii: function(finalStatusText, cb) { | |
var updateUrl = "http://m.dii.cn/wap/pubblog.do"; | |
var updateParams = { | |
content: finalStatusText, | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "html", | |
error: function() { | |
displayMessage("[Dii] Failed to update the status: Not logged in?"); | |
}, | |
success: function(data, textStatus) { | |
displayMessage("[Dii] Status updated: " + finalStatusText); | |
}, | |
complete: function(XMLHttpRequest, textStatus) { | |
if (cb) cb(); | |
}, | |
}); | |
}, | |
updateQQ: function(finalStatusText, cb) { | |
var updateUrl = "http://taotao.qq.com/cgi-bin/emotion_cgi_publish"; | |
var updateParams = { | |
con: finalStatusText, | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "html", | |
error: function() { | |
displayMessage("[QQ] Failed to update the status: Not logged in?"); | |
}, | |
success: function(data, textStatus) { | |
displayMessage("[QQ] Status updated: " + finalStatusText); | |
}, | |
complete: function(XMLHttpRequest, textStatus) { | |
if (cb) cb(); | |
}, | |
}); | |
}, | |
update163: function(finalStatusText, cb) { | |
var updateUrl = "http://t.163.com/statuses/update.do"; | |
var updateParams = { | |
status: finalStatusText, | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "json", | |
error: function() { | |
displayMessage("[163] Failed to update the status: Not logged in?"); | |
}, | |
success: function(data, textStatus) { | |
displayMessage("[163] Status updated: " + finalStatusText); | |
}, | |
complete: function(XMLHttpRequest, textStatus) { | |
if (cb) cb(); | |
}, | |
}); | |
}, | |
updateF5: function(finalStatusText, cb) { | |
var updateUrl = "http://m.follow5.com/mwfm/unote?c=wn¬eToken=" + Math.random(); | |
var updateParams = { | |
noteContent: finalStatusText, | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "html", | |
error: function() { | |
displayMessage("[Follow5] Failed to update the status: Not logged in?"); | |
}, | |
success: function(data, textStatus) { | |
displayMessage("[Follow5] Status updated: " + finalStatusText); | |
}, | |
complete: function(XMLHttpRequest, textStatus) { | |
if (cb) cb(); | |
}, | |
}); | |
}, | |
updateWS: function(finalStatusText, cb) { | |
var updateUrl = "http://woshao.com/dao.php?action=post"; | |
var updateParams = { | |
content: finalStatusText, | |
}; | |
jQuery.ajax({ | |
type: "POST", | |
url: updateUrl, | |
data: updateParams, | |
dataType: "html", | |
error: function() { | |
displayMessage("[WS] Failed to update the status: Not logged in?"); | |
}, | |
success: function(data, textStatus) { | |
displayMessage("[WS] Status updated: " + finalStatusText); | |
}, | |
complete: function(XMLHttpRequest, textStatus) { | |
if (cb) cb(); | |
}, | |
}); | |
}, | |
}; | |
CmdUtils.CreateCommand({ | |
name: ['t', 'twitter', 'tweet'], | |
icon: "http://519it.net/qq/twitter.ico", | |
arguments: [ {role: 'status', nountype: noun_arb_text, label: 'query'} ], | |
homepage: "http://bwskyer.com", | |
description: "Posts to 18个微博客.", | |
help: "You need to log in before using this command to update status services.", | |
preview: function(pblock, args) { | |
var statusText = args.status.text; | |
var result = multiServiceUpdater.parseActions(statusText); | |
var statusLength = result.status.length; | |
var usesUrlShortener = statusText.indexOf('#URL') != -1; | |
if (usesUrlShortener) statusLength += TWEET_SHORT_URL_MAX_LENGTH - 4; | |
var previewData = { | |
status: result.status, | |
chars: TWEET_MAXLEN - statusLength | |
}; | |
var previewTemplate = "Updates your status to: <br /><b>${status}</b><br /><br />Characters remaining: <b>${chars}</b>"; | |
var truncateTemplate = "<br />The last <b>${truncate}</b> characters will be truncated!"; | |
var shortenInstructionText = "<br />To link to the current page, type <b>#URL</b> as part of your tweet."; | |
var urlWillBeShortenedText = "<br />The text <b>#URL</b> will be replaced with an http:/knb.im/ link to the current page."; | |
var actionsTemplate = "<br />The status will be updated on:<b>${services}</b>."; | |
var previewHTML = CmdUtils.renderTemplate(previewTemplate, previewData); | |
if (usesUrlShortener) | |
previewHTML += urlWillBeShortenedText; | |
else | |
previewHTML += shortenInstructionText; | |
if (previewData.chars < 0) { | |
var truncateData = { | |
truncate: 0 - previewData.chars | |
}; | |
previewHTML += CmdUtils.renderTemplate(truncateTemplate, truncateData); | |
} | |
var servicesToBeUpdated = ''; | |
for (var i = 0; i < result.actions.length; i++) { | |
servicesToBeUpdated += ' ' + result.actions[i].substring(1); | |
} | |
previewHTML += CmdUtils.renderTemplate(actionsTemplate, {services: servicesToBeUpdated}); | |
pblock.innerHTML = previewHTML; | |
}, | |
execute: function(args) { | |
var statusText = args.status.text; | |
if(statusText.length < 1) { | |
displayMessage("Twitter requires a status to be entered"); | |
return; | |
} | |
var usesUrlShortener = statusText.indexOf(' #URL') != -1; | |
var thisObj = this; | |
var postUpdate = function( shortURL ) { | |
var finalStatusText = statusText.replace('#URL', shortURL); | |
multiServiceUpdater.updateStatus(finalStatusText); | |
} | |
if (usesUrlShortener) { | |
var urlToShorten = Application.activeWindow.activeTab.document.location.href; | |
jQuery.get( URL_SHORTENER_API + encodeURIComponent(urlToShorten), null, postUpdate); | |
} else { | |
postUpdate(''); | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment