2020-11-10 09:29:58 +08:00
/ *
感谢github @ dompling的PR
Author : 2 Ya
2020-11-23 09:42:51 +08:00
Github : https : //github.com/dompling
2020-11-10 09:29:58 +08:00
=== === === === === === =
特别说明 :
2020-12-27 12:41:12 +08:00
1. 获取多个京东cookie的脚本 , 不和NobyDa的京东cookie冲突 。
2020-11-10 09:29:58 +08:00
=== === === === === === =
=== === === === === === =
2020-12-27 12:34:11 +08:00
使用方式 : 在代理软件配置好下方配置后 , 复制 https : //home.m.jd.com/myJd/newhome.action 到浏览器打开 ,在个人中心自动获取 cookie,
2020-11-10 09:29:58 +08:00
若弹出成功则正常使用 。 否则继续再此页面继续刷新一下试试
=== === === === === === =
=== === === === === === =
[ MITM ]
hostname = wq . jd . com
【 Surge脚本配置 】 :
=== === === === === === =
[ Script ]
2021-01-16 17:10:19 +08:00
获取京东Cookie = type = http - request , pattern = ^ https : \ / \ / wq \ . jd \ . com \ / user _new \ / info \ / GetJDUserInfoUnion , requires - body = 1 , max - size = 0 , script - path = https : //raw.githubusercontent.com/LXK9301/jd_scripts/master/JD_extra_cookie.js,script-update-interval=0
2020-11-10 09:29:58 +08:00
=== === === === === === =
【 Loon脚本配置 】 :
=== === === === === === =
[ Script ]
2021-01-16 17:10:19 +08:00
http - request https : \ / \ / wq \ . jd \ . com \ / user _new \ / info \ / GetJDUserInfoUnion tag = 获取京东Cookie , script - path = https : //raw.githubusercontent.com/LXK9301/jd_scripts/master/JD_extra_cookie.js
2020-11-10 09:29:58 +08:00
=== === === === === === =
【 QX 脚本配置 】 :
=== === === === === === =
[ rewrite _local ]
2021-01-16 17:10:19 +08:00
https : \ / \ / wq \ . jd \ . com \ / user _new \ / info \ / GetJDUserInfoUnion url script - request - header https : //raw.githubusercontent.com/LXK9301/jd_scripts/master/JD_extra_cookie.js
2020-11-10 09:29:58 +08:00
* /
const APIKey = "CookiesJD" ;
$ = new API ( APIKey , true ) ;
const CacheKey = ` # ${ APIKey } ` ;
if ( $request ) GetCookie ( ) ;
function getCache ( ) {
var cache = $ . read ( CacheKey ) || "[]" ;
$ . log ( cache ) ;
return JSON . parse ( cache ) ;
}
function GetCookie ( ) {
try {
if ( $request . headers && $request . url . indexOf ( "GetJDUserInfoUnion" ) > - 1 ) {
var CV = $request . headers [ "Cookie" ] || $request . headers [ "cookie" ] ;
if ( CV . match ( /(pt_key=.+?pt_pin=|pt_pin=.+?pt_key=)/ ) ) {
var CookieValue = CV . match ( /pt_key=.+?;/ ) + CV . match ( /pt_pin=.+?;/ ) ;
var UserName = CookieValue . match ( /pt_pin=(.+?);/ ) [ 1 ] ;
var DecodeName = decodeURIComponent ( UserName ) ;
var CookiesData = getCache ( ) ;
var updateCookiesData = [ ... CookiesData ] ;
var updateIndex ;
var CookieName = "【账号】" ;
var updateCodkie = CookiesData . find ( ( item , index ) => {
var ck = item . cookie ;
var Account = ck
? ck . match ( /pt_pin=.+?;/ )
? ck . match ( /pt_pin=(.+?);/ ) [ 1 ]
: null
: null ;
const verify = UserName === Account ;
if ( verify ) {
updateIndex = index ;
}
return verify ;
} ) ;
var tipPrefix = "" ;
if ( updateCodkie ) {
updateCookiesData [ updateIndex ] . cookie = CookieValue ;
CookieName = ` 【账号 ${ updateIndex + 1 } 】 ` ;
tipPrefix = "更新京东" ;
} else {
updateCookiesData . push ( {
userName : DecodeName ,
cookie : CookieValue ,
} ) ;
CookieName = "【账号" + updateCookiesData . length + "】" ;
tipPrefix = "首次写入京东" ;
}
const cacheValue = JSON . stringify ( updateCookiesData , null , "\t" ) ;
$ . write ( cacheValue , CacheKey ) ;
$ . notify (
"用户名: " + DecodeName ,
"" ,
tipPrefix + CookieName + "Cookie成功 🎉"
) ;
} else {
$ . notify ( "写入京东Cookie失败" , "" , "请查看脚本内说明, 登录网页获取 ‼️" ) ;
}
$ . done ( ) ;
return ;
} else {
$ . notify ( "写入京东Cookie失败" , "" , "请检查匹配URL或配置内脚本类型 ‼️" ) ;
}
} catch ( eor ) {
$ . write ( "" , CacheKey ) ;
$ . notify ( "写入京东Cookie失败" , "" , "已尝试清空历史Cookie, 请重试 ⚠️" ) ;
console . log (
` \n 写入京东Cookie出现错误 ‼️ \n ${ JSON . stringify (
eor
) } \ n \ n$ { eor } \ n \ n$ { JSON . stringify ( $request . headers ) } \ n `
) ;
}
$ . done ( ) ;
}
// prettier-ignore
2021-01-20 11:35:26 +08:00
function Env ( t , e ) { "undefined" != typeof process && JSON . stringify ( process . env ) . indexOf ( "GITHUB" ) > - 1 && process . exit ( 0 ) ; class s { constructor ( t ) { this . env = t } send ( t , e = "GET" ) { t = "string" == typeof t ? { url : t } : t ; let s = this . get ; return "POST" === e && ( s = this . post ) , new Promise ( ( e , i ) => { s . call ( this , t , ( t , s , r ) => { t ? i ( t ) : e ( s ) } ) } ) } get ( t ) { return this . send . call ( this . env , t ) } post ( t ) { return this . send . call ( this . env , t , "POST" ) } } return new class { constructor ( t , e ) { this . name = t , this . http = new s ( this ) , this . data = null , this . dataFile = "box.dat" , this . logs = [ ] , this . isMute = ! 1 , this . isNeedRewrite = ! 1 , this . logSeparator = "\n" , this . startTime = ( new Date ) . getTime ( ) , Object . assign ( this , e ) , this . log ( "" , ` 🔔 ${ this . name } , 开始! ` ) } isNode ( ) { return "undefined" != typeof module && ! ! module . exports } isQuanX ( ) { return "undefined" != typeof $task } isSurge ( ) { return "undefined" != typeof $httpClient && "undefined" == typeof $loon } isLoon ( ) { return "undefined" != typeof $loon } toObj ( t , e = null ) { try { return JSON . parse ( t ) } catch { return e } } toStr ( t , e = null ) { try { return JSON . stringify ( t ) } catch { return e } } getjson ( t , e ) { let s = e ; const i = this . getdata ( t ) ; if ( i ) try { s = JSON . parse ( this . getdata ( t ) ) } catch { } return s } setjson ( t , e ) { try { return this . setdata ( JSON . stringify ( t ) , e ) } catch { return ! 1 } } getScript ( t ) { return new Promise ( e => { this . get ( { url : t } , ( t , s , i ) => e ( i ) ) } ) } runScript ( t , e ) { return new Promise ( s => { let i = this . getdata ( "@chavy_boxjs_userCfgs.httpapi" ) ; i = i ? i . replace ( /\n/g , "" ) . trim ( ) : i ; let r = this . getdata ( "@chavy_boxjs_userCfgs.httpapi_timeout" ) ; r = r ? 1 * r : 20 , r = e && e . timeout ? e . timeout : r ; const [ o , h ] = i . split ( "@" ) , n = { url : ` http:// ${ h } /v1/scripting/evaluate ` , body : { script _text : t , mock _type : "cron" , timeout : r } , headers : { "X-Key" : o , Accept : "*/*" } } ; this . post ( n , ( t , e , i ) => s ( i ) ) } ) . catch ( t => this . logErr ( t ) ) } loaddata ( ) { if ( ! this . isNode ( ) ) return { } ; { this . fs = this . fs ? this . fs : require ( "fs" ) , this . path = this . path ? this . path : require ( "path" ) ; const t = this . path . resolve ( this . dataFile ) , e = this . path . resolve ( process . cwd ( ) , this . dataFile ) , s = this . fs . existsSync ( t ) , i = ! s && this . fs . existsSync ( e ) ; if ( ! s && ! i ) return { } ; { const i = s ? t : e ; try { return JSON . parse ( this . fs . readFileSync ( i ) ) } catch ( t ) { return { } } } } } writedata ( ) { if ( this . isNode ( ) ) { this . fs = this . fs ? this . fs : require ( "fs" ) , this . path = this . path ? this . path : require ( "path" ) ; const t = this . path . resolve ( this . dataFile ) , e = this . path . resolve ( process . cwd ( ) , this . dataFile ) , s = this . fs . existsSync ( t ) , i = ! s && this . fs . existsSync ( e ) , r = JSON . stringify ( this . data ) ; s ? this . fs . writeFileSync ( t , r ) : i ? this . fs . writeFileSync ( e , r ) : this . fs . writeFileSync ( t , r ) } } lodash _get ( t , e , s ) { const i = e . replace ( /\[(\d+)\]/g , ".$1" ) . split ( "." ) ; let r = t ; for ( const t of i ) if ( r = Object ( r ) [ t ] , void 0 === r ) return s ; return r } lodash _set ( t , e , s ) { return Object ( t ) !== t ? t : ( Array . isArray ( e ) || ( e = e . toString ( ) . match ( /[^.[\]]+/g ) || [ ] ) , e . slice ( 0 , - 1 ) . reduce ( ( t , s , i ) => Object ( t [ s ] ) === t [ s ] ? t [ s ] : t [ s ] = Math . abs ( e [ i + 1 ] ) >> 0 == + e [ i + 1 ] ? [ ] : { } , t ) [ e [ e . length - 1 ] ] = s , t ) } getdata ( t ) { let e = this . getval ( t ) ; if ( /^@/ . test ( t ) ) { const [ , s , i ] = /^@(.*?)\.(.*?)$/ . exec ( t ) , r = s ? this . getval ( s ) : "" ; if ( r ) try { const t = JSON . parse ( r ) ; e = t ? this . lodash _get ( t , i , "" ) : e } catch ( t ) { e = "" } } return e } setdata ( t , e ) { let s = ! 1 ; if ( /^@/ . test ( e ) ) { const [ , i , r ] = /^@(.*?)\.(.*?)$/ . exec ( e ) , o = this . getval ( i ) , h = i ? "null" === o ? null : o || "{}" : "{}" ; try { const e = JSON . parse ( h ) ; this . lodash _set ( e , r , t ) , s = this . setval ( JSON . stringify ( e ) , i ) } catch ( e ) { const o = { } ; this . lodash _set ( o , r , t ) , s = this . setval ( JSON . stringify ( o ) , i ) } } else s = this . setval ( t , e ) ; return s } getval ( t ) { return this . isSurge ( ) || this . isLoon ( ) ? $persistentStore . read ( t ) : this . isQuanX ( ) ? $prefs . valueForKey ( t ) : this . isNode ( ) ? ( this . data = this . loaddata ( ) , this . data [ t ] ) : this . data && this . data [ t ] || null } setval ( t , e ) { return this . isSurge ( ) || this . isLoon ( ) ? $persistentStore . write ( t , e ) : this . isQuanX ( ) ? $prefs . setValueForKey ( t , e ) : this . isNode ( ) ? ( this . data = this . loaddata ( ) , this . data [ e ] = t , this . writedata ( ) , ! 0 ) : this . data && this . data [ e ] || null } initGotEnv ( t ) { this . got = this . got ? this . got : require ( "got" ) , this . cktough = this . cktough ? this . cktough : require ( "tough-cookie" ) , this . ckjar = this . ckjar ? this . ckjar : new this . cktough . CookieJar , t && ( t . headers = t . headers ? t . headers : { } , void 0 === t . headers . Cookie && void 0 === t . cookieJar && ( t . cookieJar = this . ckjar ) ) } get ( t , e = ( ( ) => { } ) ) { t . headers && ( delete t . headers [ "Content-Type" ] , delete t . headers [ "Content-Length" ] )
2020-11-10 09:29:58 +08:00
// prettier-ignore
function HTTP ( baseURL , defaultOptions = { } ) { const { isQX , isLoon , isSurge , isScriptable , isNode } = ENV ( ) ; const methods = [ "GET" , "POST" , "PUT" , "DELETE" , "HEAD" , "OPTIONS" , "PATCH" ] ; function send ( method , options ) { options = typeof options === "string" ? { url : options } : options ; options . url = baseURL ? baseURL + options . url : options . url ; options = { ... defaultOptions , ... options } ; const timeout = options . timeout ; const events = { ... { onRequest : ( ) => { } , onResponse : ( resp ) => resp , onTimeout : ( ) => { } , } , ... options . events , } ; events . onRequest ( method , options ) ; let worker ; if ( isQX ) { worker = $task . fetch ( { method , ... options } ) } else if ( isLoon || isSurge || isNode ) { worker = new Promise ( ( resolve , reject ) => { const request = isNode ? require ( "request" ) : $httpClient ; request [ method . toLowerCase ( ) ] ( options , ( err , response , body ) => { if ( err ) reject ( err ) ; else resolve ( { statusCode : response . status || response . statusCode , headers : response . headers , body , } ) } ) } ) } else if ( isScriptable ) { const request = new Request ( options . url ) ; request . method = method ; request . headers = options . headers ; request . body = options . body ; worker = new Promise ( ( resolve , reject ) => { request . loadString ( ) . then ( ( body ) => { resolve ( { statusCode : request . response . statusCode , headers : request . response . headers , body , } ) } ) . catch ( ( err ) => reject ( err ) ) } ) } let timeoutid ; const timer = timeout ? new Promise ( ( _ , reject ) => { timeoutid = setTimeout ( ( ) => { events . onTimeout ( ) ; return reject ( ` ${ method } URL: ${ options . url } exceeds the timeout ${ timeout } ms ` ) } , timeout ) } ) : null ; return ( timer ? Promise . race ( [ timer , worker ] ) . then ( ( res ) => { clearTimeout ( timeoutid ) ; return res } ) : worker ) . then ( ( resp ) => events . onResponse ( resp ) ) } const http = { } ; methods . forEach ( ( method ) => ( http [ method . toLowerCase ( ) ] = ( options ) => send ( method , options ) ) ) ; return http }
// prettier-ignore
function API ( name = "untitled" , debug = false ) { const { isQX , isLoon , isSurge , isNode , isJSBox , isScriptable } = ENV ( ) ; return new ( class { constructor ( name , debug ) { this . name = name ; this . debug = debug ; this . http = HTTP ( ) ; this . env = ENV ( ) ; this . node = ( ( ) => { if ( isNode ) { const fs = require ( "fs" ) ; return { fs } } else { return null } } ) ( ) ; this . initCache ( ) ; const delay = ( t , v ) => new Promise ( function ( resolve ) { setTimeout ( resolve . bind ( null , v ) , t ) } ) ; Promise . prototype . delay = function ( t ) { return this . then ( function ( v ) { return delay ( t , v ) } ) } } initCache ( ) { if ( isQX ) this . cache = JSON . parse ( $prefs . valueForKey ( this . name ) || "{}" ) ; if ( isLoon || isSurge ) this . cache = JSON . parse ( $persistentStore . read ( this . name ) || "{}" ) ; if ( isNode ) { let fpath = "root.json" ; if ( ! this . node . fs . existsSync ( fpath ) ) { this . node . fs . writeFileSync ( fpath , JSON . stringify ( { } ) , { flag : "wx" } , ( err ) => console . log ( err ) ) } this . root = { } ; fpath = ` ${ this . name } .json ` ; if ( ! this . node . fs . existsSync ( fpath ) ) { this . node . fs . writeFileSync ( fpath , JSON . stringify ( { } ) , { flag : "wx" } , ( err ) => console . log ( err ) ) ; this . cache = { } } else { this . cache = JSON . parse ( this . node . fs . readFileSync ( ` ${ this . name } .json ` ) ) } } } persistCache ( ) { const data = JSON . stringify ( this . cache ) ; if ( isQX ) $prefs . setValueForKey ( data , this . name ) ; if ( isLoon || isSurge ) $persistentStore . write ( data , this . name ) ; if ( isNode ) { this . node . fs . writeFileSync ( ` ${ this . name } .json ` , data , { flag : "w" } , ( err ) => console . log ( err ) ) ; this . node . fs . writeFileSync ( "root.json" , JSON . stringify ( this . root ) , { flag : "w" } , ( err ) => console . log ( err ) ) } } write ( data , key ) { this . log ( ` SET ${ key } ` ) ; if ( key . indexOf ( "#" ) !== - 1 ) { key = key . substr ( 1 ) ; if ( isSurge || isLoon ) { return $persistentStore . write ( data , key ) } if ( isQX ) { return $prefs . setValueForKey ( data , key ) } if ( isNode ) { this . root [ key ] = data } } else { this . cache [ key ] = data } this . persistCache ( ) } read ( key ) { this . log ( ` READ ${ key } ` ) ; if ( key . indexOf ( "#" ) !== - 1 ) { key = key . substr ( 1 ) ; if ( isSurge || isLoon ) { return $persistentStore . read ( key ) } if ( isQX ) { return $prefs . valueForKey ( key ) } if ( isNode ) { return this . root [ key ] } } else { return this . cache [ key ] } } delete ( key ) { this . log ( ` DELETE ${ key } ` ) ; if ( key . indexOf ( "#" ) !== - 1 ) { key = key . substr ( 1 ) ; if ( isSurge || isLoon ) { $persistentStore . write ( null , key ) } if ( isQX ) { $prefs . removeValueForKey ( key ) } if ( isNode ) { delete this . root [ key ] } } else { delete this . cache [ key ] } this . persistCache ( ) } notify ( title , subtitle = "" , content = "" , options = { } ) { const openURL = options [ "open-url" ] ; const mediaURL = options [ "media-url" ] ; if ( isQX ) $notify ( title , subtitle , content , options ) ; if ( isSurge ) { $notification . post ( title , subtitle , content + ` ${ mediaURL ? "\n多媒体:" + mediaURL : "" } ` , { url : openURL } ) } if ( isLoon ) { let opts = { } ; if ( openURL ) opts [ "openUrl" ] = openURL ; if ( mediaURL ) opts [ "mediaUrl" ] = mediaURL ; if ( JSON . stringify ( opts ) == "{}" ) { $notification . post ( title , subtitle , content ) } else { $notification . post ( title , subtitle , content , opts ) } } if ( isNode || isScriptable ) { const content _ = content + ( openURL ? ` \n 点击跳转: ${ openURL } ` : "" ) + ( mediaURL ? ` \n 多媒体: ${ mediaURL } ` : "" ) ; if ( isJSBox ) { const push = require ( "push" ) ; push . schedule ( { title : title , body : ( subtitle ? subtitle + "\n" : "" ) + content _ , } ) } else { console . log ( ` ${ title } \n ${ subtitle } \n ${ content _ } \n \n ` ) } } } log ( msg ) { if ( this . debug ) console . log ( msg ) } info ( msg ) { console . log ( msg ) } error ( msg ) { console . log ( "ERROR: " + msg ) } wait ( millisec ) { return new Promise ( ( resolve ) => setTimeout ( resolve , millisec ) ) } done ( value = { } ) { if ( isQX || isLoon || isSurge ) { $done ( value ) } else if ( isNode && ! isJSBox ) { if ( typeof $context !== "undefined" ) { $context . headers = value . headers ; $context . statusCode = value . statusCode ; $context . body = value . body } } } } ) ( name , debug ) }