forked from Ryuno-Ki/diaspora-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_share.js
44 lines (40 loc) · 1.63 KB
/
script_share.js
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
// Handler for the share event
navigator.mozSetMessageHandler("activity", function(activity){
if(activity.source.name == "share"){
// obtain the URL from the activity
var urlToShare = activity.source.data.url;
if (window.localStorage.length > 1) {
var div = document.getElementById('previousHandles');
var existingHandlesLabel = document.createElement('p');
existingHandlesLabel.id = 'existing-handles-label';
existingHandlesLabel.setAttribute('data-l10n-id', 'select-id');
div.appendChild(existingHandlesLabel);
// Add handles to a list
var ul = document.createElement('ul');
for (var i = 0; i < window.localStorage.length; i++) {
var handle = window.localStorage.key(i);
var li = document.createElement('li');
var linkToPod = document.createElement('a');
linkToPod.setAttribute('href', getShareUrl(handle, urlToShare));
linkToPod.setAttribute('title', 'Share to my pod!');
linkToPod.appendChild(document.createTextNode(handle));
li.appendChild(linkToPod);
ul.appendChild(li);
}
div.appendChild(ul);
} else if (window.localStorage.length == 1){
//if only one account, share directly to it
var handle = window.localStorage.key(0);
window.location = getShareUrl(handle, urlToShare);
} else{
// If no diaspora* account has been defined.
//TODO: propose for configuration and continue
alert(navigator.mozL10n.get('configuration-required'));
}
}
});
// url to share something
function getShareUrl(handle, content) {
var splitted = handle.split('@');
return 'https://' + splitted[1] + '/bookmarklet?title=&url=' + content;
}