mirror of
https://github.com/fergalmoran/chrometophone.git
synced 2025-12-22 09:41:51 +00:00
82 lines
2.4 KiB
HTML
82 lines
2.4 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<script type="text/javascript" src="constants.js"></script>
|
|
<script type="text/javascript" src="send_logic.js"></script>
|
|
<script>
|
|
var UIItemProperties = { // options for the button
|
|
disabled: false,
|
|
title: "Opera to Phone",
|
|
icon: "icon_18x18.png",
|
|
popup: {
|
|
href: 'popup.html',
|
|
width: "320px",
|
|
height: "60px"
|
|
}
|
|
}
|
|
var operaBtn = opera.contexts.toolbar.createItem( UIItemProperties ); // create the button
|
|
opera.contexts.toolbar.addItem( operaBtn ); // add button to UI
|
|
|
|
var timoutTimer = null;
|
|
|
|
function onMessage( message ) {
|
|
var currentTab = opera.extension.tabs.getFocused();
|
|
|
|
switch( message.data.action ) {
|
|
case ACTION_START_SEND:
|
|
if( currentTab ) {
|
|
var captureSelection = {
|
|
action: ACTION_CAPTURE_SELECTION
|
|
};
|
|
currentTab.postMessage(captureSelection);
|
|
}
|
|
timeoutTimer = window.setTimeout( function() {
|
|
message.data.action = ACTION_SEND_PAGE;
|
|
onMessage( message );
|
|
}, 1000);
|
|
break;
|
|
case ACTION_SEND_PAGE:
|
|
window.clearTimeout( timeoutTimer ); // Cancel timeout error timer
|
|
var pageData = message.data.data || {};
|
|
if( currentTab ) {
|
|
var data = {
|
|
title: pageData.title || currentTab.title,
|
|
url: pageData.link || currentTab.url,
|
|
sel: pageData.selection || null,
|
|
type: pageData.selection ? 'selection' : 'page'
|
|
};
|
|
sendToPhone( data, function( status ) {
|
|
// Display sendToPhone result in Popup
|
|
opera.extension.broadcastMessage({
|
|
action: status
|
|
});
|
|
} );
|
|
} else {
|
|
opera.extension.broadcastMessage({
|
|
action: STATUS_NO_TAB_ACCESS
|
|
});
|
|
}
|
|
break;
|
|
case ACTION_OPEN_TAB:
|
|
if(message.data.data && message.data.data.url) {
|
|
var tabData = {
|
|
url: message.data.data.url,
|
|
focused: true
|
|
};
|
|
opera.extension.tabs.create( tabData );
|
|
}
|
|
break;
|
|
case ACTION_CLOSE_TAB:
|
|
if( currentTab )
|
|
currentTab.close();
|
|
break;
|
|
}
|
|
}
|
|
|
|
opera.extension.addEventListener( 'message' , onMessage, false );
|
|
</script>
|
|
</head>
|
|
<body>
|
|
</body>
|
|
</html>
|