diff --git a/CHANGELOG.md b/CHANGELOG.md index ec3b2a08..fe4ff34c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,29 @@ # Changelog +## Version 2.0.0 - To be released + +Major breaking changes. Removed lots of no longer working functions, +or long ago obsoleted functions or unsupported ways of using Gmail.js. + +High level change in functionality: + +- Using Gmail.js without node/bundling and js "modules" is no longer supported. +- Long obsoleted non-async API-calls where async alternatives exist are now + removed. +- No longer working or fixable API-calls have been removed. + +Functions removed includes: + +- `api.version` +- `api.get.loggedin_accounts()` +- `api.get.delegated_to_email()` +- `api.get.manager_email()` +- `api.helper.get.is_delegated_inbox()` + +This release may hurt a little, but hopefully it should improve the health of +Gmail.js in the long run. + ## Version 1.0.18 - Fix parsing of attachments in emails form embedded JSON. Thanks @onestep! diff --git a/README.md b/README.md index 0177ab6e..3dc19aa7 100755 --- a/README.md +++ b/README.md @@ -44,38 +44,22 @@ For a ready to use example/boilerplate repo, look no further: - **[GmailJS Node Boilerplate](https://github.com/josteink/gmailjs-node-boilerplate)** - Example for how to create a browser-extension using GmailJS and modern javascript with NodeJS and script-bundling for instant load-times. -### Content Security Policy (legacy advice) +## Usage -In earlier advice given w.r.t. deployment of GmailJS, where scripts were injected one by -one, with cumbersome loading and probing mechanisms, CSP could be an -problem causing your extension to fail if GmailJS was injected incorrectly. - -If you use modern javascript and script-bundling in your extension (like in the boilerplate example), CSP will not interfere with loading -of your extension, nor GmailJS. - -If you have any issues with CSP, the general advice is to build your extension using script-bundling and eliminate the cause of the error -all together. - -While you may be able to make it work, legacy loading is no longer considered supported by GmailJS. - -## Typescript - -Using gmail-js with TypeScript is relatively easy, but if you use normal `import` syntax it -will fail. Instead you need to use `require`-syntax to load it: +Using gmail-js works as normal node-module and you just `import` it into your script: ````typescript -const GmailFactory = require("gmail-js"); -const gmail = new GmailFactory.Gmail() as Gmail; -// working on the gmail-object now provides type-safety. -```` - -You will also have to import the types somewhere, like in a file called `types.d.ts` in your project: +import { Gmail } from "gmail-js"; -````typescript -import "gmail-js"; +const gmail = new Gmail(); +// for typescript, working on the gmail-object automatically provides type-safety. ```` +### Notes on Typescript support +If you want to use gmail-js with TypeScript, you will probably also need to import +additional types in the above import-statement. Don't worry about it, and let your IDE +of choice guide you wrt which types are needed and should be imported :) ## Methods @@ -85,7 +69,6 @@ import "gmail-js"; - [gmail.get**.user_email()**](#gmailgetuser_email) -- [gmail.get**.manager_email()**](#gmailgetmanager_email) - [gmail.get**.current_page()**](#gmailgetcurrent_page) - [gmail.get**.new.email_id()**](#gmailnewgetemail_id) @@ -108,7 +91,6 @@ import "gmail-js"; - [gmail.get**.unread_social_emails()**](#gmailgetunread_emails) - [gmail.get**.last_active()**](#gmailgetlast_active) - [gmail.get**.storage_info()**](#gmailgetstorage_info) -- [gmail.get**.loggedin_accounts()**](#gmailgetloggedin_accounts) - [gmail.get**.beta()**](#gmailgetbeta) - [gmail.get**.localization()**](#gmailgetlocalization) @@ -466,22 +448,6 @@ Returns the current user's email address "california@gmail.com" ``` -#### gmail.get.manager_email() - -Returns the email address of the user currently managing the account (if the inbox is used by the owner, this function returns the same value as [gmail.get**.user_email()**](#gmailgetuser_email)) - -```js -"california@gmail.com" -``` - -#### gmail.get.delegated_to_email() - -Returns the email address of the user the account is currently delegated to (if the inbox is used by the owner, this function returns null) - -```js -"california@gmail.com" -``` - #### gmail.get.storage_info() Returns current user's file storage stats @@ -573,14 +539,6 @@ Gets user's account activity data } ``` -#### gmail.get.loggedin_accounts() - -Returns a list of signed-in accounts (multiple user accounts setup in gmail) - -```json -[{"name":"California","email":"california@gmail.com"}] -``` - #### gmail.get.beta() Although hand picked, this method returns the checks on beta features and deployments diff --git a/src/gmail.d.ts b/src/gmail.d.ts index 5d551ff7..dc953686 100644 --- a/src/gmail.d.ts +++ b/src/gmail.d.ts @@ -124,28 +124,10 @@ interface GmailGet { */ last_active(): GmailLastActive; - /** - Returns a list of signed-in accounts (multiple user accounts - setup in gmail) - */ - loggedin_accounts(): GmailLoggedInAccount[]; - /** Returns the current user's email address */ user_email(): string; - /** - Returns the email address of the user currently managing the - account (if the inbox is used by the owner, this function - returns the same value as gmail.get.user_email()) - */ - manager_email(): string; - /** - Returns the email address of the user the account is currently - delegated to (if the inbox is used by the owner, this function - returns null) - */ - delegated_to_email(): string; /** Returns the Gmail localization, e.g. 'US'. */ @@ -1008,8 +990,8 @@ interface GmailCache { // //////////////////////////////////////////////////////////////////////////////// -declare class Gmail { - constructor(localJQuery?: JQueryStatic); +export class Gmail { + constructor(); version: string; /** diff --git a/src/gmail.js b/src/gmail.js index 426b0f33..c59e165d 100644 --- a/src/gmail.js +++ b/src/gmail.js @@ -6,28 +6,10 @@ /*eslint-env es6*/ -var Gmail = function(localJQuery) { +import $ from "jquery"; - /* - Use the provided "jQuery" if possible, in order to avoid conflicts with - other extensions that use $ for other purposes. - */ - var $; - if (typeof localJQuery !== "undefined") { - $ = localJQuery; - } else if (typeof jQuery !== "undefined") { - $ = jQuery; - } else { - // try load jQuery through node. - try { - $ = require("jquery"); - } - catch(err) { - // else leave $ undefined, which may be fine for some purposes. - } - } - - var window_opener = typeof (window) !== "undefined" ? window.opener : null; +export function Gmail() { + let window_opener = typeof (window) !== "undefined" ? window.opener : null; if (window_opener) { try { // access to window.opener domain will fail in case of cross-origin access @@ -42,17 +24,19 @@ var Gmail = function(localJQuery) { } } - var api = { - get : {}, - observe : {}, - check : { data: {}}, - tools : {}, - tracker : {}, - dom : {}, - chat : {}, - compose : {}, - helper : {get: {}} - }; + this.get = {}; + this.observe = {}; + this.check = {}; + this.check.data = {}; + this.tools = {}; + this.tracker = {}; + this.dom = {}; + this.chat = {}; + this.compose = {}; + this.helper = {}; + this.helper.get = {}; + + api = this; api.DISABLE_OLD_GMAIL_API_DEPRECATION_WARNINGS = false; @@ -64,7 +48,6 @@ var Gmail = function(localJQuery) { console.warn("GmailJS: using deprecated API for old Gmail.", text); } - api.version = "0.8.0"; api.tracker.globals = typeof GLOBALS !== "undefined" ? GLOBALS : ( @@ -96,71 +79,11 @@ var Gmail = function(localJQuery) { }; - api.get.loggedin_accounts = function() { - var i, j, data; - var users = []; - - var globals17 = api.tracker.globals[17]; - for (i in globals17) { - // at least for the delegated inboxes, the index of the mla is not stable - // it was observed to be somewhere between 22 and 24, but we should not depend on it - data = globals17[i]; - - if (data[0] === "mla") { - for(j in data[1]) { - users.push({ - name : data[1][j][4], - email : data[1][j][0], - index: data[1][j][3] - }); - } - - return users; - } - } - - return users; - }; - - api.get.user_email = function() { return api.tracker.globals[10]; }; - api.get.manager_email = function() { - if (api.helper.get.is_delegated_inbox()) { - return api.get.delegated_to_email(); - } - - return api.get.user_email(); - }; - - - api.get.delegated_to_email = function() { - if (!api.helper.get.is_delegated_inbox()) { - return null; - } - - var i, account; - var userIndexPrefix = "/u/"; - var pathname = window.location.pathname; - var delegatedToUserIndex = parseInt(pathname.substring(pathname.indexOf(userIndexPrefix) + userIndexPrefix.length), 10); - - var loggedInAccounts = api.get.loggedin_accounts(); - if (loggedInAccounts && loggedInAccounts.length > 0) { - for (i in loggedInAccounts) { - account = loggedInAccounts[i]; - if (account.index === delegatedToUserIndex) { - return account.email; - } - } - } - - // as a last resort, we query the DOM of the upper right account selection menu - return $(".gb_rb[href$='" + userIndexPrefix + delegatedToUserIndex + "'] .gb_yb").text().split(" ")[0]; - }; - api.helper.get.is_locale = function(locale) { // A locale is a string that begins with 2 letters, either lowercase or uppercase // The "lowercase" check distinguishes locales from other 2-letter strings like "US" @@ -2816,11 +2739,6 @@ var Gmail = function(localJQuery) { }; - api.helper.get.is_delegated_inbox = function() { - return $(".identityUserDelegatedAccount").length === 1; - }; - - api.helper.get.visible_emails_pre = function(customInboxQuery) { var page = api.get.current_page(); var url = window.location.origin + window.location.pathname + "?ui=2&ik=" + api.tracker.ik+"&rid=" + api.tracker.rid + "&view=tl&num=120&rt=1"; @@ -4444,11 +4362,4 @@ var Gmail = function(localJQuery) { if (typeof(document) !== "undefined") { api.tools.embedded_data_watcher(); } - - return api; }; - -// make class accessible to require()-users. -if (typeof(exports) !== "undefined") { - exports.Gmail = Gmail; -}