FF Progs

Improves FFlogs.

当前为 2025-02-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name FF Progs
  3. // @name:en FF Progs
  4. // @description Improves FFlogs.
  5. // @description:en Improves FFlogs.
  6. // @version 1.4.1
  7. // @namespace k_fizzel
  8. // @author Chad Bradly
  9. // @website https://www.fflogs.com/character/id/12781922
  10. // @icon https://assets.rpglogs.com/img/ff/favicon.png?v=2
  11. // @match https://*.fflogs.com/*
  12. // @require https://code.jquery.com/jquery-3.2.0.min.js
  13. // @grant unsafeWindow
  14. // @grant GM_addStyle
  15. // @grant GM_getValue
  16. // @grant GM_setValue
  17. // @grant GM_deleteValue
  18. // @license MIT License
  19. // ==/UserScript==
  20.  
  21. (function () {
  22. "use strict";
  23.  
  24. // If you want to add more filter expression presets, you can add them here.
  25. const PIN_PRESETS = {
  26. "No Filter": "",
  27. calulateddamage: "type='calculateddamage'",
  28. damage: "type='damage'",
  29. cast: "type='cast'",
  30. Targetability: "type='targetabilityupdate'",
  31. GCD: "ability.isOffGCD=false",
  32. "Kill Event": "kill",
  33. LB: `2$Main$#ffff14$script$let l;pinMatchesFightEvent=(e,f)=>{switch(e.type){case"limitbreakupdate":return l&&l===e.timestamp||(l=e.timestamp),!0;case"calculateddamage":if("Player"===e.target.type&&e.timestamp===l)return!0;break;case"heal":if(!e.isTick&&e.timestamp===l)return!0}return!1};`,
  34. Magical: "ability.type=1024",
  35. Physical: "ability.type=128",
  36. Heal: "ability.type=8",
  37. DOT: "ability.type=64",
  38. "Buff/Debuff": "ability.type=1",
  39. Darkness: "ability.type=124",
  40. True: "ability.type=32",
  41. System: "ability.type=0",
  42. };
  43.  
  44. const ABILITY_TYPES = {
  45. 0: "System",
  46. 1: "Buff/Debuff",
  47. // 2: "Unknown",
  48. // 4: "Unknown",
  49. 8: "Heal",
  50. // 16: "Unknown",
  51. 32: "True",
  52. 64: "DOT",
  53. 124: "Darkness",
  54. // 125: "Darkness?",
  55. // 126: "Darkness?",
  56. // 127: "Darkness?",
  57. 128: "Physical",
  58. // 256: "Magical?",
  59. // 512: "Unknown",
  60. 1024: "Magical",
  61. };
  62. const PASSIVE_LB_GAIN = [
  63. ["75"], // one bar
  64. ["180"], // two bars
  65. ["220", "170", "160", "154", "144", "140"], // three bars
  66. ];
  67.  
  68. const REPORTS_PATH_REGEX = /\/reports\/.+/;
  69. const ZONE_RANKINGS_PATH_REGEX = /\/zone\/rankings\/.+/;
  70. const CHARACTER_PATH_REGEX = /\/character\/.+/;
  71. const PROFILE_PATH_REGEX = /\/profile/;
  72. const LB_REGEX = /The limit break gauge updated to (\d+). There are (\d+) total bars./;
  73. const apiKey = GM_getValue("apiKey");
  74.  
  75. const getQueryParams = () => {
  76. const queryParams = new URLSearchParams(window.location.search);
  77. const params = Object.fromEntries(queryParams.entries());
  78. return params;
  79. };
  80.  
  81. const changeQueryParams = (defaultParams) => {
  82. const url = new URL(window.location);
  83.  
  84. const queryParams = new URLSearchParams(url.search);
  85.  
  86. Object.entries(defaultParams).forEach(([key, value]) => {
  87. if (value !== null && value !== undefined && value !== "") {
  88. queryParams.set(key, value);
  89. } else {
  90. queryParams.delete(key);
  91. }
  92. });
  93.  
  94. changeView(queryParams);
  95. };
  96.  
  97. const updateTable = (onTableChange) => {
  98. const tableContainer = document.querySelector("#table-container");
  99. if (tableContainer) {
  100. const observer = new MutationObserver(onTableChange);
  101. observer.observe(tableContainer, {
  102. attributes: true,
  103. characterData: true,
  104. childList: true,
  105. });
  106. }
  107. };
  108.  
  109. function parseTime(cell) {
  110. const [_, sign, m, s, ms] = $(cell)
  111. .text()
  112. .match(/(-?)(\d+):(\d+)\.(\d+)/);
  113. const totalMs = (+m * 60000 + +s * 1000 + +ms) * (sign === "-" ? -1 : 1);
  114. return totalMs;
  115. }
  116.  
  117. const characterAllStar = (rank, outOf, rDPS, rankOneRDPS) => {
  118. return Math.min(Math.max(100 * (rDPS / rankOneRDPS), 100 - (rank / outOf) * 100) + 20 * (rDPS / rankOneRDPS), 120);
  119. };
  120.  
  121. // AdBlock
  122. $(
  123. "#top-banner, .side-rail-ads, #bottom-banner, #subscription-message-tile-container, #playwire-video-container, #right-ad-box, #right-vertical-banner, #gear-box-ad, .ad-placement-sticky-footer, .content-sidebar, #ap-ea8a4fe5-container"
  124. ).remove();
  125. $(".content-with-sidebar").css("display", "block");
  126. $("#table-container").css("margin", "0 0 0 0");
  127.  
  128. // Reports Page
  129. if (REPORTS_PATH_REGEX.test(location.pathname)) {
  130. // Add XIV Analysis Button
  131. $("#filter-analyze-tab").before(
  132. `<a target="_blank" class="big-tab view-type-tab" id="xivanalysis-tab"><span class="zmdi zmdi-time-interval"></span> <span class="big-tab-text"><br>xivanalysis</span></a>`
  133. );
  134. $("#xivanalysis-tab").on("click", () => {
  135. window.open(`https://xivanalysis.com/report-redirect/${location.href}`, "_blank");
  136. });
  137.  
  138. if (!$("#filter-rankings-tab").length) {
  139. $("#filter-replay-tab").before(
  140. `<a href="#" class="big-tab view-type-tab" id="filter-rankings-tab" onclick="return changeFilterView('rankings', this)" oncontextmenu="changeFilterView('rankings', this)"><span class="zmdi zmdi-sort"></span><span class="big-tab-text"><br>Rankings</span></a>`
  141. );
  142. }
  143.  
  144. // Fixes Cursor behavior on Filter Type Tabs
  145. $("#filter-type-tabs").css("cursor", "default");
  146.  
  147. const rankOnes = {};
  148. let jobs;
  149.  
  150. const onTableChange = () => {
  151. let queryParams = getQueryParams();
  152. let lastLbGain;
  153. let lastTimeDiff;
  154. let lastSkillName;
  155. let lastSelectedPreset;
  156.  
  157. // Filter Presets
  158. if (!queryParams.view || queryParams.view === "events" || queryParams.view === "timeline" || queryParams.view === "execution") {
  159. if (!$("#presets").length) {
  160. $("#graph-title-strip > div:first-child").after(
  161. `<div style="margin-left: auto; padding-right: 8px;" id="presets">
  162. No Overwrite:
  163. <input type="checkbox" id="no-overwrite" style="margin-right: 8px;">
  164. Filter Presets:
  165. <select id="presets-select" style="margin-right: 8px;">
  166. ${Object.entries(PIN_PRESETS)
  167. .map(([name, pin]) => `<option value="${pin}">${name}</option>`)
  168. .join("")}
  169. </select>
  170. </div>`
  171. );
  172.  
  173. $("#presets-select").on("change", (e) => {
  174. const selected = $("#presets-select").val();
  175. const name = $("#presets-select option:selected").text();
  176.  
  177. if (!selected) {
  178. changeQueryParams({
  179. type: "",
  180. view: "",
  181. source: "",
  182. hostility: "",
  183. pins: "",
  184. start: "",
  185. end: "",
  186. });
  187. lastSelectedPreset = null;
  188. return;
  189. }
  190. if (name === "LB") {
  191. changeQueryParams({
  192. type: "summary",
  193. view: "events",
  194. source: "",
  195. pins: PIN_PRESETS.LB,
  196. });
  197. lastSelectedPreset = name
  198. return;
  199. }
  200. if (name === "Kill Event") {
  201. changeQueryParams({
  202. type: "resources",
  203. view: "events",
  204. source: "",
  205. hostility: "1",
  206. pins: "",
  207. start: fightSegmentEndTime - 5 * 1000,
  208. end: fightSegmentEndTime,
  209. });
  210. lastSelectedPreset = name
  211. return;
  212. }
  213. const pinTemplate = `2$Off$#244F4B$expression$${selected}`;
  214. if ($("#no-overwrite").is(":checked") && lastSelectedPreset !== "LB" && lastSelectedPreset !== "Kill Event") {
  215. queryParams = getQueryParams();
  216. changeQueryParams({ pins: queryParams.pins ? `${queryParams.pins}^${pinTemplate}` : pinTemplate });
  217. } else {
  218. changeQueryParams({ pins: pinTemplate });
  219. }
  220. lastSelectedPreset = name
  221. });
  222. }
  223. }
  224.  
  225. // Rankings Tab
  226. if (queryParams.view === "rankings") {
  227. if (!GM_getValue("apiKey")) return;
  228. const rows = [];
  229. if (!jobs) {
  230. fetch(`https://www.fflogs.com/v1/classes?api_key=${GM_getValue("apiKey")}`)
  231. .then((res) => res.json())
  232. .then((data) => {
  233. jobs = data[0].specs;
  234. rows.forEach((row) => {
  235. updatePoints(row);
  236. });
  237. })
  238. .catch((err) => console.error(err));
  239. } else {
  240. setTimeout(() => {
  241. rows.forEach((row) => {
  242. updatePoints(row);
  243. });
  244. }, 0);
  245. }
  246.  
  247. const updatePoints = async (row) => {
  248. const queryParams = getQueryParams();
  249. const rank = Number($(row).find("td:nth-child(2)").text().replace("~", ""));
  250. const outOf = Number($(row).find("td:nth-child(3)").text().replace(",", ""));
  251. const dps = Number($(row).find("td:nth-child(6)").text().replace(",", ""));
  252. const jobName = $(row).find("td:nth-child(5) > a").attr("class") || "";
  253. const jobName2 = $(row).find("td:nth-child(5) > a:nth-last-child(1)").attr("class") || "";
  254. const playerMetric = queryParams.playermetric || "rdps";
  255.  
  256. if (jobName2 !== "players-table-realm") {
  257. $(row)
  258. .find("td:nth-child(7)")
  259. .html(`<center><img src="https://cdn.7tv.app/emote/62523dbbbab59cfd1b8b889d/1x.webp" title="No api v1 endpoint for combined damage." style="height: 15px;"></center>`);
  260. return;
  261. }
  262.  
  263. const updateCharecterAllStar = async () => {
  264. $(row).find("td:nth-child(7)").html(characterAllStar(rank, outOf, dps, rankOnes[jobName][playerMetric]).toFixed(2));
  265. };
  266.  
  267. if (!rankOnes[jobName]) {
  268. rankOnes[jobName] = {};
  269. }
  270.  
  271. if (!rankOnes[jobName][playerMetric]) {
  272. const url = `https://www.fflogs.com/v1/rankings/encounter/${reportsCache.filterFightBoss}?metric=${playerMetric}&spec=${
  273. jobs.find((job) => job.name.replace(" ", "") === jobName)?.id
  274. }&api_key=${GM_getValue("apiKey")}`;
  275. fetch(url)
  276. .then((res) => res.json())
  277. .then((data) => {
  278. rankOnes[jobName][playerMetric] = Number(data.rankings[0].total.toFixed(1));
  279. updateCharecterAllStar();
  280. })
  281. .catch((err) => console.error(err));
  282. } else {
  283. updateCharecterAllStar();
  284. }
  285. };
  286.  
  287. $(".player-table").each((_i, table) => {
  288. $(table)
  289. .find("thead tr th:nth-child(6)")
  290. .after(
  291. `<th class="sorting ui-state-default" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Patch: activate to sort column ascending"><div class="DataTables_sort_wrapper">Points<span class="DataTables_sort_icon css_right ui-icon ui-icon-caret-2-n-s"></span></div></th>`
  292. );
  293. $(table)
  294. .find("tbody tr")
  295. .each((_i, row) => {
  296. $(row)
  297. .find("td:nth-child(6)")
  298. .after(`<td class="rank-per-second primary main-table-number"><center><span class="zmdi zmdi-spinner zmdi-hc-spin" style="color:white font-size:24px"></center></span></td>`);
  299. rows.push(row);
  300. });
  301. });
  302. }
  303.  
  304. // Events Tab
  305. if (queryParams.view === "events") {
  306. if (queryParams.type === "resources") {
  307. return;
  308. }
  309. $(".events-table")
  310. .find("thead tr th:nth-child(1)")
  311. .after(`<th class="ui-state-default sorting_disabled" rowspan="1" colspan="1"><div class="DataTables_sort_wrapper">Diff<span class="DataTables_sort_icon"></span></div></th>`);
  312.  
  313. $(".main-table-number").each((_i, cell) => {
  314. if (lastTimeDiff !== undefined) {
  315. const time = parseTime(cell);
  316. const diff = ((time - lastTimeDiff) / 1000).toFixed(3);
  317. const whiteListlastSkill = ["Ten", "Chi", "Jin", "Savage Claw"];
  318. const whiteListSkill = ["Quadruple Technical Finish", "Pneuma", "Star Prism"];
  319. let bgColor = "";
  320. const skillName = $(cell).next().next().find("a").text();
  321. if (queryParams.type === "casts" && !!queryParams.source && !whiteListlastSkill.includes(lastSkillName) && !!lastSkillName && !whiteListSkill.includes(skillName) && !!skillName) {
  322. if (diff < 0.576 && diff > 0.2) {
  323. bgColor = "background-color: chocolate !important;";
  324. }
  325. if (diff > 5) {
  326. bgColor = "background-color: gray !important;";
  327. }
  328. }
  329. lastSkillName = skillName;
  330. $(cell).after(`<td style="width: 2em; text-align: right; ${bgColor}">${diff}</td>`);
  331. lastTimeDiff = time;
  332. } else {
  333. $(cell).after(`<td style="width: 2em; text-align: right;"> - </td>`);
  334. lastTimeDiff = parseTime(cell);
  335. }
  336. });
  337.  
  338. if (queryParams.type === "casts" && queryParams.hostility === "1") {
  339. $(".event-ability-cell a").each((_i, cell) => {
  340. const actionId = $(cell).attr("href").split("/")[5];
  341. const hexId = parseInt(actionId).toString(16);
  342. $(cell).text(`${$(cell).text()} [${hexId}]`);
  343. });
  344. }
  345. }
  346.  
  347. // LB Pin
  348. if (queryParams.view === "events" && queryParams.type === "summary" && queryParams.pins === PIN_PRESETS.LB) {
  349. $(".events-table")
  350. .find("thead tr th:nth-last-child(3)")
  351. .after(`<th class="ui-state-default sorting_disabled" rowspan="1" colspan="1"><div class="DataTables_sort_wrapper">Active<span class="DataTables_sort_icon"></span></div></th>`);
  352. $(".events-table")
  353. .find("thead tr th:nth-last-child(2)")
  354. .after(`<th class="ui-state-default sorting_disabled" rowspan="1" colspan="1"><div class="DataTables_sort_wrapper">Bars<span class="DataTables_sort_icon"></span></div></th>`);
  355.  
  356. $(".event-description-cell").each((_i, cell) => {
  357. const text = $(cell).text();
  358. if (text === "Event") {
  359. $(cell).html(`<div class="DataTables_sort_wrapper">Limit Break Total<span class="DataTables_sort_icon"></span></div>`);
  360. return;
  361. }
  362.  
  363. if (!LB_REGEX.test(text)) {
  364. $(cell).before(`<td style="width: 2em; text-align: right; white-space: nowrap;"> * </td>`);
  365. $(cell).after(`<td style="width: 2em; text-align: right;"> * </td>`);
  366. return;
  367. }
  368.  
  369. const lb = text.match(LB_REGEX);
  370. const currentLb = Number(lb?.[1]);
  371. const currentBars = Number(lb?.[2]);
  372.  
  373. if (lb) {
  374. let diff;
  375. if (lastLbGain !== undefined) {
  376. diff = (currentLb - lastLbGain).toLocaleString();
  377. } else {
  378. diff = " - ";
  379. }
  380. lastLbGain = currentLb;
  381. let actualDiff = diff > 0 ? `+${diff}` : diff;
  382.  
  383. if (PASSIVE_LB_GAIN[currentBars - 1].includes(diff)) {
  384. // passive lb gain
  385. diff = " - ";
  386. } else {
  387. // active lb gain
  388. }
  389.  
  390. $(cell).before(`<td style="width: 2em; text-align: right; white-space: nowrap;">${diff}</td>`);
  391. $(cell).html(`${Number(currentLb).toLocaleString()} / ${(Number(currentBars) * 10000).toLocaleString()} <span style="float: right;">${actualDiff}</span>`);
  392. $(cell).after(`<td style="width: 2em; text-align: right;">${currentBars}</td>`);
  393. }
  394. });
  395. }
  396. };
  397.  
  398. updateTable(onTableChange);
  399. }
  400.  
  401. // Zone Rankings Page
  402. if (ZONE_RANKINGS_PATH_REGEX.test(location.pathname)) {
  403. const onTableChange = () => {
  404. // Auto Translate Report Links
  405. $(".main-table-name").each((_i, cell) => {
  406. if ($(cell).find(".main-table-guild").attr("href").includes("translate=true")) return;
  407. if ($(cell).find(".main-table-guild").attr("href").includes("guild")) return;
  408. $(cell)
  409. .find(".main-table-guild")
  410. .attr("href", `${$(cell).find(".main-table-guild").attr("href")}&translate=true`);
  411. });
  412. };
  413.  
  414. onTableChange();
  415. updateTable(onTableChange);
  416. }
  417.  
  418. // Character Page
  419. if (CHARACTER_PATH_REGEX.test(location.pathname)) {
  420. // Chad Bradly's Profile Customization
  421. const CHAD_ID_REGEX = /\/character\/id\/12781922/;
  422. const CHAD_NAME_REGEX = /\/character\/na\/sargatanas\/chad%20bradly/;
  423. const CHAD_ICON_URL = "https://media.tenor.com/epNMHGvRyHcAAAAd/gigachad-chad.gif";
  424.  
  425. if (CHAD_ID_REGEX.test(location.pathname) || CHAD_NAME_REGEX.test(location.pathname)) {
  426. $("#character-portrait-image").attr("src", CHAD_ICON_URL);
  427. }
  428. }
  429.  
  430. // Profile Page
  431. if (PROFILE_PATH_REGEX.test(location.pathname)) {
  432. const $extension = $(`
  433. <div id="extension" class="dialog-block">
  434. <div id="extension-title" class="dialog-title">FF Progs</div>
  435. <div id="extension-content" style="margin:1em"></div>
  436. </div>
  437. `);
  438.  
  439. const $apiInputContainer = $(`
  440. <div id="api-input-container" style="margin:1em">
  441. <div>Enter your FFLogs API Key</div>
  442. <input type="text" id="api-key-input" style="margin-left: 10px" value="${apiKey || ""}">
  443. <input type="button" id="api-save-button" style="margin-left: 10px" value="${apiKey ? "Update API Key" : "Save API Key"}">
  444. </div>
  445. `);
  446.  
  447. const $apiStatus = $(`
  448. <div id="api-status" style="margin:1em; display: ${apiKey ? "block" : "none"}">
  449. <div>API Key ${apiKey ? "saved" : "not saved"}</div>
  450. <input type="button" id="api-remove-button" style="margin-left: 10px" value="Remove API Key">
  451. </div>
  452. `);
  453.  
  454. const saveApiKey = () => {
  455. const newApiKey = $("#api-key-input").val().trim();
  456. if (newApiKey) {
  457. GM_setValue("apiKey", newApiKey);
  458. $apiStatus.show().find("div").text("API Key saved");
  459. $apiInputContainer.hide();
  460. setTimeout(() => {
  461. $apiStatus.hide();
  462. $apiInputContainer.show();
  463. }, 2000);
  464. }
  465. };
  466.  
  467. const removeApiKey = () => {
  468. GM_deleteValue("apiKey");
  469. $apiStatus.show().find("div").text("API Key removed");
  470. $apiStatus.find("#api-remove-button").remove();
  471. $apiInputContainer.show();
  472. setTimeout(() => {
  473. $apiStatus.hide();
  474. }, 2000);
  475. };
  476.  
  477. $extension.insertAfter("#api");
  478. $apiInputContainer.appendTo("#extension-content");
  479. $apiStatus.appendTo("#extension-content");
  480.  
  481. $apiInputContainer.on("click", "#api-save-button", saveApiKey);
  482. $apiStatus.on("click", "#api-remove-button", removeApiKey);
  483. }
  484. })();