Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Linkifier Bookmarklet For https://aoe2.net/ to https://ratings.aoe2.se/
let isMyMatchesPage = window.location.href.includes(
"aoe2de-matches-my-recent-matches"
);
let isProfilePage = window.location.href.includes("profile-");
let COL_INDEX = undefined;
let LINK_LOCATION_PREFIX = undefined;
let LINK_LOCATION_POSTFIX = undefined;
let TABLE = undefined;
if (isMyMatchesPage) {
COL_INDEX = 3;
LINK_LOCATION_PREFIX = "#aoe2de-matches-table > tbody > tr:nth-child(";
LINK_LOCATION_POSTFIX = ") > td:nth-child(1)";
TABLE = "#aoe2de-matches-table";
} else if (isProfilePage) {
COL_INDEX = 1;
LINK_LOCATION_PREFIX = "#profile-matches-table > tbody > tr:nth-child(";
LINK_LOCATION_POSTFIX = ") > td:nth-child(1) > h5";
TABLE = "#profile-matches-table";
} else {
throw new Error(
"Unrecognized page, doing nothing..." +
isMyMatchesPage +
" " +
isProfilePage
);
}
for (
let i = 0;
i < document.querySelectorAll(TABLE + " > tbody > tr").length;
i++
) {
let teamOne = [];
let teamTwo = [];
for (
let j = 0;
j <
document.querySelectorAll(
`${TABLE} > tbody > tr:nth-child(${
i + 1
}) > td:nth-child(${COL_INDEX}) > table > tbody > tr`
).length;
j++
) {
let players = document.querySelectorAll(
`${TABLE} > tbody > tr:nth-child(${
i + 1
}) > td:nth-child(${COL_INDEX}) > table > tbody > tr:nth-child(${
j + 1
}) > td.player-name`
);
let teamOnePlayer = players[0];
let teamTwoPlayer = players[1];
if (teamOnePlayer) {
let profileId = teamOnePlayer.innerHTML.split("'")[5];
teamOne.push(profileId);
}
if (teamTwoPlayer) {
let profileId = teamTwoPlayer.innerHTML.split("'")[5];
teamTwo.push(profileId);
}
}
let link = `https://ratings.aoe2.se/?team_one=${teamOne.join(
"-"
)}&team_two=${teamTwo.join("-")}`;
let type = document.querySelector(
LINK_LOCATION_PREFIX + (i + 1) + LINK_LOCATION_POSTFIX
);
type.innerHTML = `<a title="" href="${link}">${type.innerText}</a>`;
("done");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment