腾讯微博“一键转播”bookmarklet

腾讯微博“一键转播”的js调用起来非常便捷。相比之下,新浪微博用iframe的加载方式就不好办了。
下面的代码稍微修改自腾讯微博“一键转播”官方代码,请注意将
var _appkey = “xxxxxx” || “ooooooo”; //你从腾讯微博开放平台获得的appkey
替换为你自己的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(function() {
     String.prototype.elength = function() {
         return this.replace(/[^\u0000-\u00ff]/g, "aa").length;
     };
     String.prototype.tripurl = function() {
         return this.replace(new RegExp("((news|telnet|nttp|file|http|ftp|https)://){1}(([-A-Za-z0-9]+(\\.[-A-Za-z0-9]+)*(\\.[-A-Za-z]{2,5}))|([0-9]{1,3}(\\.[0-9]{1,3}){3}))(:[0-9]*)?(/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*)*", "gi"), new Array(12).join("aa"));
     };
     if ( !! window.find) {
         HTMLElement.prototype.contains = function(B) {
             return this.compareDocumentPosition(B) - 19 > 0
         }
     };
     var _appkey = "xxxxxx" || "ooooooo"; //你从腾讯微博开放平台获得的appkey
     var _web = {
         "name": document.title || "",
         "href": location.href.replace(/([^\x00-\xff]+)/g,encodeURIComponent("$1")),
         "hash": location.hash,
         "target": "toolbar=0,status=0,resizable=1,width=630,height=530"
     };
     var _pic = function(area) {
         var _imgarr = area.getElementsByTagName("img");
         var _srcarr = [];
         for (var i = 0; i < _imgarr.length; i++) {
             if (_imgarr[i].width < 50 || _imgarr[i].height < 50) {
                 continue;
             }
             _srcarr.push(encodeURIComponent(_imgarr[i].src));
         }
         return _srcarr.join("|");
     };
     var _text = function() {
         var s1 = arguments[0] || "",
         s2 = Array().slice.call(arguments, 1).join(" ").replace(/[\s\n]+/g, " "),
         k = 257 - s1.tripurl().elength();
         var s = s2.slice(0, (k - 4) >> 1);
         if (s2.elength() > k) {
             k = k - 3;
             for (var i = k >> 1; i <= k; i++) {
                 if ((s2.slice(0, i)).tripurl().elength() >= k) {
                     break;
                 }
                 else {
                     s = s2.slice(0, i);
                 }
             }
             s += "...";
         } else {
             s = s2;
         }
         return [s1, s];
     };
     var _u = "http://share.v.t.qq.com/index.php?c=share&#038;a=index&#038;f=q2&#038;url=$url$&#038;appkey=" + _appkey + "&#038;assname=hacklog&#038;title=$title$&#038;pic=$pic$";

var share_area = function() {
             return [document.body];
     } ();
     var current_area = share_area[0];
     window.open(_u.replace("$title$", encodeURIComponent(_text(_web.name,"").join(" "))).replace("$url$", encodeURIComponent(_web.href)).replace("$pic$", _pic(share_area[0])).substr(0, 2048), 'null', _web.target);

} )();

修改成你自己的以后,将代码放到这里点击净化或者压缩,然后复制代码粘贴到书签的URL属性里。注意前面要加一个:

1
javascript:

如图:

更多
No Responses Post a comment

Leave a Reply

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS