extension.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const St = imports.gi.St;
  2. const Main = imports.ui.main;
  3. const ExtensionUtils = imports.misc.extensionUtils;
  4. const Me = imports.misc.extensionUtils.getCurrentExtension();
  5. //const Me = ExtensionUtils.getCurrentExtension();
  6. const Webkit = imports.gi.WebKit2;
  7. const Gtk = imports.gi.Gtk;
  8. //new const
  9. const Gio = imports.gi.Gio;
  10. let button;
  11. function init() {
  12. button = new St.Bin({ style_class: 'panel-button',
  13. reactive: true,
  14. can_focus: true,
  15. x_expand: true,
  16. y_expand: false,
  17. track_hover: true });
  18. //set menubar icon
  19. let gicon = Gio.icon_new_for_string(Me.path + "/icons/chatgpt_icon.png");
  20. icon = new St.Icon({ gicon });
  21. //let icon = new St.Icon({ icon_name: 'system-run-symbolic',
  22. //style_class: 'system-status-icon' });
  23. button.set_child(icon);
  24. button.connect('button-press-event', _handleClick);
  25. }
  26. // Open GTK Window when the menubar button is clicked.
  27. let window, webView;
  28. function _handleClick() {
  29. if (!window) {
  30. //set window style- in this case TOPLEVEL
  31. window = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL });
  32. //remove window interaction buttons
  33. window.decorated = false;
  34. //set the size of the window
  35. window.set_default_size(350, 550);
  36. //set the border radius of the window
  37. //make the window non resizeable
  38. window.resizable = false;
  39. //open the website
  40. webView = new Webkit.WebView();
  41. //enable scrolling inside the window
  42. // !!! NOT YET IMPLEMENTED !!!
  43. //load the URL and add it to WebView
  44. webView.load_uri('https://chat.openai.com');
  45. window.add(webView);
  46. //window positioning
  47. window.set_position(Gtk.WindowPosition.MOUSE);
  48. //skip showing in the taskbar
  49. window.set_skip_taskbar_hint(true);
  50. //open the window
  51. window.show_all();
  52. //check if the window is open, if yes, close it after clicking the menubar button
  53. } else if (window.get_visible()) {
  54. window.hide();
  55. } else {
  56. window.show_all();
  57. }
  58. }
  59. function enable() {
  60. Main.panel._rightBox.insert_child_at_index(button, 0);
  61. }
  62. function disable() {
  63. Main.panel._rightBox.remove_child(button);
  64. }
  65. function main() {
  66. init();
  67. enable();
  68. }