@@ -9,7 +9,7 @@ var session = require('../session');
99//
1010// https://github.com/skygragon/leetcode-cli-plugins/blob/master/docs/cookie.chrome.md
1111//
12- var plugin = new Plugin ( 13 , 'cookie.chrome' , '2017.12.23 ' ,
12+ var plugin = new Plugin ( 13 , 'cookie.chrome' , '2018.05.30 ' ,
1313 'Plugin to reuse Chrome\'s leetcode cookie.' ,
1414 [ 'ffi:win32' , 'keytar:darwin' , 'ref:win32' , 'ref-struct:win32' , 'sqlite3' ] ) ;
1515
@@ -28,7 +28,9 @@ plugin.help = function() {
2828var Chrome = { } ;
2929
3030var ChromeMAC = {
31- db : process . env . HOME + '/Library/Application Support/Google/Chrome/Default/Cookies' ,
31+ getDBPath : function ( ) {
32+ return `${ process . env . HOME } /Library/Application Support/Google/Chrome/${ this . profile } /Cookies` ;
33+ } ,
3234 iterations : 1003 ,
3335 getPassword : function ( cb ) {
3436 var keytar = require ( 'keytar' ) ;
@@ -37,7 +39,9 @@ var ChromeMAC = {
3739} ;
3840
3941var ChromeLinux = {
40- db : process . env . HOME + '/.config/google-chrome/Default/Cookies' ,
42+ getDBPath : function ( ) {
43+ return `${ process . env . HOME } /.config/google-chrome/${ this . profile } /Cookies` ;
44+ } ,
4145 iterations : 1 ,
4246 getPassword : function ( cb ) {
4347 // FIXME: keytar failed to read gnome-keyring on ubuntu??
@@ -48,7 +52,9 @@ var ChromeLinux = {
4852} ;
4953
5054var ChromeWindows = {
51- db : path . resolve ( process . env . APPDATA || '' , '../Local/Google/Chrome/User Data/Default/Cookies' ) ,
55+ getDBPath : function ( ) {
56+ return path . resolve ( process . env . APPDATA || '' , `../Local/Google/Chrome/User Data/${ this . profile } /Cookies` ) ;
57+ } ,
5258 getPassword : function ( cb ) { cb ( ) ; }
5359} ;
5460
@@ -124,7 +130,7 @@ function doDecode(key, queue, cb) {
124130
125131Chrome . getCookies = function ( cb ) {
126132 var sqlite3 = require ( 'sqlite3' ) ;
127- var db = new sqlite3 . Database ( my . db ) ;
133+ var db = new sqlite3 . Database ( my . getDBPath ( ) ) ;
128134 var KEYS = [ 'csrftoken' , 'LEETCODE_SESSION' ] ;
129135
130136 db . serialize ( function ( ) {
@@ -149,9 +155,12 @@ Chrome.getCookies = function(cb) {
149155plugin . signin = function ( user , cb ) {
150156 log . debug ( 'running cookie.chrome.signin' ) ;
151157 log . debug ( 'try to copy leetcode cookies from chrome ...' ) ;
158+
159+ my . profile = plugin . config . profile || 'Default' ;
152160 my . getCookies ( function ( e , cookies ) {
153161 if ( e ) {
154- log . error ( 'failed to copy cookies: ' + e ) ;
162+ log . error ( `Failed to copy cookies from profile "${ my . profile } "` ) ;
163+ log . error ( e ) ;
155164 return plugin . next . signin ( user , cb ) ;
156165 }
157166
0 commit comments