-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
104 lines (84 loc) · 3.28 KB
/
extension.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
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
// (function(){
console.log('Start loading the extension');
var pebblepresenter_io = window.pebblepresenter_io;
var pebblePresenter = {
init: function(){
// Initialize the socket connection
pebblePresenter.data = {
page_url: document.URL,
pebble_auth: null,
debug: true
}
if( pebblePresenter.data.debug ) {
var s = document.createElement('ul');
s.id = 'PP_debugmsg';
s.style.cssText="border: 1px solid #000; background: #eee; width: 300px; word-wrap: break-word; position: fixed; top: 0px; right: 0px; z-index: 1000000000; max-height: 100px; overflow-y: scroll; opacity: 0.5;";
s.innerHTML = 'Debug Log';
document.documentElement.appendChild(s);
}
var s = document.createElement('div');
s.id = 'PP_mainContain';
s.style.cssText="background: #29333f; position: fixed; bottom: 0px; right: 0px; z-index: 1000000000; color: #fff !important; padding: 10px 25px; font-family: arial; text-decoration: none;";
s.innerHTML = '<a href="#" id="connectToPebbleSocket" onclick="pebblePresenter.connect()" style="color: #fff">+ Present</a>';
document.documentElement.appendChild(s);
},
connect: function( ) {
document.getElementById('PP_mainContain').innerHTML = 'Loading...';
if( typeof jQuery == 'undefined') {
var s = document.createElement('script');
s.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js";
s.onload = function() {
this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);
}
var socket = pebblepresenter_io.connect('http://pebblepresenter.syvarth.com');
pebblePresenter.socket = socket;
socket.emit('registerPresentation', pebblePresenter.data);
socket.on('presentationInfo', function(data){
pebblePresenter.log(data);
pebblePresenter.renderBox(data);
pebblePresenter.bindEvents();
});
socket.on('changeSlide', function(data){
pebblePresenter.log(data);
if(data.direction=='next'){
player.playerViewModel.next();
} else if( data.direction=='back'){
player.playerViewModel.back();
}
});
},
renderBox: function( data ) {
console.log( data );
jQuery('#PP_mainContain')
.html('<h3>Configure Presentation</h3>')
.css({'width':300,'height':200});
if( data.pebble_id ) {
jQuery('#PP_mainContain').append('<div><span style="color: rgb(116,166,55)">Connected</span> to Pebble id '+data.pebble_id+'</div><br />');
}
jQuery('#PP_mainContain')
.append('<div>Auth Code <input type="text" id="PP_authKey" /></div>')
.append('<div><input type="button" value="Save" id="PP_saveSettings" /><span id="PP_saveResponse"></span></div>');
},
bindEvents: function() {
jQuery(document).on('click','#PP_saveSettings',function(e){
console.log('Clicked');
e.preventDefault();
pebblePresenter.saveSettings();
});
},
saveSettings: function() {
var auth_id = jQuery('#PP_authKey').val();
pebblePresenter.socket.emit('updatePresentation', {pebble_auth: auth_id, page_url: pebblePresenter.data.page_url});
},
log: function( data ) {
if( pebblePresenter.data.debug ) {
var elem = document.getElementById('PP_debugmsg');
elem.innerHTML = '<li>'+JSON.stringify(data)+'</li>' + elem.innerHTML;
}
console.log(data);
}
};
pebblePresenter.init();
// });