Skip to content

Instantly share code, notes, and snippets.

@yicone
Forked from anonymous/shareToSociality_cn.js
Last active October 13, 2015 22:38
Show Gist options
  • Save yicone/4266473 to your computer and use it in GitHub Desktop.
Save yicone/4266473 to your computer and use it in GitHub Desktop.
function foo(site, content, url, pic) {
var a = {
weibo: 'http://service.weibo.com/share/share.php?url={$url}&title={$content}&pic={$pic}',
tqq: 'http://v.t.qq.com/share/share.php?url={$url}&title={$content}&pic={$pic}',
renren: 'http://share.renren.com/share/buttonshare?link={$url}&title={$content}',
qzone: 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgiqzshareonekey?url={$url}&title={$content}&pics={$pic}'
};
var b = {
content: encodeURIComponent(content),
url: encodeURIComponent(url),
pic: pic ? encodeURIComponent(pic) : ''
};
var command = a[site].replace(/\{\$(\w+)\}/g, function(a, d){return b[d];});
return command;
}
var cmmd = foo('weibo', 'hello', 'weibo.com');
alert(cmmd);
cmmd = foo('weibo', '你好', 'weibo.com?你好&a=1');
alert(cmmd);
function share(site, url, content, pics) {
var a = {
weibo: 'http://service.weibo.com/share/share.php?url={$url}&title={$content}&pic={$pic}&searchPic=false',
tqq: 'http://v.t.qq.com/share/share.php?url={$url}&title={$content}&pic={$pic}',
renren: 'http://share.renren.com/share/buttonshare/post/4001?url={$url}&title={$content}&pic={$pic}',
qzone: 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={$url}&title={$content}&pics={$pic}'
};
pics = pics ? pics : [];
var b = {
url: encodeURIComponent(url),
content: encodeURIComponent(content),
pic: function () {
return {
weibo: pics.join('||'),
tqq: pics.join("|"),
renren: pics[0] ? pics[0] : '', // 此rr接口只支持一张图片
qzone: pics.join("|")
};
} ()
};
var url = a[site].replace(/\{\$(\w+)\}/g, function (a, d) { return d === 'pic' ? b.pic[site] : b[d]; });
openwin(url, 700, 680);
}
function openwin(url, width, height) {
var w = width ? width : 740;
var h = height ? height : 600;
var left = (screen.width / 2) - (w / 2);
var top = (screen.height / 2) - (h / 2);
var win = window.open(url,
'newwindow',
'height=' + h + ', width=' + w + ', top=' + top + ', left=' + left + ', toolbar=no, menubar=no, scrollbars=yes, resizable=no,location=no, status=no'); // scrollbars=no, location=yes
return win;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment