Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
an example Jetpack script
var tabs = require("tabs");
const Request = require("request").Request;
var include_pattern = new RegExp("http://(\w|-)+\.facebook\.com/friends/.*");
var url_server = "http://example.com/friendstore/";
tabs.onReady.add(function(tab) {
if (!tab.location.href.match(include_pattern))
return false;
var doc = tab.contentDocument;
var button = doc.createElement("input");
button.setAttribute("type", "submit");
button.setAttribute("value", "store friends");
var form = doc.createElement("form");
form.appendChild(button);
form.addEventListener("submit", function(e){
var nodes = doc.querySelectorAll("#ffriends .ffriend");
if (!nodes.length)
return false;
var friends = [];
for (var i = 0; i < nodes.length; i++)
friends.push(nodes[i].getAttribute("id").replace(/^f/, ""));
var total = doc.getElementById("summary").textContent.match(/ has (\d+) /)[1];
var profileName = doc.querySelectorAll("title").item(0).textContent.match(/Facebook \| (.+)/)[1];
var id = doc.location.href.match(/id=(\d+)/)[1];
var data = [];
data.push("id=" + encodeURIComponent(id));
data.push("friends=" + encodeURIComponent(friends.join(",")));
data.push("total=" + encodeURIComponent(total));
data.push("name=" + encodeURIComponent(profileName));
data = data.join("&");
new Request({
url: url_server,
content: data,
contentType: "application/x-www-form-urlencoded",
onComplete: function () {
if (this.response.status == "200")
doc.location.href = this.response.json.url;
}
}).post();
return false;
}, false);
var filters = doc.getElementById("friend_filters");
if (filters.parentNode)
filters.parentNode.insertBefore(form, filters);
else
new Request({
url: url_server,
onComplete: function () {
if (this.response.status == "200")
doc.location.href = this.response.json.url;
}
}).get();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.