infinite craft combo tracker

tracks how you made things in infinite craft. no ui yet so just look at the storage data directly

当前为 2024-02-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name infinite craft combo tracker
  3. // @namespace https://github.com/adrianmgg
  4. // @version 1.0.0
  5. // @description tracks how you made things in infinite craft. no ui yet so just look at the storage data directly
  6. // @author amgg
  7. // @match https://neal.fun/infinite-craft/
  8. // @icon https://neal.fun/favicons/infinite-craft.png
  9. // @grant unsafeWindow
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @run-at document-idle
  13. // @compatible chrome
  14. // @license MIT
  15. // ==/UserScript==
  16.  
  17. // TODO test on firefox
  18.  
  19. (function() {
  20. 'use strict';
  21. const GM_VALUE_KEY = 'infinitecraft_observed_combos';
  22. // TODO this should probably use the async versions of getvalue/setvalue since we're already only calling it from async code
  23. function saveCombo(lhs, rhs, result) {
  24. const data = GM_getValue(GM_VALUE_KEY, {});
  25. if(!(result in data)) data[result] = [];
  26. for(const [a, b] in data[result]) {
  27. if(a === lhs && b === rhs) return;
  28. }
  29. data[result].push([lhs, rhs]);
  30. GM_setValue(GM_VALUE_KEY, data);
  31. }
  32. function main() {
  33. const _getCraftResponse = unsafeWindow.$nuxt._route.matched[0].instances.default.getCraftResponse;
  34. unsafeWindow.$nuxt._route.matched[0].instances.default.getCraftResponse = async function(lhs, rhs) {
  35. const resp = await _getCraftResponse.apply(this, arguments);
  36. saveCombo(lhs.text, rhs.text, resp.result);
  37. return resp;
  38. }
  39. }
  40. // need to wait for stuff to be actually initialized.
  41. // might be an actual thing we can hook into to detect that
  42. // but for now just waiting until the function we want exists works well enough
  43. (function waitForReady(){
  44. const cur = unsafeWindow?.$nuxt?._route?.matched?.[0]?.instances?.default?.getCraftResponse;
  45. const ready = cur !== undefined && cur !== null;
  46. if(ready) main();
  47. else setTimeout(waitForReady, 10);
  48. })();
  49. })();