Skip to content

Commit fbd9856

Browse files
KoddrKoddr
Koddr
authored and
Koddr
committed
Bug fixes
1 parent 07a902b commit fbd9856

33 files changed

+518
-821
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Download [goodshare.min.js](https://raw.githubusercontent.com/koddr/goodshare.js
3232
* `linkedin` [LinkedIn](http://linkedin.com)
3333
* `twitter` [Twitter](http://twitter.com)
3434
* `livejournal` [LiveJournal](http://livejournal.com)
35-
* `tumblr` [tumblr](http://tumblr.com)
35+
* `tumblr` [Tumblr](http://tumblr.com)
3636
* `blogger` [Blogger](http://blogger.com)
3737
* `pinterest` [Pinterest](http://pinterest.com)
3838
* `digg` [Digg](http://digg.com)
@@ -108,7 +108,7 @@ Value of `data-counter` attribute, see in this list of supported social networks
108108
* `moimir` [Мой Мир@Mail.Ru](http://my.mail.ru)
109109
* `googleplus` [Google Plus](http://plus.google.ru)
110110
* `linkedin` [LinkedIn](http://linkedin.com)
111-
* `tumblr` [tumblr](http://tumblr.com)
111+
* `tumblr` [Tumblr](http://tumblr.com)
112112
* `pinterest` [Pinterest](http://pinterest.com)
113113
* `reddit` [Reddit](http://reddit.com)
114114
* `stumbleupon` [StumbleUpon](http://www.stumbleupon.com)
@@ -117,6 +117,8 @@ Value of `data-counter` attribute, see in this list of supported social networks
117117
* `buffer` [Buffer](http://buffer.com)
118118
* `xing` [Xing](http://www.xing.com)
119119

120+
**Note:** `Google Plus`, `Surfingbird`, `StumbleUpon`, `Pocket` and `Xing` counters use [Yahoo Query Language](https://developer.yahoo.com/yql) (YQL). It may impose some restrictions on use, associated with limit queries to Yahoo (we try to find another solution for this, if you know — [write issue to us](https://github.com/enjoyiacm/goodshare.js/issues/new)).
121+
120122
### How to get Twitter share counter after API 1.1 changes?
121123

122124
Simple solution for single domain: http://opensharecount.com

dist/goodshare.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
require('whatwg-fetch');
4-
53
var _Vkontakte = require('./providers/Vkontakte');
64

75
var _Facebook = require('./providers/Facebook');

dist/providers/Buffer.js

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,30 @@ var Buffer = function () {
3434
value: function shareWindow() {
3535
var share_url = 'https://buffer.com/add?url=' + this.url + '&text=' + this.title;
3636

37-
document.body.querySelectorAll("[data-social=buffer]").forEach(function (item) {
37+
document.body.querySelectorAll('[data-social=buffer]').forEach(function (item) {
3838
item.addEventListener('click', function (event) {
3939
event.preventDefault();
40-
return window.open(share_url, 'Share window', 'width=400, height=400');
40+
return window.open(share_url, 'Share this', 'width=640,height=480,location=no,toolbar=no,menubar=no');
4141
});
4242
});
4343
}
4444
}, {
4545
key: 'getCounter',
4646
value: function getCounter() {
47-
var count_url = 'https://api.bufferapp.com/1/links/shares.json?url=' + this.url;
47+
var script = document.createElement('script');
48+
var callback = ('cb_' + Math.random()).replace('.', '');
49+
var count_url = 'https://api.bufferapp.com/1/links/shares.json?url=' + this.url + '&callback=' + callback;
4850

49-
fetch(count_url, { method: 'GET', mode: 'cors' }).then(this.checkStatus).then(function (response) {
50-
return response.json();
51-
}).then(function (counter) {
52-
document.body.querySelectorAll("[data-counter=buffer]").forEach(function (item) {
53-
if (counter.shares) {
54-
return item.innerHTML = counter.shares;
55-
} else {
56-
return item.innerHTML = 0;
57-
}
51+
window[callback] = function (counter) {
52+
document.body.querySelectorAll('[data-counter=buffer]').forEach(function (item) {
53+
item.innerHTML = counter.shares ? counter.shares : 0;
5854
});
59-
}).catch(function (error) {
60-
console.log('Request failed!', error);
61-
});
62-
}
63-
}], [{
64-
key: 'checkStatus',
65-
value: function checkStatus(response) {
66-
if (response.status >= 200 && response.status < 300) {
67-
return response;
68-
} else {
69-
var error = new Error(response.statusText);
70-
error.response = response;
71-
throw error;
72-
}
55+
56+
script.parentNode.removeChild(script);
57+
};
58+
59+
script.src = count_url;
60+
document.body.appendChild(script);
7361
}
7462
}]);
7563

dist/providers/Facebook.js

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,42 +34,30 @@ var Facebook = function () {
3434
value: function shareWindow() {
3535
var share_url = 'https://facebook.com/sharer/sharer.php?u=' + this.url + '&t=' + this.title;
3636

37-
document.body.querySelectorAll("[data-social=facebook]").forEach(function (item) {
37+
document.body.querySelectorAll('[data-social=facebook]').forEach(function (item) {
3838
item.addEventListener('click', function (event) {
3939
event.preventDefault();
40-
return window.open(share_url, 'Share window', 'width=400, height=400');
40+
return window.open(share_url, 'Share this', 'width=640,height=480,location=no,toolbar=no,menubar=no');
4141
});
4242
});
4343
}
4444
}, {
4545
key: 'getCounter',
4646
value: function getCounter() {
47-
var count_url = 'https://graph.facebook.com/?id=' + this.url;
47+
var script = document.createElement('script');
48+
var callback = ('cb_' + Math.random()).replace('.', '');
49+
var count_url = 'https://graph.facebook.com/?id=' + this.url + '&callback=' + callback;
4850

49-
fetch(count_url, { method: 'get', mode: 'cors' }).then(this.checkStatus).then(function (response) {
50-
return response.text();
51-
}).then(function (counter) {
52-
document.body.querySelectorAll("[data-counter=facebook]").forEach(function (item) {
53-
if (counter.share) {
54-
return item.innerHTML = counter.share.share_count;
55-
} else {
56-
return item.innerHTML = 0;
57-
}
51+
window[callback] = function (counter) {
52+
document.body.querySelectorAll('[data-counter=facebook]').forEach(function (item) {
53+
item.innerHTML = counter.share ? counter.share.share_count : 0;
5854
});
59-
}).catch(function (error) {
60-
console.log('Request failed!', error);
61-
});
62-
}
63-
}], [{
64-
key: 'checkStatus',
65-
value: function checkStatus(response) {
66-
if (response.status >= 200 && response.status < 300) {
67-
return response;
68-
} else {
69-
var error = new Error(response.statusText);
70-
error.response = response;
71-
throw error;
72-
}
55+
56+
script.parentNode.removeChild(script);
57+
};
58+
59+
script.src = count_url;
60+
document.body.appendChild(script);
7361
}
7462
}]);
7563

dist/providers/GooglePlus.js

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,30 @@ var GooglePlus = function () {
3232
value: function shareWindow() {
3333
var share_url = 'https://plus.google.com/share?url=' + this.url;
3434

35-
document.body.querySelectorAll("[data-social=googleplus]").forEach(function (item) {
35+
document.body.querySelectorAll('[data-social=googleplus]').forEach(function (item) {
3636
item.addEventListener('click', function (event) {
3737
event.preventDefault();
38-
return window.open(share_url, 'Share window', 'width=400, height=400');
38+
return window.open(share_url, 'Share this', 'width=640,height=480,location=no,toolbar=no,menubar=no');
3939
});
4040
});
4141
}
4242
}, {
4343
key: 'getCounter',
4444
value: function getCounter() {
45-
var count_url = 'https://plusone.google.com/_/+1/fastbutton?url=' + this.url;
45+
var script = document.createElement('script');
46+
var callback = ('cb_' + Math.random()).replace('.', '');
47+
var count_url = 'https://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="https://plusone.google.com/_/+1/fastbutton?url=' + this.url + '" and xpath="*"') + '&callback=' + callback;
4648

47-
fetch(count_url, { method: 'GET', mode: 'cors' }).then(this.checkStatus).then(function (response) {
48-
return response.text();
49-
}).then(function (counter) {
50-
document.body.querySelectorAll("[data-counter=googleplus]").forEach(function (item) {
51-
return item.innerHTML = counter.match(/script type="text\/javascript">window.__SSR = \{c: (\d+).0/)[1] / 1;
49+
window[callback] = function (counter) {
50+
document.body.querySelectorAll('[data-counter=googleplus]').forEach(function (item) {
51+
item.innerHTML = counter.results[0].match(/javascript">window.__SSR = \{c: (\d+).0/) != null ? counter.results[0].match(/javascript">window.__SSR = \{c: (\d+).0/)[1] / 1 : 0;
5252
});
53-
}).catch(function (error) {
54-
console.log('Request failed!', error);
55-
});
56-
}
57-
}], [{
58-
key: 'checkStatus',
59-
value: function checkStatus(response) {
60-
if (response.status >= 200 && response.status < 300) {
61-
return response;
62-
} else {
63-
var error = new Error(response.statusText);
64-
error.response = response;
65-
throw error;
66-
}
53+
54+
script.parentNode.removeChild(script);
55+
};
56+
57+
script.src = count_url;
58+
document.body.appendChild(script);
6759
}
6860
}]);
6961

dist/providers/LinkedIn.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var LinkedIn = function () {
2222
function LinkedIn() {
2323
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.location.href;
2424
var title = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.title;
25-
var description = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.head.querySelector("meta[name=description]").content;
25+
var description = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.head.querySelector('meta[name=description]').content;
2626

2727
_classCallCheck(this, LinkedIn);
2828

@@ -36,38 +36,30 @@ var LinkedIn = function () {
3636
value: function shareWindow() {
3737
var share_url = 'http://www.linkedin.com/shareArticle?url=' + this.url + '&text=' + this.title + '&summary=' + this.description + '&mini=true';
3838

39-
document.body.querySelectorAll("[data-social=linkedin]").forEach(function (item) {
39+
document.body.querySelectorAll('[data-social=linkedin]').forEach(function (item) {
4040
item.addEventListener('click', function (event) {
4141
event.preventDefault();
42-
return window.open(share_url, 'Share window', 'width=400, height=400');
42+
return window.open(share_url, 'Share this', 'width=640,height=480,location=no,toolbar=no,menubar=no');
4343
});
4444
});
4545
}
4646
}, {
4747
key: 'getCounter',
4848
value: function getCounter() {
49-
var count_url = 'https://www.linkedin.com/countserv/count/share?url=' + this.url;
49+
var script = document.createElement('script');
50+
var callback = ('cb_' + Math.random()).replace('.', '');
51+
var count_url = 'https://www.linkedin.com/countserv/count/share?url=' + this.url + '&callback=' + callback;
5052

51-
fetch(count_url, { method: 'GET', mode: 'cors' }).then(this.checkStatus).then(function (response) {
52-
return response.text();
53-
}).then(function (counter) {
54-
document.body.querySelectorAll("[data-counter=linkedin]").forEach(function (item) {
55-
return item.innerHTML = counter.count;
53+
window[callback] = function (counter) {
54+
document.body.querySelectorAll('[data-counter=linkedin]').forEach(function (item) {
55+
item.innerHTML = counter.count;
5656
});
57-
}).catch(function (error) {
58-
console.log('Request failed!', error);
59-
});
60-
}
61-
}], [{
62-
key: 'checkStatus',
63-
value: function checkStatus(response) {
64-
if (response.status >= 200 && response.status < 300) {
65-
return response;
66-
} else {
67-
var error = new Error(response.statusText);
68-
error.response = response;
69-
throw error;
70-
}
57+
58+
script.parentNode.removeChild(script);
59+
};
60+
61+
script.src = count_url;
62+
document.body.appendChild(script);
7163
}
7264
}]);
7365

dist/providers/MoiMir.js

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"use strict";
1+
'use strict';
22

33
Object.defineProperty(exports, "__esModule", {
44
value: true
@@ -22,59 +22,47 @@ var MoiMir = function () {
2222
function MoiMir() {
2323
var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.location.href;
2424
var title = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.title;
25-
var description = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.head.querySelector("meta[name=description]").content;
26-
var image = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : document.head.querySelector("link[rel=image_src]").href;
25+
var description = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : document.head.querySelector('meta[name=description]').content;
26+
var image = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : document.head.querySelector('link[rel=image_src]').href;
2727

2828
_classCallCheck(this, MoiMir);
2929

30-
this.url = encodeURIComponent(url);
30+
this.url = url;
3131
this.title = encodeURIComponent(title);
3232
this.description = encodeURIComponent(description);
3333
this.image = encodeURIComponent(image);
3434
}
3535

3636
_createClass(MoiMir, [{
37-
key: "shareWindow",
37+
key: 'shareWindow',
3838
value: function shareWindow() {
39-
var share_url = 'http://connect.mail.ru/share?url=' + this.url + '&title=' + this.title + '&description=' + this.description + '&imageurl=' + this.image;
39+
var share_url = 'http://connect.mail.ru/share?url=' + encodeURIComponent(this.url) + '&title=' + this.title + '&description=' + this.description + '&imageurl=' + this.image;
4040

41-
document.body.querySelectorAll("[data-social=moimir]").forEach(function (item) {
41+
document.body.querySelectorAll('[data-social=moimir]').forEach(function (item) {
4242
item.addEventListener('click', function (event) {
4343
event.preventDefault();
44-
return window.open(share_url, 'Share window', 'width=400, height=400');
44+
return window.open(share_url, 'Share this', 'width=640,height=480,location=no,toolbar=no,menubar=no');
4545
});
4646
});
4747
}
4848
}, {
49-
key: "getCounter",
49+
key: 'getCounter',
5050
value: function getCounter() {
51-
var page_url = this.url;
52-
var count_url = 'https://connect.mail.ru/share_count?url_list=' + page_url;
51+
var script = document.createElement('script');
52+
var this_url = encodeURIComponent(this.url.replace(/^.*?:\/\//, ''));
53+
var callback = ('cb_' + Math.random()).replace('.', '');
54+
var count_url = 'https://appsmail.ru/share/count/' + this_url + '?callback=' + callback;
5355

54-
fetch(count_url, { method: 'GET', mode: 'cors' }).then(this.checkStatus).then(function (response) {
55-
return response.json();
56-
}).then(function (counter) {
57-
document.body.querySelectorAll("[data-counter=moimir]").forEach(function (item) {
58-
for (page_url in counter) {
59-
if (counter.hasOwnProperty(page_url)) {
60-
return item.innerHTML = counter[page_url].shares;
61-
}
62-
}
56+
window[callback] = function (counter) {
57+
document.body.querySelectorAll('[data-counter=moimir]').forEach(function (item) {
58+
item.innerHTML = counter.share_mm;
6359
});
64-
}).catch(function (error) {
65-
console.log('Request failed!', error);
66-
});
67-
}
68-
}], [{
69-
key: "checkStatus",
70-
value: function checkStatus(response) {
71-
if (response.status >= 200 && response.status < 300) {
72-
return response;
73-
} else {
74-
var error = new Error(response.statusText);
75-
error.response = response;
76-
throw error;
77-
}
60+
61+
script.parentNode.removeChild(script);
62+
};
63+
64+
script.src = count_url;
65+
document.body.appendChild(script);
7866
}
7967
}]);
8068

0 commit comments

Comments
 (0)