@@ -72,7 +72,7 @@ function obtain_deck_splited(data_array) {
7272
7373// ## check valid
7474
75- const obtainValidCids = async ( lang = "en" ) => {
75+ /* const obtainValidCids = async (lang = "en") => {
7676 const url_now = location.href;
7777 const url_Eng = url_now.replace(/&request_locale=\S\S/g, "") + `&request_locale=${lang}`;
7878 const res_Eng = await fetch(url_Eng).then(d => d.body)
@@ -115,7 +115,7 @@ async function showValidCards(IsColored = true) {
115115 }
116116 });
117117 });
118- }
118+ }*/
119119
120120//---------------------------------
121121// # export
@@ -127,13 +127,31 @@ async function exportAs(form = "id") {
127127 const row_names = [ ...Array ( rows_num ) . keys ( ) ] . map ( row_ind => $ ( `#deck_text [id$='_list']:eq(${ row_ind } )` ) . attr ( "id" )
128128 . match ( / ^ \S * (? = _ l i s t ) / ) [ 0 ] ) ;
129129
130- const obtainRowResults = {
130+ const obtainRowResults = async ( ) => {
131+ return [ ...Array ( rows_num ) . keys ( ) ] . map ( row_ind => {
132+ const card_length = $ ( `#deck_text [id$='_list']:eq(${ row_ind } ) .card_name` ) . length ;
133+ return {
134+ names : [ ...Array ( card_length ) . keys ( ) ]
135+ . map ( d => $ ( `#deck_text [id$='_list']:eq(${ row_ind } ) .card_name:eq(${ d } )` ) . text ( ) ) ,
136+ cids : [ ...Array ( card_length ) . keys ( ) ]
137+ . map ( d => $ ( `#deck_text [id$='_list']:eq(${ row_ind } ) .card_name:eq(${ d } )` )
138+ . parent ( "td" ) . children ( "input.link_value" ) . val ( ) . match ( / (?< = c i d = ) \d + / ) [ 0 ] - 0 ) ,
139+ nums : [ ...Array ( card_length ) . keys ( ) ]
140+ . map ( d => $ ( `#deck_text [id$='_list']:eq(${ row_ind } ) .num:eq(${ d } )` ) . text ( ) . match ( / \d / ) [ 0 ] )
141+ } ;
142+ } )
143+ }
144+
145+ /* const obtainRowResults_old = {
131146 Jap: async () => {
132147 return [...Array(rows_num).keys()].map(row_ind => {
133148 const card_length = $(`#deck_text [id$='_list']:eq(${row_ind}) .card_name`).length;
134149 return {
135150 names: [...Array(card_length).keys()]
136151 .map(d => $(`#deck_text [id$='_list']:eq(${row_ind}) .card_name:eq(${d})`).text()),
152+ cids : [...Array(card_length).keys()]
153+ .map(d => $(`#deck_text [id$='_list']:eq(${row_ind}) .card_name:eq(${d})`)
154+ .parent("td").children("input.link_value").val().match(/(?<=cid=)\d+/)),
137155 nums: [...Array(card_length).keys()]
138156 .map(d => $(`#deck_text [id$='_list']:eq(${row_ind}) .num:eq(${d})`).text().match(/\d/)[0])
139157 };
@@ -158,7 +176,8 @@ async function exportAs(form = "id") {
158176 let count = 0;
159177 return [...Array(card_length).keys()]
160178 .reduce((acc, d) => {
161- const cid_tmp = $ ( `#deck_text [id$='_list']:eq(${ row_ind } ) .card_name:eq(${ d } )` ) . parent ( "td" ) . children ( "input.link_value" ) . val ( ) . match ( / (?< = c i d = ) \d + / ) ;
179+ const cid_tmp = $(`#deck_text [id$='_list']:eq(${row_ind}) .card_name:eq(${d})`)
180+ .parent("td").children("input.link_value").val().match(/(?<=cid=)\d+/);
162181 const IsValid = cids.en.flat().indexOf(cid_tmp[0]) != -1;
163182 const wrapper = IsValid ? content : $("body");
164183 const ind_tmp = IsValid ? count++ : d;
@@ -176,39 +195,44 @@ async function exportAs(form = "id") {
176195 }, { names: [], nums: [] })
177196 })
178197 }
179- }
180- const row_results = await obtainRowResults [ form ] ( ) ;
198+ }*/
199+ const row_results = await obtainRowResults ( ) ;
181200 console . log ( row_results )
182201
183202 const df = await obtainDF ( ) ;
184203 const keys = [ "#main" , "#extra" , "!side" ] ;
185204 let result_outputs = keys . map ( _ => [ ] ) ;
205+ let result_exception_counts = keys . map ( _ => 0 ) ;
186206 for ( const [ row_ind , row_result ] of Object . entries ( row_results ) ) {
187207 const out_ind = ( row_ind < 3 ) ? 0 : row_ind - 2 ;
188208 for ( const [ ind , name_tmp ] of Object . entries ( row_result . names ) ) {
189- let output_comp = null ;
209+ const cid_tmp = row_result . cids [ ind ] ;
210+ let output_comp = undefined ;
190211 if ( form == "Jap" ) output_comp = `${ name_tmp } ` ;
191212 else if ( form == "id" ) {
192213 // convert id -> name / convert cid -> name
193- output_comp = df_filter ( df , "id" , [ "name " , name_tmp ] ) [ 0 ] ;
194- if ( output_comp === null ) {
214+ output_comp = df_filter ( df , "id" , [ "cid " , cid_tmp ] ) [ 0 ] ;
215+ /* if (output_comp === null) {
195216 const cid_db = $(`#deck_text [id$='_list']:eq(${row_ind}) .card_name:eq(${ind})`).parent("td").children("input.link_value").val().match(/(?<=cid=)\d+/)
196217 output_comp = !!(cid_db) ? df_filter(df, "id", ["cid", cid_db[0]])[0] : "";
197- }
218+ }*/
198219 }
199- if ( output_comp === null ) {
220+ if ( output_comp === undefined || / ^ \s * $ / . test ( output_comp ) ) {
200221 // can't convert case
201- const name_Jap = $ ( `#deck_text [id$='_list']:eq(${ row_ind } ) .card_name:eq(${ ind } )` ) . text ( ) ;
222+ const name_Jap = name_tmp // $(`#deck_text [id$='_list']:eq(${row_ind}) .card_name:eq(${ind})`).text();
202223 exceptions . push ( name_Jap ) ;
203224 // form=id and db has error => Japanese name and type wil be outputed with tab-separation
204225 output_comp = `${ name_Jap } \t${ row_names [ row_ind ] } ` ;
226+ result_exception_counts [ row_ind ] ++ ;
205227 }
206228 result_outputs [ out_ind ] . push ( ...Array ( row_result . nums [ ind ] - 0 ) . fill ( output_comp ) )
207229 }
208230 }
209231 const content = result_outputs . map ( ( id , ind ) => keys [ ind ] + "\n" + id . join ( "\n" ) ) . join ( "\n" ) ;
210232
211- const convert_results_message = [ "main" , "extra" , "side" ] . map ( ( d , ind ) => `${ d } : ${ result_outputs [ ind ] . length } ` ) . join ( "\n" )
233+ const convert_results_message = [ "main" , "extra" , "side" ] . map ( ( d , row_ind ) =>
234+ `${ d } : ${ result_outputs [ row_ind ] . length - result_exception_counts [ row_ind ] } /${ result_outputs [ row_ind ] . length } ` )
235+ . join ( "\n" )
212236 console . log ( convert_results_message ) ;
213237
214238 const bom = new Uint8Array ( [ 0xEF , 0xBB , 0xBF ] ) ;
@@ -388,7 +412,7 @@ $(async function () {
388412 document . addEventListener ( "click" , async function ( e ) {
389413 if ( $ ( e . target ) . is ( "a.button_export, a.button_export *" ) ) {
390414 const form = [ "id" , "Jap" ] . filter ( d => $ ( e . target ) . is ( `.${ d } , .${ d } *` ) ) [ 0 ] ;
391- console . log ( `export with ${ form } ` )
415+ console . log ( `export deck as ${ form } ` )
392416 await exportAs ( form ) ;
393417 }
394418 } )
0 commit comments