-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTitech Fill Matrix.js
65 lines (53 loc) · 1.66 KB
/
Titech Fill Matrix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// ==UserScript==
// @name Titech Fill Matrix
// @description This is your new file, start writing code
// @include *://portal.nap.gsic.titech.ac.jp/GetAccess/Login?Template=idg_key&AUTHMETHOD=IG&GASF=CERTIFICATE*
// @run-at document-end
// ==/UserScript==
function getElementByXpath(path) {
return document.evaluate(
path,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
}
function fillMatrix() {
const okPath = '//*[@id="authentication"]/tbody/tr[9]/td/input[1]';
const okButton = getElementByXpath(okPath);
const matrix = {
A: ["j", "l", "h", "x", "i", "h", "l"],
// B: ["h", "l", "h", "x", "i", "h", "l"],
}; // TODO: Fill your matrix here
const mPaths = [
'//*[@id="authentication"]/tbody/tr[5]/td/div/div/input',
'//*[@id="authentication"]/tbody/tr[6]/td/div/div/input',
'//*[@id="authentication"]/tbody/tr[7]/td/div/div/input',
];
const vPaths_1 = [
'//*[@id="authentication"]/tbody/tr[5]/th[1]',
'//*[@id="authentication"]/tbody/tr[6]/th[1]',
'//*[@id="authentication"]/tbody/tr[7]/th[1]',
];
const vPaths_2 = [
'//*[@id="authentication"]/tbody/tr[5]/td',
'//*[@id="authentication"]/tbody/tr[6]/td',
'//*[@id="authentication"]/tbody/tr[7]/td',
];
const vPaths =
getElementByXpath(vPaths_1[0]).innerText.trim() === ""
? vPaths_2
: vPaths_1;
const values = vPaths.map((path) => {
const innerText = getElementByXpath(path).innerText.trim();
return { i: innerText[1], j: parseInt(innerText[3]) };
});
mPaths.map((path, i) => {
const input = getElementByXpath(path);
const value = values[i];
input.value = matrix[value.i][value.j - 1];
});
okButton.click();
}
fillMatrix();