0
I’m trying to get permissions from the user when a gmail link is posted on facebook. The goal is to share gmail content on facebook.
//code from facebook
window.fbAsyncInit = function() {
FB.init({
appId : '326350284188834',
xfbml : true,
cookie : true, // enable cookies to allow the server to access the session
status : true, // check login status
version : 'v2.0'
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id))
return
js = d.createElement(s);
js.id = id;
js.src = "sdk.js";
js.async = true;
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
//Get current URL to share in facebook
chrome.tabs.getSelected(null, function(tab) {
//cut permission in gmail
chrome.permissions.request({
permissions: ['tabs'],
origins: ['http://www.google.com/']
}, function(teste) {
chrome.permissions.contains({
permissions: ['tabs'],
origins: ['http://www.google.com/']},
function(result) {
if (result) {
var teste="pede permissão1";
console.log(teste);
} else {
var teste="não pede permissão1";
console.log(teste);
}
});
if (teste=="pede permissão") {
console.log('permissão pedida');
} else {
console.log('permissão não pedida');
document.getElementById('share2').innerHTML = tab.url;
document.getElementById('share2').innerHTML = tab.data;
console.log(tab.data);
document.querySelector("div.fb-share-button").setAttribute("data-href", tab.url);
}
});
});
html:
<!doctype html>
<html>
<head>
<!--<link rel="stylesheet" href="http://s3-ak.buzzfed.com/static/css/webfonts.css?v=1370354313" type="text/css" />-->
<script src="fbbutton.js"></script>
<!-- <script src="settings.js"></script>-->
<!--<script src="sdk.js"></script>-->
<style>
div span, iframe {
height:50px!important;
width:100px!important;
}
</style>
</head>
<body>
<div style="width:160px; height:200px; font: normal 21px/23px 'ProximaNovaSemibold',Helvetica,Arial,sans-serif">
<div id="fb-root"></div>
<form id="share" action="" method="">
<label>
<input type="checkbox" id="share2" name="share" /> <span style="position:relative; top:3px;margin-bottom:20px;c">Quer partilhar no face?</span>
</label>
<div id= "share1"class="fb-share-button" data-href="https://developers.facebook.com/docs/plugins/" data-layout="button" style="width:100px; height:50px;"></div>
</form>
</div>
</body>
</html>
manifest.json
{
"manifest_version": 2,
"name": "teste-gmail",
"description": "This extension will share the contents of your gmail.",
"version": "1.0",
"page_action": {
"default_icon": "icon.png",
"default_title":"Gmail",
"default_popup": "popup.html"
},
"permissions": [
"http://mail.google.com/*",
"http://google.com/",
"http://www.facebook.com/",
"https://mail.google.com/*",
"https://www.facebook.com/",
"https://www.google.com/",
"tabs",
"storage",
"activeTab"
],
"optional_permissions": [ "tabs", "http://mail.google.com/*", "http://google.com/"],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"content_security_policy": "script-src 'self'; object-src 'self'"
}
background js.
chrome.tabs.onUpdated.addListener(function(id, info, tab){
chrome.pageAction.show(tab.id);
chrome.tabs.executeScript(tab.id, {
file: "fbbutton.js"
}, function() {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
}
});
});
And what’s the problem?
– Guilherme Bernal
The code does not ask the user permissions to be posted on facebook the content of each email.
– Marta
@Marta why you are using the snippet to format the code?
– Guilherme Nascimento
Another thing @Marta your code is with several "indentation" flaws and have some that I see you copied, but you "modified" without any need, leaving flaws in the code. Let me ask you a question, have you ever programmed outside this code? Don’t be upset with my comment please.
– Guilherme Nascimento