forked from AnneTrue/nexus-clash-interface-tweaks
-
Notifications
You must be signed in to change notification settings - Fork 2
/
betterFactionPage.js
69 lines (62 loc) · 2.28 KB
/
betterFactionPage.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
66
67
68
69
const betterFactionPage = {
module: async (api) => {
const mod = await api.registerModule(
'betterFactionPage',
'Better Faction Page',
'global',
'Displays the faction\'s roster and politics directly on the main faction\'s page.',
);
const betterFactionPage = () => {
const factionIDmatch = window.location.search.match(/\?op=faction&do=view&id=(\d*)/);
if (!factionIDmatch) {
mod.debug('Not on a faction\'s page');
return;
}
factionID = factionIDmatch[1];
const roster = document.createElement('div');
const politics = document.createElement('div');
roster.innerHTML = `
<iframe
style='border: 0px; width: 45%; height: 400px;'
src='/clash.php?op=faction&do=roster&faction_id=${factionID}'
onload='
let fetchRoster = this.contentWindow.document.body.querySelector(".content>table");
this.contentWindow.document.body.innerHTML = "";
this.replaceWith(fetchRoster);
'
hidden=true
>
</iframe>
`;
politics.innerHTML = `
<iframe
style='border: 0px; width: 45%; height: 400px;'
src='/clash.php?op=faction&do=politics&faction_id=${factionID}'
onload='
let fetchPolitics = this.contentWindow.document.body.querySelectorAll(".content>p");
this.contentWindow.document.body.innerHTML = "";
this.replaceWith(fetchPolitics[0], fetchPolitics[1]);
'
hidden=true
>
</iframe>
`;
roster.insertBefore(document.createElement('h2'), roster.firstElementChild).innerHTML = '<b>Roster</b>';
roster.className = 'content';
roster.style.display = 'inline-block';
roster.style.width = '50%';
roster.style.verticalAlign = 'top';
politics.insertBefore(document.createElement('h2'), politics.firstElementChild).innerHTML = '<b>Faction Politics</b>';
politics.className = 'content';
politics.style.display = 'inline-block';
politics.style.width = '50%';
politics.style.verticalAlign = 'top';
document.body.querySelector('form[name="roster"]').replaceWith(roster);
document.body.querySelector('form[name="roster"]').replaceWith(politics);
}
await mod.registerMethod(
'sync',
betterFactionPage
);
}
}