Skip to content
This repository

Support Gimme Bar without recipe #85

Merged
merged 4 commits into from about 2 years ago

2 participants

YungSang Yusuke Suzuki
YungSang

#84 に上がっていたサイトが良さそうだったので、
作ってみました。

YungSang

あっ、余計なコードが残ってる。。。
削除します。

YungSang

SNS というよりはスクラップブック色が強く、かつ、後から、Public/Private の切り替え、分類等が出来るので、デフォルトで、未分類の Private 投稿でガンガンアップ出来るようしました。

Yusuke Suzuki

おおお, どうもです. 帰宅したら見てみます!

Yusuke Suzuki Constellation merged commit 9b6bfa1 into from April 24, 2012
Yusuke Suzuki Constellation closed this April 24, 2012
Yusuke Suzuki
Owner

mergeしました! どうもです!

YungSang

ちょっとマイナーですが、スクラップには非常にいいので、ありがとうございます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 161 additions and 0 deletions. Show diff stats Hide diff stats

  1. 161  src/lib/models.js
161  src/lib/models.js
@@ -3520,6 +3520,167 @@ Models.register({
3520 3520
   }
3521 3521
 });
3522 3522
 
  3523
+Models.register({
  3524
+  name      : 'GimmeBar',
  3525
+  ICON      : 'https://gimmebar.com/img/favicon.png',
  3526
+  LINK      : 'https://gimmebar.com/',
  3527
+  LOGIN_URL : 'https://gimmebar.com/login',
  3528
+
  3529
+  INIT_URL    : 'https://gimmebar.com/ajax/bookmarklet_data',
  3530
+  POST_URL    : 'https://gimmebar.com/bookmarklet/capture',
  3531
+  CHECK_URL   : 'https://gimmebar.com/ajax/content_url',
  3532
+  UPLOAD_URL  : 'https://gimmebar.com/bookmarklet/upload',
  3533
+  DESC_URL    : 'https://gimmebar.com/site-api-1/asset/',
  3534
+  TWITTER_API : 'http://api.twitter.com/1/statuses/show.json',
  3535
+
  3536
+  check : function(ps) {
  3537
+    return /photo|quote|link|video/.test(ps.type);
  3538
+  },
  3539
+
  3540
+  getCSRFToken : function() {
  3541
+    var self = this;
  3542
+    return request(this.INIT_URL).addCallback(function(res) {
  3543
+      if (res.responseText) {
  3544
+        var data = MochiKit.Base.evalJSON(res.responseText);
  3545
+        return data.csrf_token;
  3546
+      }
  3547
+      else {
  3548
+        throw new Error(chrome.i18n.getMessage('error_notLoggedin', self.name));
  3549
+      }
  3550
+    });
  3551
+  },
  3552
+
  3553
+  post : function(ps) {
  3554
+    var self = this;
  3555
+
  3556
+    var sendContent = {
  3557
+      source   : ps.pageUrl,
  3558
+      title    : ps.item || ps.page,
  3559
+      private  : 1,
  3560
+      use_prev : 0
  3561
+    };
  3562
+
  3563
+    if (ps.description) {
  3564
+      sendContent.description = ps.description;
  3565
+    }
  3566
+
  3567
+    switch (ps.type) {
  3568
+    case 'photo':
  3569
+      if (ps.file) {
  3570
+        return this.upload(ps);
  3571
+      }
  3572
+      else {
  3573
+        sendContent.url = ps.itemUrl;
  3574
+      }
  3575
+      break;
  3576
+    case 'quote':
  3577
+      var regex = ps.pageUrl.match(/\/\/twitter\.com\/.*?\/(?:status|statuses)\/(\d+)/);
  3578
+      if (regex) {
  3579
+        return this.post_twitter(ps, regex[1], sendContent);
  3580
+      }
  3581
+      sendContent.text = ps.body;
  3582
+      break;
  3583
+    case 'link':
  3584
+      var regex = ps.pageUrl.match(/\/\/twitter\.com\/.*?\/(?:status|statuses)\/(\d+)/);
  3585
+      if (regex) {
  3586
+        return this.post_twitter(ps, regex[1], sendContent);
  3587
+      }
  3588
+      sendContent.url = ps.itemUrl;
  3589
+      break;
  3590
+    case 'video':
  3591
+      return this.post_video(ps, sendContent);
  3592
+    }
  3593
+
  3594
+    return this.getCSRFToken().addCallback(function(csrftoken) {
  3595
+      sendContent._csrf_token = csrftoken;
  3596
+      return request(self.POST_URL, {
  3597
+        sendContent : sendContent
  3598
+      });
  3599
+    });
  3600
+  },
  3601
+
  3602
+  post_twitter : function(ps, id, sendContent) {
  3603
+    var self = this;
  3604
+    return request(this.TWITTER_API + '?' + queryString({
  3605
+      id                  : id,
  3606
+      contributor_details : 'true'
  3607
+    })).addCallback(function(res) {
  3608
+      if (res.responseText) {
  3609
+        var data = MochiKit.Base.evalJSON(res.responseText);
  3610
+        var sitesense = {
  3611
+          minURL  : 'http://twitter.com',
  3612
+          data    : data,
  3613
+          private : 'null',
  3614
+          url     : ps.pageUrl,
  3615
+          type    : 'status'
  3616
+        };
  3617
+        sendContent.sitesense = JSON.stringify(sitesense);
  3618
+        return self.getCSRFToken().addCallback(function(csrftoken) {
  3619
+          sendContent._csrf_token = csrftoken;
  3620
+          return request(self.POST_URL, {
  3621
+            sendContent : sendContent
  3622
+          });
  3623
+        });
  3624
+      }
  3625
+    });
  3626
+  },
  3627
+
  3628
+  post_video : function(ps, sendContent) {
  3629
+    var self = this;
  3630
+    return request(this.CHECK_URL + '?' + queryString({
  3631
+      check : ps.itemUrl || ps.pageUrl
  3632
+    })).addCallback(function(res) {
  3633
+      if (res.responseText) {
  3634
+        var data = MochiKit.Base.evalJSON(res.responseText);
  3635
+        sendContent.assimilator = JSON.stringify(data[0]);
  3636
+        return self.getCSRFToken().addCallback(function(csrftoken) {
  3637
+          sendContent._csrf_token = csrftoken;
  3638
+          return request(self.POST_URL, {
  3639
+            sendContent : sendContent
  3640
+          });
  3641
+        });
  3642
+      }
  3643
+    });
  3644
+  },
  3645
+
  3646
+  upload : function(ps) {
  3647
+    var self = this;
  3648
+
  3649
+    var description = joinText([
  3650
+      ps.description,
  3651
+      (ps.body) ? '“' + ps.body + '”' : '',
  3652
+      '(via ' + ps.pageUrl + ' )'
  3653
+    ], "\n", true);
  3654
+
  3655
+    return self.getCSRFToken().addCallback(function(csrftoken) {
  3656
+      return request(self.UPLOAD_URL, {
  3657
+        mode        : 'raw',
  3658
+        sendContent : ps.file,
  3659
+        headers : {
  3660
+          'Content-Type'     : ps.file.type || 'image/png',
  3661
+          'X-CSRF-Token'     : csrftoken,
  3662
+          'X-Filename'       : ps.item || ps.page,
  3663
+          'X-Privacy'        : 1,
  3664
+          'X-Requested-With' : 'XMLHttpRequest'
  3665
+        }
  3666
+      }).addCallback(function(res) {
  3667
+        if (res.responseText) {
  3668
+          var data = MochiKit.Base.evalJSON(res.responseText);
  3669
+          return request(self.DESC_URL + data.id, {
  3670
+            sendContent : {
  3671
+              description : description,
  3672
+              _csrf       : csrftoken
  3673
+            },
  3674
+            headers : {
  3675
+              'X-Requested-With' : 'XMLHttpRequest'
  3676
+            }
  3677
+          });
  3678
+        }
  3679
+      });
  3680
+    });
  3681
+  }
  3682
+});
  3683
+
3523 3684
 function shortenUrls(text, model){
3524 3685
   var reUrl = /https?[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#\^]+/g;
3525 3686
   if(!reUrl.test(text))
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.