命运2赛季切换工具

命运2赛季切换工具,可前往更久远的赛季,领取对应奖励。

  1. // ==UserScript==
  2. // @name 命运2赛季切换工具
  3. // @namespace https://moegarden.com/
  4. // @version 0.0.1
  5. // @description 命运2赛季切换工具,可前往更久远的赛季,领取对应奖励。
  6. // @author MoeHero
  7. // @run-at document-start
  8. // @match https://www.bungie.net/*/Seasons/PreviousSeason
  9. // @icon https://www.bungie.net/favicon.ico
  10. // @license MIT License
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. console.log('命运2赛季切换工具:脚本加载成功!版本:V0.0.1');
  15. function getSeasons() {
  16. return new Promise((resolve, reject) => {
  17. let db;
  18. let seasons = [];
  19. const request = indexedDB.open('Destiny');
  20. request.onerror = reject;
  21. request.onsuccess = (event) => {
  22. db = event.target.result;
  23. const request = db.transaction(['DestinySeasonDefinition']).objectStore('DestinySeasonDefinition').openCursor();
  24. request.onerror = reject;
  25. request.onsuccess = (event) => {
  26. const result = event.target.result;
  27. if(result) {
  28. const data = result.value.def;
  29. if(isVaildSeason(data)) {
  30. seasons.push({seasonNumber: data.seasonNumber, hash: data.hash, name: data.displayProperties.name});
  31. }
  32. result.continue();
  33. return;
  34. }
  35. seasons = seasons.sort((a, b) => b.seasonNumber - a.seasonNumber);
  36. seasons.shift();
  37. resolve(seasons);
  38. };
  39. };
  40. });
  41.  
  42. function isVaildSeason(season) {
  43. return season.endDate !== undefined && new Date(season.endDate) < Date.now() && season.displayProperties.name !== '';
  44. }
  45. }
  46.  
  47. function getSeasonHash() {
  48. return localStorage.getItem('MOEHERO_MODIFY_SEASON_HASH');
  49. }
  50.  
  51. function setSeasonHash(hash) {
  52. localStorage.setItem('MOEHERO_MODIFY_SEASON_HASH', hash);
  53. }
  54.  
  55. async function insertSeasonSelect(element) {
  56. console.log('命运2赛季切换工具:插入赛季选择器...');
  57. const seasons = await getSeasons();
  58.  
  59. const seasonSelect = document.createElement('select');
  60. seasonSelect.id = 'moehero-season-select';
  61. seasonSelect.options.add(new Option('【禁用修改】', ''));
  62. for(const season of seasons) {
  63. const selected = getSeasonHash() == season.hash;
  64. seasonSelect.options.add(new Option(season.name, season.hash, false, selected));
  65. }
  66. seasonSelect.onchange = () => {
  67. const hash = seasonSelect.options[seasonSelect.selectedIndex].value;
  68. console.log(`命运2赛季切换工具:切换赛季!Hash${hash}`);
  69. setSeasonHash(hash);
  70. location.reload();
  71. }
  72. element.appendChild(seasonSelect);
  73. }
  74.  
  75. function insertStyle() {
  76. console.log('命运2赛季切换工具:插入自定义样式...');
  77. const style = document.createElement('style');
  78. document.head.appendChild(style);
  79. style.textContent = `
  80. #main-content div[class^=SeasonsUtilityPages_wrapper] div[class^=SeasonsUtilityPage_seasonInfoContainer] div p {
  81. margin-bottom: 0;
  82. }
  83. #moehero-season-select {
  84. padding: 4px;
  85. font-size: 1em;
  86. border-radius: 4px;
  87. margin-top: 8px;
  88. }
  89. `;
  90. }
  91.  
  92. console.log('命运2赛季切换工具:开始拦截fetch...');
  93. const originFetch = fetch;
  94. window.fetch = async (url, options) => {
  95. const response = await originFetch(url, options);
  96. const modifySeasonHash = getSeasonHash();
  97. if(modifySeasonHash && response.url.includes('bungie.net/Platform/Settings')) {
  98. const data = await response.json();
  99. console.log(`命运2赛季切换工具:拦截请求成功!ModifySeasonHash${modifySeasonHash}`);
  100. data.Response.destiny2CoreSettings.pastSeasonHashes.push(modifySeasonHash);
  101. return new Response(JSON.stringify(data), response);
  102. }
  103. return response;
  104. };
  105.  
  106. console.log('命运2赛季切换工具:等待页面加载...');
  107. let waitElementReadyInterval = setInterval(waitElementReady, 500);
  108. function waitElementReady() {
  109. const element = document.querySelector('#main-content div[class^=SeasonsUtilityPages_wrapper] div[class^=SeasonsUtilityPage_seasonInfoContainer] div');
  110. if(element === null) return;
  111. clearInterval(waitElementReadyInterval);
  112. waitElementReadyInterval = null;
  113. insertStyle();
  114. insertSeasonSelect(element);
  115. }

QingJ © 2025

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