MazyarTools

Mazyar Tools & Utilities

目前为 2024-10-18 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/513041/1466977/MazyarTools.js

  1. // ==UserScript==
  2. // @name MazyarTools
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Mazyar Tools & Utilities
  6. // @copyright z7z from managerzone.com
  7. // @author z7z from managerzone.com
  8. // @license MIT
  9. // @match https://www.managerzone.com/*
  10. // @match https://test.managerzone.com/*
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=managerzone.com
  12. // @supportURL https://github.com/mz-ir/mazyar
  13. // ==/UserScript==
  14.  
  15. function mazyarParseMzDate(dateString) {
  16. const [day, month, year] = dateString.split('-').map(Number);
  17. return new Date(year, month - 1, day);
  18. }
  19.  
  20. function mazyarParseMzDateTime(dateTimeString) {
  21. const [date, time] = dateTimeString.split(' ');
  22. const [day, month, year] = date.split('-').map(Number);
  23. const [hours, minutes] = time.split(':').map(Number);
  24. return new Date(year, month - 1, day, hours, minutes);
  25. }
  26.  
  27. function mazyarGenerateUuidV4() {
  28. return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
  29. const r = (Math.random() * 16) | 0,
  30. v = c == "x" ? r : (r & 0x3) | 0x8;
  31. return v.toString(16);
  32. });
  33. }
  34.  
  35. function mazyarIsFilterHitsValid(hits) {
  36. return typeof hits === "number" && hits >= 0;
  37. }
  38.  
  39. function mazyarHasDuplicates(array) {
  40. return new Set(array).size !== array.length;
  41. }
  42.  
  43. function mazyarExtractSportType(doc = document) {
  44. const zone = doc.querySelector("a#shortcut_link_thezone");
  45. if (zone) {
  46. return zone.href.indexOf("hockey") > -1 ? "hockey" : "soccer";
  47. }
  48. return "soccer";
  49. }
  50.  
  51. function mazyarExtractClubCurrency(doc) {
  52. const players = doc.getElementById("playerAltViewTable")?.querySelectorAll("tbody tr");
  53. if (players && players.length > 0) {
  54. const parts = players[0].querySelector("td:nth-child(3)")?.innerText.split(" ");
  55. return parts[parts.length - 1].trim();
  56. }
  57. return "";
  58. }
  59.  
  60. function mazyarExtractNationalCurrency(doc) {
  61. // works for both domestic and foreign countries
  62. const playerNode = doc.getElementById("thePlayers_0")?.querySelector("table tbody tr:nth-child(6)");
  63. if (playerNode) {
  64. const parts = playerNode.innerText.split(" ");
  65. return parts[parts.length - 1].trim();
  66. }
  67. return "";
  68. }
  69.  
  70. function mazyarExtractTeamId(link) {
  71. const regex = /tid=(\d+)/;
  72. const match = regex.exec(link);
  73. return match ? match[1] : null;
  74. }
  75.  
  76. function mazyarExtractPlayerIdFromProfileLink(link) {
  77. const regex = /pid=(\d+)/;
  78. const match = regex.exec(link);
  79. return match ? match[1] : null;
  80. }
  81.  
  82. function mazyarExtractMatchId(link) {
  83. const regex = /mid=(\d+)/;
  84. const match = regex.exec(link);
  85. return match ? match[1] : null;
  86. }
  87.  
  88. function mazyarExtractPlayerIdFromTransferMonitor(link) {
  89. const regex = /u=(\d+)/;
  90. const match = regex.exec(link);
  91. return match ? match[1] : null;
  92. }
  93.  
  94. function mazyarExtractPlayerIdFromContainer(player) {
  95. return player?.querySelector("h2 span.player_id_span")?.innerText;
  96. }
  97.  
  98. function mazyarIsMatchInProgress(resultText) {
  99. const scoreRegex = /\b(X|0|[1-9]\d*) - (X|0|[1-9]\d*)\b/;
  100. return !scoreRegex.test(resultText);
  101. }
  102.  
  103. function mazyarGetSquadSummaryLink(tid) {
  104. return `https://${location.hostname}/?p=players&sub=alt&tid=${tid}`;
  105. }
  106.  
  107. function mazyarFormatBigNumber(n, sep = " ") {
  108. if (n) {
  109. const numberString = n.toString();
  110. let formattedParts = [];
  111. for (let i = numberString.length - 1; i >= 0; i -= 3) {
  112. let part = numberString.substring(Math.max(i - 2, 0), i + 1);
  113. formattedParts.unshift(part);
  114. }
  115. return formattedParts.join(sep);
  116. }
  117. return "0";
  118. }
  119.  
  120. function mazyarFormatAverageAge(age, fractionDigits = 1) {
  121. if (age) {
  122. return age.toFixed(fractionDigits);
  123. }
  124. return "0.0";
  125. }
  126.  
  127. function mazyarFormatFileSize(b) {
  128. const s = 1024;
  129. let u = 0;
  130. while (b >= s || -b >= s) {
  131. b /= s;
  132. u++;
  133. }
  134. return (u ? b.toFixed(1) + " " : b) + " KMGTPEZY"[u] + "B";
  135. }
  136.  
  137. function mazyarExtractClubPlayersDetails(doc, currency) {
  138. const players = [];
  139. const playerNodes = doc.querySelectorAll("table#playerAltViewTable tr");
  140. for (const playerNode of playerNodes) {
  141. const age = playerNode.querySelector("td:nth-child(5)")?.innerText.replace(/\s/g, "");
  142. if (age) {
  143. const value = playerNode.querySelector("td:nth-child(3)")?.innerText.replaceAll(currency, "").replace(/\s/g, "");
  144. const shirtNumber = playerNode.querySelector("td:nth-child(0)")?.innerText.replace(/\s/g, "");
  145. const pid = playerNode.querySelector("a")?.href;
  146. players.push({
  147. shirtNumber,
  148. age: parseInt(age, 10),
  149. value: parseInt(value, 10),
  150. id: mazyarExtractPlayerIdFromProfileLink(pid),
  151. });
  152. }
  153. }
  154. return players;
  155. }
  156.  
  157. function mazyarExtractNumberOfFlags(infoTable) {
  158. const images = infoTable.getElementsByTagName("img");
  159. return images ? [...images].filter((img) => img.src.indexOf("/flags/") > -1).length : 0;
  160. }
  161.  
  162. function mazyarIsPlayerDomestic(infoTable) {
  163. return mazyarExtractNumberOfFlags(infoTable) === 1;
  164. }
  165.  
  166. function mazyarExtractNationalPlayersDetails(doc, currency) {
  167. const players = [];
  168. const playerNodes = doc.querySelectorAll("div.playerContainer");
  169. for (const playerNode of playerNodes) {
  170. const id = mazyarExtractPlayerIdFromProfileLink(playerNode.querySelector("h2 a")?.href);
  171. const infoTable = playerNode.querySelector("div.dg_playerview_info table");
  172. const age = infoTable.querySelector("tbody tr:nth-child(1) td strong").innerText;
  173. const selector = mazyarIsPlayerDomestic(infoTable) ? "tbody tr:nth-child(5) td span" : "tbody tr:nth-child(6) td span";
  174. const value = infoTable.querySelector(selector)?.innerText.replaceAll(currency, "").replace(/\s/g, "");
  175. players.push({
  176. age: parseInt(age, 10),
  177. value: parseInt(value, 10),
  178. id,
  179. });
  180. }
  181. return players;
  182. }
  183.  
  184. function mazyarGetNumberOfPlayers(players, ageLow = 0, ageHigh = 99) {
  185. return players.filter((player) => player.age <= ageHigh && player.age >= ageLow).length;
  186. }
  187.  
  188. function mazyarFilterPlayers(players, count = 0, ageLow = 0, ageHigh = 99) {
  189. if (players.length === 0) {
  190. return { values: 0, avgAge: 0.0 };
  191. }
  192.  
  193. const n = count === 0 ? players.length : count;
  194. const filtered = players
  195. .filter((player) => player.age <= ageHigh && player.age >= ageLow)
  196. .sort((a, b) => b.value - a.value)
  197. .slice(0, n);
  198. if (filtered.length === 0) {
  199. return { values: 0, avgAge: 0.0 };
  200. }
  201. const values = filtered.map((player) => player.value).reduce((a, b) => a + b, 0);
  202. const avgAge = filtered.map((player) => player.age).reduce((a, b) => a + b, 0) / filtered.length;
  203. return { values, avgAge };
  204. }
  205.  
  206. async function mazyarFetchNationalPlayersAndCurrency(tid, sport) {
  207. const url = `https://${location.hostname}/ajax.php?p=nationalTeams&sub=players&ntid=${tid}&sport=${sport}`;
  208. let players = [];
  209. let currency = '';
  210. await fetch(url)
  211. .then((resp) => resp.text())
  212. .then((content) => {
  213. const parser = new DOMParser();
  214. const doc = parser.parseFromString(content, "text/html");
  215. currency = mazyarExtractNationalCurrency(doc);
  216. players = mazyarExtractNationalPlayersDetails(doc, currency);
  217. })
  218. .catch((error) => {
  219. console.warn(error);
  220. });
  221. return { players, currency };
  222. }
  223.  
  224. async function mazyarFetchClubPlayersAndCurrency(tid) {
  225. const url = mazyarGetSquadSummaryLink(tid);
  226. let players = [];
  227. let currency = '';
  228. await fetch(url)
  229. .then((resp) => resp.text())
  230. .then((content) => {
  231. const parser = new DOMParser();
  232. const doc = parser.parseFromString(content, "text/html");
  233. currency = mazyarExtractClubCurrency(doc);
  234. players = mazyarExtractClubPlayersDetails(doc, currency);
  235. })
  236. .catch((error) => {
  237. console.warn(error);
  238. });
  239. return { players, currency };
  240. }
  241.  
  242. async function mazyarFetchPlayersAndCurrency(tid, sport) {
  243. const url = mazyarGetSquadSummaryLink(tid);
  244. const isNational = await fetch(url, { method: "HEAD" })
  245. .then((resp) => (resp.url.search("p=national_teams") > -1));
  246. return isNational ? await mazyarFetchNationalPlayersAndCurrency(tid, sport) : await mazyarFetchClubPlayersAndCurrency(tid);
  247. }
  248.  
  249. function mazyarExtractClubTopPlyers(doc) {
  250. const currency = mazyarExtractClubCurrency(doc);
  251. const players = mazyarExtractClubPlayersDetails(doc, currency);
  252. const sport = mazyarExtractSportType(doc);
  253. const count = sport === "soccer" ? 11 : 21;
  254. return players ? mazyarFilterPlayers(players, count) : { values: 0, avgAge: 0 };
  255. }
  256.  
  257. async function mazyarExtractPlayersProfileDetails(teamId) {
  258. const url = `https://${location.hostname}/?p=players&tid=${teamId}`;
  259. return await fetch(url)
  260. .then((resp) => {
  261. return resp.text();
  262. }).then((content) => {
  263. const parser = new DOMParser();
  264. const doc = parser.parseFromString(content, "text/html");
  265. const players = doc.getElementById("players_container")?.querySelectorAll("div.playerContainer");
  266. const info = {};
  267. for (const player of players) {
  268. const playerId = player.querySelector("span.player_id_span")?.innerText;
  269. const inMarket = [...player.querySelectorAll("a")].find((el) => el.href?.indexOf("p=transfer&sub") > -1);
  270. info[playerId] = {
  271. detail: player,
  272. shared: !!player.querySelector("i.special_player.fa-share-alt"),
  273. market: !!inMarket,
  274. marketLink: inMarket?.href,
  275. }
  276. }
  277. return info;
  278. }).catch((error) => {
  279. console.warn(error);
  280. return null;
  281. });
  282. }
  283.  
  284. function mazyarExtractSquadSummaryDetails(players, sport = "soccer") {
  285. if (!players) {
  286. return [];
  287. }
  288. const rows = [];
  289. if (sport === "hockey") {
  290. {
  291. const all = mazyarFilterPlayers(players);
  292. const top21 = mazyarFilterPlayers(players, 21);
  293. rows.push({
  294. title: "All",
  295. count: players.length,
  296. all: all.values,
  297. allAge: all.avgAge,
  298. top21: top21.values,
  299. top21Age: top21.avgAge,
  300. });
  301. }
  302. {
  303. const all = mazyarFilterPlayers(players, 0, 0, 23);
  304. const top21 = mazyarFilterPlayers(players, 21, 0, 23);
  305. rows.push({
  306. title: "U23",
  307. count: mazyarGetNumberOfPlayers(players, 0, 23),
  308. all: all.values,
  309. allAge: all.avgAge,
  310. top21: top21.values,
  311. top21Age: top21.avgAge,
  312. });
  313. }
  314. {
  315. const all = mazyarFilterPlayers(players, 0, 0, 21);
  316. const top21 = mazyarFilterPlayers(players, 21, 0, 21);
  317. rows.push({
  318. title: "U21",
  319. count: mazyarGetNumberOfPlayers(players, 0, 21),
  320. all: all.values,
  321. allAge: all.avgAge,
  322. top21: top21.values,
  323. top21Age: top21.avgAge,
  324. });
  325. }
  326. {
  327. const all = mazyarFilterPlayers(players, 0, 0, 18);
  328. const top21 = mazyarFilterPlayers(players, 21, 0, 18);
  329. rows.push({
  330. title: "U18",
  331. count: mazyarGetNumberOfPlayers(players, 0, 18),
  332. all: all.values,
  333. allAge: all.avgAge,
  334. top21: top21.values,
  335. top21Age: top21.avgAge,
  336. });
  337. }
  338. } else {
  339. {
  340. const all = mazyarFilterPlayers(players);
  341. const top16 = mazyarFilterPlayers(players, 16);
  342. const top11 = mazyarFilterPlayers(players, 11);
  343. rows.push({
  344. title: "All",
  345. count: players.length,
  346. all: all.values,
  347. allAge: all.avgAge,
  348. top16: top16.values,
  349. top16Age: top16.avgAge,
  350. top11: top11.values,
  351. top11Age: top11.avgAge,
  352. });
  353. }
  354. {
  355. const all = mazyarFilterPlayers(players, 0, 0, 23);
  356. const top16 = mazyarFilterPlayers(players, 16, 0, 23);
  357. const top11 = mazyarFilterPlayers(players, 11, 0, 23);
  358. rows.push({
  359. title: "U23",
  360. count: mazyarGetNumberOfPlayers(players, 0, 23),
  361. all: all.values,
  362. allAge: all.avgAge,
  363. top16: top16.values,
  364. top16Age: top16.avgAge,
  365. top11: top11.values,
  366. top11Age: top11.avgAge,
  367. });
  368. }
  369. {
  370. const all = mazyarFilterPlayers(players, 0, 0, 21);
  371. const top16 = mazyarFilterPlayers(players, 16, 0, 21);
  372. const top11 = mazyarFilterPlayers(players, 11, 0, 21);
  373. rows.push({
  374. title: "U21",
  375. count: mazyarGetNumberOfPlayers(players, 0, 21),
  376. all: all.values,
  377. allAge: all.avgAge,
  378. top16: top16.values,
  379. top16Age: top16.avgAge,
  380. top11: top11.values,
  381. top11Age: top11.avgAge,
  382. });
  383. }
  384. {
  385. const all = mazyarFilterPlayers(players, 0, 0, 18);
  386. const top16 = mazyarFilterPlayers(players, 16, 0, 18);
  387. const top11 = mazyarFilterPlayers(players, 11, 0, 18);
  388. rows.push({
  389. title: "U18",
  390. count: mazyarGetNumberOfPlayers(players, 0, 18),
  391. all: all.values,
  392. allAge: all.avgAge,
  393. top16: top16.values,
  394. top16Age: top16.avgAge,
  395. top11: top11.values,
  396. top11Age: top11.avgAge,
  397. });
  398. }
  399. }
  400. return rows;
  401. }
  402.  
  403. async function mazyarFetchDocument(url) {
  404. return await fetch(url)
  405. .then((resp) => resp.text())
  406. .then((content) => {
  407. const parser = new DOMParser();
  408. return parser.parseFromString(content, "text/html");
  409. })
  410. .catch((error) => {
  411. console.warn(error);
  412. return null;
  413. });
  414. }
  415.  
  416. async function mazyarFetchJson(url) {
  417. return await fetch(url)
  418. .then((resp) => resp.json())
  419. .catch((error) => {
  420. console.warn(error);
  421. return null;
  422. });
  423. }
  424.  
  425. async function mazyarFetchPlayerProfileDocument(playerId) {
  426. const url = `https://${location.hostname}/?p=players&pid=${playerId}`;
  427. return await mazyarFetchDocument(url);
  428. }
  429.  
  430. async function mazyarFetchTransferMonitorData(sport = "soccer") {
  431. const url = `https://${location.hostname}/ajax.php?p=transfer&sub=your-bids&sport=${sport}`;
  432. return await mazyarFetchJson(url);
  433. }
  434.  
  435. async function mazyarFetchSquadSummaryDocument(teamId) {
  436. const url = mazyarGetSquadSummaryLink(teamId);
  437. return await mazyarFetchDocument(url);
  438. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址