1- //const SPREADSHEET_ID = '1pzuWR409vSmoFX9inmoU6el6vjG0SniB1KrxWLeVpaA';
2- const SPREADSHEET_ID = '1dUnmBZSnz3aeB948b7pIq0iT7_FuCDvtv6FXaVsNcOo' ;
1+ const SPREADSHEET_ID = '1dUnmBZSnz3aeB948b7pIq0iT7_FuCDvtv6FXaVsNcOo' ; // production
32const SCV_RANGE = 'SCVs' ;
4- const VCV_RANGE = 'VCVs' ;
53
64// Inform the background page that
75// this tab should have a page-action.
86chrome . runtime . sendMessage ( {
9- from : 'content' ,
10- subject : 'showPageAction' ,
7+ from : 'content' ,
8+ subject : 'showPageAction' ,
119} ) ;
1210
13- // Listen for messages from the popup.
14- chrome . runtime . onMessage . addListener ( ( msg , sender , response ) => {
15-
16- // First, validate the message's structure.
17- if ( ( msg . from === 'popup' ) && ( msg . subject === 'DOMInfo' ) ) {
18-
19- function getMatch ( text , re , grp ) {
20- var result ;
21- result = text . match ( re ) ;
22- if ( result === null ) {
23- return "" ;
24- }
25- return result [ grp ] ;
11+ function getMatch ( text , re , grp ) {
12+ var result ;
13+ result = text . match ( re ) ;
14+ if ( result === null ) {
15+ return "" ;
2616 }
17+ return result [ grp ] ;
18+ }
19+
20+ function extractClinVarData ( ) {
21+
2722 // Collect the necessary data.
2823 var cond_origin_re = / \W * A l l e l e o r i g i n : .* ?( \w + ( [ \, \s ] + \w + ) * ) / is;
2924 var review_method_re = / ( p r a c t i c e g u i d e l i n e | r e v i e w e d b y e x p e r t p a n e l | n o a s s e r t i o n p r o v i d e d | n o i n t e r p r e t a t i o n f o r t h e s i n g l e v a r i a n t | c r i t e r i a p r o v i d e d , m u l t i p l e s u b m i t t e r s , n o c o n f l i c t s | c r i t e r i a p r o v i d e d , s i n g l e s u b m i t t e r | c r i t e r i a p r o v i d e d , c o n f l i c t i n g i n t e r p r e t a t i o n s | n o a s s e r t i o n c r i t e r i a p r o v i d e d | n o c l a s s i f i c a t i o n p r o v i d e d | F l a g g e d s u b m i s s i o n ) .* ?M e t h o d : .* ?( [ \w \, \s ] + ) * / is;
3025 var subm_scv_re = / \W * \/ c l i n v a r \/ s u b m i t t e r s \/ ( \d + ) \/ " .* ?> ( .+ ?) < \/ a > .* ?A c c e s s i o n : .* ?( S C V \d + \. \d + ) .* ?F i r s t i n C l i n V a r : \W ( \w + \s \d + \, \s \d + ) .* ?L a s t u p d a t e d : .* ?( \w + \s \d + \, \s \d + ) / is;
3126 var interp_re = / \W * < d i v .* ?< d i v .* ?( \w + ( [ \s \/ \- \, ] * \w + ) * ) .* ?\( ( [ \w \s \, \- ] + ) \) / is;
32-
27+
3328 var vcv_accession_re = / A c c e s s i o n : .* ?( V C V \d + \. \d + ) / is;
3429 var vcv_variation_id_re = / V a r i a t i o n I D : .* ?( \d + ) / is;
3530
36- var domInfo = {
31+ var clinvarData = {
3732 spreadsheet : SPREADSHEET_ID ,
3833 scv_range : SCV_RANGE ,
39- vcv_range : VCV_RANGE ,
4034 vcv : "" ,
4135 name : "" ,
4236 variation_id : "" ,
@@ -46,7 +40,7 @@ chrome.runtime.onMessage.addListener((msg, sender, response) => {
4640 vcv_eval_date : "" ,
4741 row : [ ]
4842 } ;
49-
43+
5044 var variantBox = document . evaluate ( "//div[@id='new-variant-details']//dl" , document , null , XPathResult . ANY_TYPE , null ) ;
5145 var variantBoxHTML = variantBox . iterateNext ( ) . innerHTML ;
5246
@@ -56,57 +50,65 @@ chrome.runtime.onMessage.addListener((msg, sender, response) => {
5650
5751 var vcvClassificationTextNode = vcvClassificationText . iterateNext ( ) ;
5852 var vcvReviewStatusNode = vcvReviewStatus . iterateNext ( ) ;
59-
53+
6054 if ( ! vcvClassificationTextNode ) {
61- // for 2 star and below the vcvs review status and classifiction are found with the following
62- vcvClassificationText = document . evaluate ( "//div[@class='germline-section']//div[@class='single-item-value']" , document , null , XPathResult . ANY_TYPE , null ) ;
63- vcvReviewStatus = document . evaluate ( "//div[@class='germline-section']//div[@class='section-cnt']//span" , document , null , XPathResult . ANY_TYPE , null ) ;
64- vcvClassificationTextNode = vcvClassificationText . iterateNext ( ) ;
65- vcvReviewStatusNode = vcvReviewStatus . iterateNext ( ) ;
55+ // for 2 star and below the vcvs review status and classifiction are found with the following
56+ vcvClassificationText = document . evaluate ( "//div[@class='germline-section']//div[@class='single-item-value']" , document , null , XPathResult . ANY_TYPE , null ) ;
57+ vcvReviewStatus = document . evaluate ( "//div[@class='germline-section']//div[@class='section-cnt']//span" , document , null , XPathResult . ANY_TYPE , null ) ;
58+ vcvClassificationTextNode = vcvClassificationText . iterateNext ( ) ;
59+ vcvReviewStatusNode = vcvReviewStatus . iterateNext ( ) ;
6660 }
67-
61+
6862 if ( ! vcvClassificationTextNode ) {
69- // for vcv with no germline scvs there is no classification and review status
70- vcvClassificationText = document . evaluate ( "//div[@class='germline-section']/p[@class='without-classification']" , document , null , XPathResult . ANY_TYPE , null ) ;
71- vcvReviewStatus = document . evaluate ( "//div[@class='germline-section']/p[@class='without-classification']" , document , null , XPathResult . ANY_TYPE , null ) ;
72- vcvClassificationTextNode = vcvClassificationText . iterateNext ( ) ;
73- vcvReviewStatusNode = vcvReviewStatus . iterateNext ( ) ;
63+ // for vcv with no germline scvs there is no classification and review status
64+ vcvClassificationText = document . evaluate ( "//div[@class='germline-section']/p[@class='without-classification']" , document , null , XPathResult . ANY_TYPE , null ) ;
65+ vcvReviewStatus = document . evaluate ( "//div[@class='germline-section']/p[@class='without-classification']" , document , null , XPathResult . ANY_TYPE , null ) ;
66+ vcvClassificationTextNode = vcvClassificationText . iterateNext ( ) ;
67+ vcvReviewStatusNode = vcvReviewStatus . iterateNext ( ) ;
7468 }
75-
76- domInfo . name = document . querySelectorAll ( '#variant-details-table div div dl dd p' ) [ 0 ] . innerText ;
77- domInfo . vcv = getMatch ( variantBoxHTML , vcv_accession_re , 1 ) ;
78- domInfo . variation_id = getMatch ( variantBoxHTML , vcv_variation_id_re , 1 ) ;
79- domInfo . vcv_review = vcvReviewStatusNode . textContent . trim ( ) ;
80- domInfo . vcv_interp = vcvClassificationTextNode . textContent . trim ( ) ;
81-
69+
70+ clinvarData . name = document . querySelectorAll ( '#variant-details-table div div dl dd p' ) [ 0 ] . innerText ;
71+ clinvarData . vcv = getMatch ( variantBoxHTML , vcv_accession_re , 1 ) ;
72+ clinvarData . variation_id = getMatch ( variantBoxHTML , vcv_variation_id_re , 1 ) ;
73+ clinvarData . vcv_review = vcvReviewStatusNode . textContent . trim ( ) ;
74+ clinvarData . vcv_interp = vcvClassificationTextNode . textContent . trim ( ) ;
75+
8276 var timelineArray = document . querySelectorAll ( 'table.timeline-table tbody tr td' ) ;
83- domInfo . vcv_most_recent = timelineArray [ 2 ] . innerHTML ;
84- domInfo . vcv_eval_date = timelineArray [ 3 ] . innerHTML ;
85-
77+ clinvarData . vcv_most_recent = timelineArray [ 2 ] . innerHTML ;
78+ clinvarData . vcv_eval_date = timelineArray [ 3 ] . innerHTML ;
79+
8680 var scvarray = document . querySelectorAll ( '#new-submission-germline table tbody tr' ) ;
8781 scvarray . forEach ( myFunction ) ;
88-
82+
8983 function myFunction ( value , index , array ) {
90- var interp_match = value . cells [ 0 ] . innerHTML . match ( interp_re ) ;
91- var review_method_match = value . cells [ 1 ] . innerHTML . match ( review_method_re ) ;
84+ var interp_match = value . cells [ 0 ] . innerHTML . match ( interp_re ) ;
85+ var review_method_match = value . cells [ 1 ] . innerHTML . match ( review_method_re ) ;
9286
93- var cond_origin_match = value . cells [ 2 ] . innerHTML . match ( cond_origin_re ) ; // alert(value.cells[3].innerHTML);
94- var subm_scv_match = value . cells [ 3 ] . innerHTML . match ( subm_scv_re ) ;
87+ var cond_origin_match = value . cells [ 2 ] . innerHTML . match ( cond_origin_re ) ; // alert(value.cells[3].innerHTML);
88+ var subm_scv_match = value . cells [ 3 ] . innerHTML . match ( subm_scv_re ) ;
9589
96- domInfo . row . push ( {
97- submitter_id : subm_scv_match [ 1 ] ,
98- submitter : subm_scv_match [ 2 ] ,
99- scv : subm_scv_match [ 3 ] ,
100- subm_date : subm_scv_match [ 5 ] ,
101- origin : cond_origin_match [ 1 ] ,
102- review : review_method_match [ 1 ] ,
103- method : review_method_match [ 2 ] ,
104- interp : interp_match [ 1 ] ,
105- eval_date : interp_match [ 3 ]
106- } ) ;
90+ clinvarData . row . push ( {
91+ submitter_id : subm_scv_match [ 1 ] ,
92+ submitter : subm_scv_match [ 2 ] ,
93+ scv : subm_scv_match [ 3 ] ,
94+ subm_date : subm_scv_match [ 5 ] ,
95+ origin : cond_origin_match [ 1 ] ,
96+ review : review_method_match [ 1 ] ,
97+ method : review_method_match [ 2 ] ,
98+ interp : interp_match [ 1 ] ,
99+ eval_date : interp_match [ 3 ]
100+ } ) ;
107101 }
108- // Directly respond to the sender (popup),
109- // through the specified callback.
110- response ( domInfo ) ;
111- }
112- } ) ;
102+
103+ return clinvarData ;
104+ }
105+
106+ chrome . runtime . onMessage . addListener ( ( message , sender , sendResponse ) => {
107+ console . log ( '===== CONTENT.js event recieved: msg:' , message , new Date ( ) . getTime ( ) )
108+ if ( message . from === "popup" && message . subject === "initializePopup" ) {
109+ const data = extractClinVarData ( ) ;
110+ console . log ( '===== CONTENT.js event pre-sendResponse: ' , message , data , new Date ( ) . getTime ( ) )
111+ sendResponse ( data ) ;
112+ }
113+ return true ; // Required for async responses
114+ } ) ;
0 commit comments