extension.js 2.3 KB

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