Skip to content

Commit 4f7668a

Browse files
author
Tomotom0
committed
v0.7: Corresponds to new cards
1 parent 3997267 commit 4f7668a

5 files changed

Lines changed: 57 additions & 23 deletions

File tree

heroku

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit e474395bfc663c95a9b2d2f248546e1c6d360ae6
1+
Subproject commit 7a2c4efaaee2ebc9fe320dc7bc0f45f2c1dafc6b

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "遊戯王デッキサポート(インポート/エクスポート)",
33
"author":"TomoTomo",
4-
"version": "0.6.5.0",
4+
"version": "0.7.0.0",
55
"manifest_version": 2,
66
"icons":{
77
"16":"img/icon-16.png",

src/script/content_script.js

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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*(?=_list)/)[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(/(?<=cid=)\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(/(?<=cid=)\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
})

src/script/db_functions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,13 @@ async function updateDB(){
359359

360360
const git_content_url = `https://api.github.com/repos/${repoInfo.user}/${repoInfo.repo}/contents/data`;
361361
const res_content = await fetch(git_content_url, { method: "GET", headers: header_auth }).then(d=>d.json());
362-
const sha=res_content.filter(d=>d.path===repoInfo.path)[0].sha
363-
const git_data_url = `https://api.github.com/repos/${repoInfo.user}/${repoInfo.repo}/git/blobs/${sha}`;
362+
const git_data_url = res_content.filter(d=>d.path===repoInfo.path)[0].git_url;
364363
const content = await fetch(git_data_url, { method: "GET", headers: header_auth }).then(d=>d.json())
365364
.then(res=>atob(res.content));
366365
console.log("Database has been updated.");
367366
let df_new=JSON.parse(content).all;
368-
df_new.id=df_new.id.map(d=>d-0)
367+
df_new.id=df_new.id.map(d=>d-0);
368+
df_new.cid=df_new.cid.map(d=>d-0);
369369
await operateStorage({df:JSON.stringify(df_new), lastModifiedDate:Date.now()}, "local", "set");
370370
return df_new;
371371
}

src/script/options.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,14 @@ $(async function () {
6666
repoArea).val(val[1]);
6767
})
6868
})
69-
69+
70+
// enter then search
71+
document.addEventListener("keydown", async function (e) {
72+
if ($(e.target).is("input.inputSearchVal") && e.key == "Enter") {
73+
await searchFunc();
74+
}
75+
})
7076
})
71-
7277
});
7378

7479
// # button
@@ -98,6 +103,11 @@ const numberKey = ["atk", "def", "scale", "level", "id"];
98103
const includeKey=["type", "set"];
99104

100105
$(".btnSearchDB").on("click", async function (e) {
106+
await searchFunc();
107+
108+
})
109+
110+
const searchFunc = async ()=>{
101111
const df=await obtainDF();
102112
let searchKVs = [];
103113
$("span.spanSearchKV").map((ind, obj) => {
@@ -108,7 +118,7 @@ $(".btnSearchDB").on("click", async function (e) {
108118
});
109119
//console.log(searchKVs)
110120
const searcheResults = searchKVs.reduce((df_tmp, cur) => {
111-
const condition = ([...includeKey, "Eng"].indexOf(cur[0])!=-1) ? "in" : "=";
121+
const condition = ([...includeKey, "name"].indexOf(cur[0])!=-1) ? "in" : "=";
112122
const ids = df_filter(df_tmp, "id", cur, condition);
113123
return df_filter(df_tmp, Object.keys(df), ["id", ids])
114124
}, df)
@@ -117,7 +127,7 @@ $(".btnSearchDB").on("click", async function (e) {
117127
searchResultArea.empty();
118128
const table=makeTable(searcheResults, "Search Results");
119129
searchResultArea.append(table)
120-
})
130+
}
121131

122132
$(".btnSearchAdd").on("click", async function (e) {
123133
const df=await obtainDF();

0 commit comments

Comments
 (0)