extension.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. button.set_child(icon);
  22. button.connect('button-press-event', _handleClick);
  23. }
  24. // Open GTK Window when the menubar button is clicked.
  25. let window, webView;
  26. function _handleClick() {
  27. if (!window) {
  28. //set window style- in this case TOPLEVEL
  29. window = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL });
  30. //remove window interaction buttons
  31. window.decorated = false;
  32. //set the size of the window
  33. window.set_default_size(350, 550);
  34. //set the border radius of the window
  35. //make the window non resizeable
  36. window.resizable = false;
  37. //open the website
  38. webView = new Webkit.WebView();
  39. //enable scrolling inside the window
  40. // !!! NOT YET IMPLEMENTED !!!
  41. //load the URL and add it to WebView
  42. webView.load_uri('https://chat.openai.com/chat');
  43. window.add(webView);
  44. //window positioning
  45. window.set_position(Gtk.WindowPosition.MOUSE);
  46. //skip showing in the taskbar
  47. window.set_skip_taskbar_hint(true);
  48. //open the window
  49. window.show_all();
  50. //check if the window is open, if yes, close it after clicking the menubar button
  51. } else if (window.get_visible()) {
  52. window.hide();
  53. } else {
  54. window.show_all();
  55. }
  56. }
  57. function enable() {
  58. Main.panel._rightBox.insert_child_at_index(button, 0);
  59. }
  60. function disable() {
  61. Main.panel._rightBox.remove_child(button);
  62. }
  63. function main() {
  64. init();
  65. enable();
  66. }