0

I made custom share buttons and wanna add Pocket count to them.

If you're open this link https://widgets.getpocket.com/v1/button?count=vertical&url=http://google.com in browser, you'll see Pocket button with counter (for ex. URL is google.com).

It's simple html document:

<html><head>
<link rel="stylesheet" type="text/css" href="https://d7x5nblzs94me.cloudfront.net/v1/c/button.css?v=6">
<script type="text/javascript" src="https://d7x5nblzs94me.cloudfront.net/v1/j/shared.js?v=2"></script>
<style type="text/css"></style></head>
<body>

<div class="widget vertical pocket center">
    <a id="btn">
                <!-- 
        Please do not scrape this for the Pocket count. 
        It is not relible for you to use and will likely change. 
        Contact us at api@getpocket.com for an official API. 
        Thanks! 
        -->
        <span><em id="cnt">126775</em><i></i><u></u></span>
                <b></b>
    </a>
</div>

<script type="text/javascript">
var POCKET_DOMAIN = 'getpocket.com';
var iLi = true;

var btnData = {"mode":"viapocketbutton","ct":"b607befed1e75f78567281514cae33db78cbcab9","ctn":"ed82217ee621d17ee56ca091cd836e96149b7921","label":"pocket","count":"vertical","src":"","url":"http:\/\/google.com"};
</script>
<script type="text/javascript" src="https://d7x5nblzs94me.cloudfront.net/v1/j/button.js?v=5"></script>

</body></html>

How to parse this Pocket count (placed on <em id="cnt">...</em>) with jQuery.ajax() or something else (js)?

Platon
  • 495
  • 1
  • 4
  • 11

1 Answers1

0

Forgive me, Im on mobile. You should be able to make a GET request by using jQuery's ´load()´ function.

The function takes a url and callback that, once the request has processed, will return the html from the pocket:

$.load(myURL, function(data){
    var dom = $(data).html()
    var pocket = dom.find('pocket selector')
});

Once you have access to ´dom´, querying for the button and then using ´text()´ to grab it is probably the route Id go!

Morklympious
  • 1,065
  • 8
  • 12
  • You mean this http://api.jquery.com/load/ ? It's jQuery function don't work with cross domain query and get error in console ``XMLHttpRequest cannot load https://widgets.getpocket.com/v1/button?count=vertical&url=http://google.com. The 'Access-Control-Allow-Origin' header contains multiple values ...`` – Platon Sep 25 '15 at 05:18
  • I found this solution for CORS: http://stackoverflow.com/a/17299796/5334651 and write code with http://anyorigin.com service. – Platon Sep 25 '15 at 06:30
  • Wow... If I send answer show this message: ``We are no longer accepting answers from this account.``, btw.. :( – Platon Sep 25 '15 at 06:31