extension.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. //enable scrolling inside the window
  40. scrolled_window = new Gtk.ScrolledWindow();
  41. //open the website
  42. webView = new Webkit.WebView();
  43. scrolled_window.add(webView);
  44. //load the URL and add it to WebView
  45. webView.load_uri('https://chat.openai.com/chat');
  46. window.add(scrolled_window);
  47. //window positioning
  48. window.set_position(Gtk.WindowPosition.MOUSE);
  49. //skip showing in the taskbar
  50. window.set_skip_taskbar_hint(true);
  51. //open the window
  52. window.show_all();
  53. //check if the window is open, if yes, close it after clicking the menubar button
  54. } else if (window.get_visible()) {
  55. window.hide();
  56. } else {
  57. window.show_all();
  58. }
  59. }
  60. function enable() {
  61. Main.panel._rightBox.insert_child_at_index(button, 0);
  62. }
  63. function disable() {
  64. Main.panel._rightBox.remove_child(button);
  65. }
  66. function main() {
  67. init();
  68. enable();
  69. }