@@ -9,7 +9,7 @@ var session = require('../session');
9
9
//
10
10
// https://github.com/skygragon/leetcode-cli-plugins/blob/master/docs/cookie.chrome.md
11
11
//
12
- var plugin = new Plugin ( 13 , 'cookie.chrome' , '2017.12.23 ' ,
12
+ var plugin = new Plugin ( 13 , 'cookie.chrome' , '2018.05.30 ' ,
13
13
'Plugin to reuse Chrome\'s leetcode cookie.' ,
14
14
[ 'ffi:win32' , 'keytar:darwin' , 'ref:win32' , 'ref-struct:win32' , 'sqlite3' ] ) ;
15
15
@@ -28,7 +28,9 @@ plugin.help = function() {
28
28
var Chrome = { } ;
29
29
30
30
var 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
+ } ,
32
34
iterations : 1003 ,
33
35
getPassword : function ( cb ) {
34
36
var keytar = require ( 'keytar' ) ;
@@ -37,7 +39,9 @@ var ChromeMAC = {
37
39
} ;
38
40
39
41
var 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
+ } ,
41
45
iterations : 1 ,
42
46
getPassword : function ( cb ) {
43
47
// FIXME: keytar failed to read gnome-keyring on ubuntu??
@@ -48,7 +52,9 @@ var ChromeLinux = {
48
52
} ;
49
53
50
54
var 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
+ } ,
52
58
getPassword : function ( cb ) { cb ( ) ; }
53
59
} ;
54
60
@@ -124,7 +130,7 @@ function doDecode(key, queue, cb) {
124
130
125
131
Chrome . getCookies = function ( cb ) {
126
132
var sqlite3 = require ( 'sqlite3' ) ;
127
- var db = new sqlite3 . Database ( my . db ) ;
133
+ var db = new sqlite3 . Database ( my . getDBPath ( ) ) ;
128
134
var KEYS = [ 'csrftoken' , 'LEETCODE_SESSION' ] ;
129
135
130
136
db . serialize ( function ( ) {
@@ -149,9 +155,12 @@ Chrome.getCookies = function(cb) {
149
155
plugin . signin = function ( user , cb ) {
150
156
log . debug ( 'running cookie.chrome.signin' ) ;
151
157
log . debug ( 'try to copy leetcode cookies from chrome ...' ) ;
158
+
159
+ my . profile = plugin . config . profile || 'Default' ;
152
160
my . getCookies ( function ( e , cookies ) {
153
161
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 ) ;
155
164
return plugin . next . signin ( user , cb ) ;
156
165
}
157
166
0 commit comments