Skip to content

Commit

Permalink
fix: avoid using deprecated jQuery functions to prepare for jQuery 4 (#…
Browse files Browse the repository at this point in the history
…779)

- some DOM check functions were rewritten to use native DOM API
- jquery 3 dependency was removed from package.json
- updated some function signatures in type definitions
  • Loading branch information
onestep committed Mar 4, 2024
1 parent 8400b9a commit a9c31ac
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 87 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.idea
node_modules
**/*~
**/.#*
Expand Down
22 changes: 2 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
"gmail chrome extension",
"gmail firefox extension"
],
"dependencies": {
"jquery": "^3.6.1"
},
"devDependencies": {
"@types/jquery": "^3.5.14",
"eslint": "^8.23.1",
"gmail-js": "^1.1.0",
"jest": "^29.5.0",
"jest-junit": "^16.0.0",
"jsdom": "^20.0.0",
Expand Down
27 changes: 15 additions & 12 deletions src/gmail.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ declare type StringDict = {
//
////////////////////////////////////////////////////////////////////////////////

interface GmailTracker {
interface GmailTracker<T extends string = never> {
dom_observers: { [observer in GmailDomObserver | T]?: DomObserverConfig };
globals: any[];
view_data: any[];
ik: string;
hangouts: any;
events: {}[];
actions: {}[];
watchdog: {
before: {},
on: {},
after: {},
dom: {}
before: { [action in GmailBindAction | T]?: Function[] };
on: { [action in GmailBindAction | T]?: Function[] };
after: { [action in GmailBindAction | T]?: Function[] };
dom: { [observer in GmailDomObserver | T]?: Function[] };
};
}

Expand Down Expand Up @@ -671,7 +672,7 @@ interface GmailTools {
observes every element inserted into the DOM by Gmail and looks at the classes on those elements,
checking for any configured observers related to those classes
*/
insertion_observer(target: HTMLElement | string, dom_observers: any, dom_observer_map: any, sub: any): void;
insertion_observer(target: HTMLElement | string, dom_observers: { [observer: string]: DomObserverConfig }, dom_observer_map: { [className: string]: string[] }, sub?: string): void;

make_request(link: string, method: GmailHttpRequestMethod, disable_cache: boolean): string;
make_request_async(link: string, method: GmailHttpRequestMethod, callback: (data: string) => void, disable_cache: boolean): void;
Expand Down Expand Up @@ -764,6 +765,8 @@ declare type GmailBindAction =
| 'new_email' | 'refresh' | 'open_email' | 'upload_attachment' | 'compose'
| 'compose_cancelled' | 'recipient_change' | 'view_thread' | 'view_email'
| 'load_email_menu';
declare type GmailDomObserver =
'view_thread' | 'view_email' | 'load_email_menu' | 'recipient_change' | 'compose'

interface HttpEventRequestParams {
url: object,
Expand All @@ -780,7 +783,7 @@ interface DomObserverConfig {
handler?: Function;
}

interface GmailObserve<T extends string=never> {
interface GmailObserve<T extends string = never> {
/**
After an observer has been bound through gmail.observe.bind() (via a
call to events gmail.observe.before(), gmail.observe.on(), or
Expand All @@ -798,7 +801,7 @@ interface GmailObserve<T extends string=never> {
/**
Bind a specified callback to an array of callbacks against a specified type & action
*/
bind(type: GmailBindType, action: Function, callback: Function): void;
bind(type: GmailBindType, action: GmailBindAction | T, callback: Function): void;

/**
an on event is observed just after gmail sends an xhr request
Expand Down Expand Up @@ -850,11 +853,11 @@ interface GmailObserve<T extends string=never> {
Trigger any specified events bound to the passed type
Returns true or false depending if any events were fired
*/
trigger(type: GmailBindType, events: any, xhr: XMLHttpRequest): boolean;
trigger(type: GmailBindType, events: { [action in GmailBindAction | T]?: any[] }, xhr: XMLHttpRequest): boolean;
/**
Trigger any specified DOM events passing a specified element & optional handler
*/
trigger_dom(observer: any, element: HTMLElement, handler?: Function): void;
trigger_dom(observer: GmailDomObserver | T, element: HTMLElement, handler?: Function): void;

initialize_dom_observers(): void;

Expand All @@ -867,7 +870,7 @@ interface GmailObserve<T extends string=never> {
className / args - for a simple observer, this arg can simply be the class on an inserted DOM element that identifies this event should be
triggered. For a more complicated observer, this can be an object containing properties for each of the supported DOM observer config arguments
*/
register(action: string, args: string | DomObserverConfig): void;
register(action: T, args: string | DomObserverConfig): void;
/**
Observe DOM nodes being inserted. When a node with a class defined in api.tracker.dom_observers is inserted,
trigger the related event and fire off any relevant bound callbacks
Expand Down Expand Up @@ -1038,7 +1041,7 @@ declare class Gmail<T extends string=never> {
These are some of the variables that are tracked and kept in
memory while the rest of the methods are in use.
*/
tracker: GmailTracker;
tracker: GmailTracker<T>;
get: GmailGet;
check: GmailCheck;
/**
Expand Down
Loading

0 comments on commit a9c31ac

Please sign in to comment.