-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.html
93 lines (75 loc) · 3.17 KB
/
popup.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<html>
<head>
<style>
body { background: url('cloud.png') no-repeat; font-family: Arial, Helvetica, sans-serif; min-width: 435px;}
h1 { color: #1797C0; font-size: 18px; font-style: normal; margin: 15px 0 9px 9px; }
label { font-size: 12px; float:left; width:60px; padding-top: 4px; }
input { border:1px solid #999999; padding: 3px; border-radius: 5px; }
.textInput { width: 375px; display:block; margin-bottom: 9px; }
.submit { float: right; color: #FFF; font-weight: bold; width: 64px; border-radius: 15px; -webkit-box-shadow: 0px 1px 7px #1797C0; /*border: 2px solid #BCBCBC;*/ border:2px solid #FFF; background-image: -webkit-gradient(linear, 0% 0%, 0% 90%, from(#EEE), to(#1797C0)); }
.toChatter { font-size: 12px; float: right; margin: 0; text-decoration: none; }
.toChatter:hover { text-decoration: underline; }
a, a:visited, a:hover { color: #000; }
</style>
<script src="connection.js" type="text/javascript"></script>
<script type="text/javascript">
// a popup which gets called and loaded when the user clicks on the browser action icon.
window.onload = chrome.tabs.getSelected(null, function(tab) {
document.getElementById("urlName").value = tab.title;
document.getElementById("url").value = tab.url;
});
</script>
</head>
<body>
<a href="#" class="toChatter" onclick="goToChatter()">Home</a>
<h1>Chatter Linker</h1>
<form action="https://na7.salesforce.com/chatter/handlers" method="POST">
<label>Message</label>
<input type="text" value="posted a new link." id="text" class="textInput" />
<label>Url</label>
<input type="text" id="url" class="textInput" />
<label>Url Title</label>
<input type="text" id="urlName" class="textInput" />
<input type="button" value="Share" class="submit" onclick="sendChatter();"/>
</form>
<div style="clear:both;"> </div>
<script type="text/javascript">
// do the Salesforce.com AJAX API connection
var result = sforce.connection.login(localStorage.username, localStorage.password + localStorage.securityToken);
function sendChatter(){
var linkPost = new sforce.SObject("FeedPost");
linkPost.ParentId = result.userId;
linkPost.Body = document.getElementById("text").value;
linkPost.Title = document.getElementById("urlName").value;
linkPost.LinkURL = document.getElementById("url").value;
linkPost.Type = 'LinkPost';
sforce.connection.create([linkPost], {onSuccess : success, onFailure : alert});
function success(result) {
window.close();
}
}
function getSalesforceHomeUrl() {
return localStorage.url;
}
function isSalesforceUrl(url) {
var salesforce = getSalesforceHomeUrl();
if (url.indexOf(salesforce) != 0)
return false;
return true;
}
// Find an open tab to the salesforce URL or open a tab to that URL
function goToChatter() {
chrome.tabs.getAllInWindow(undefined, function(tabs) {
for (var i = 0, tab; tab = tabs[i]; i++) {
if (tab.url && isSalesforceUrl(tab.url)) {
chrome.tabs.update(tab.id, {selected: true});
return;
}
}
chrome.tabs.create({url: getSalesforceHomeUrl()});
});
chrome.extension.getBackgroundPage().updateTime();
}
</script>
</body>
</html>