-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.html
109 lines (95 loc) · 3.52 KB
/
options.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<html>
<head><title>My Test Extension Options</title>
<script type="text/javascript" src="lib/jquery.min.js"></script>
<script type="text/javascript" src="lib/crypto-min.js"></script>
<script type="text/javascript" src="lib/md5-min.js"></script>
<script type="text/javascript" src="lib/main.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#linked").hide();
// delete localStorage['session_key'];
// delete localStorage['s_session'];
// delete localStorage['token'];
// delete localStorage['name'];
if (localStorage['token']) {
var args = {
'method': 'auth.getSession',
'api_key': 'ac5dbe86ac1e96c2d31f8d1d',
'token': localStorage['token']
};
args['api_sig'] = calculateSignature(args,'4c5fbddec6eea1aecedaa2ff');
// Get session with token
$.get('http://like.fm/api/1.0',args,function(data) {
if(data['error']) {
delete localStorage['token'];
}
if (data['session']['name'] && data['session']['key']) {
localStorage['name'] = data['session']['name'];
localStorage['session_key'] = data['session']['key'];
}
},'json');
}
if (localStorage['name'] && localStorage['session_key']) {
$("#username").html('<a href="http://like.fm/' + localStorage['name'] + '">' + localStorage['name'] + '</a>');
$("#linked").show();
if (!localStorage['touch'] || !localStorage['finish'] || !localStorage['s_session'])
LikeFM.handshake();
if (localStorage['token'])
delete localStorage['token'];
// Todo: Check if session is valid
}
});
function link() {
var args = {
method:'auth.getToken',
api_key:'ac5dbe86ac1e96c2d31f8d1d'
}
args['api_sig'] = calculateSignature(args,'4c5fbddec6eea1aecedaa2ff');
if (localStorage['token']) {
window.location = 'http://like.fm/api/auth/?api_key=' + args['api_key'] + '&token=' + localStorage['token'];
} else {
$.get('http://like.fm/api/1.0',args,function(data) {
localStorage['token'] = data['token'];
window.location = 'http://like.fm/api/auth/?api_key=' + args['api_key'] + '&token=' + data['token'];
},'json');
}
}
// Saves options to localStorage.
function save_options() {
// var select = document.getElementById("color");
// var color = select.children[select.selectedIndex].value;
// localStorage["favorite_color"] = color;
//
// // Update status to let user know options were saved.
// var status = document.getElementById("status");
// status.innerHTML = "Options Saved.";
// setTimeout(function() {
// status.innerHTML = "";
// }, 750);
}
// Restores select box state to saved value from localStorage.
function restore_options() {
var favorite = localStorage["favorite_color"];
if (!favorite) {
return;
}
var select = document.getElementById("color");
for (var i = 0; i < select.children.length; i++) {
var child = select.children[i];
if (child.value == favorite) {
child.selected = "true";
break;
}
}
}
</script>
</head>
<body onload="restore_options()">
<div id="linked">This extension is linked to: <span id="username"></span></div>
<div id="unlinked">
<div id="link-notice">Link your account in the window opened and then come back and refresh this page.</div>
<a href="#" onclick="link(); return false;">Link your Like.fm account</a> to this extension.
</div>
<br>
</body>
</html>