-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipeCountSort.js
More file actions
159 lines (96 loc) · 6.28 KB
/
RecipeCountSort.js
File metadata and controls
159 lines (96 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// ==UserScript==
// @name RecipeCount sort
// @namespace Violentmonkey Scripts4
// @match https://neal.fun/infinite-craft/*
// @grant unsafeWindow
// @version 1.0
// @author -
// @description 5/23/2024, 7:54:23 PM
// ==/UserScript==
(function(){
let save=null;
function getSave() {
return new Promise((resolve, reject) => {
const handleClick = HTMLElement.prototype.click;
HTMLElement.prototype.click = () => {HTMLElement.prototype.click = handleClick}
const bodyObserver = new MutationObserver((mutations, observer) => {
for (const mutation of mutations) {
if (mutation.type !== "childList") continue;
const anchor = Array.from(mutation.addedNodes).find((node) => node.download === "infinitecraft.json");
if (anchor) return fetch(anchor.href).then(resolve);
}
});
bodyObserver.observe(document.body, { childList: true, subtree: true });
handleClick.call(document.querySelector(".setting[for=import-save] + .setting"));
setTimeout(() => {
bodyObserver.disconnect();
reject("Timed out")
}, 1500);
});
}
window.addEventListener('load', async () => {
console.log("Welcome to hijack sorting by recipe count");
let new_svg=`data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLC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iAxNjkuNzciIHN0cm9rZT0iIzAwMDAwMCIgc3Ryb2tlLW9wYWNpdHk9IjAuOSIgc3Ryb2tlLXdpZHRoPSIxNiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+DQo8L3N2Zz4=`;
unsafeWindow.$nuxt.$root.$children[2].$children[0].$children[0].sorts.push("recip");
let elementals=null;
const complex_filter=unsafeWindow.$nuxt.$root.$children[2].$children[0].$children[0]._computedWatchers.sortedElements.getter;
unsafeWindow.$nuxt.$root.$children[2].$children[0].$children[0]._computedWatchers.sortedElements.getter=
exportFunction( () => {
if (unsafeWindow.$nuxt.$root.$children[2].$children[0].$children[0]._data.sortBy === "recip") {
let elements2=[...complex_filter.call(this)];
console.log("elem:",elements2);
if(save!=null)
{
console.log(save);
let elem3=elements2.sort((a, b)=> {
if(!(a.text in save["recipes"]))
return -1;
if(!(b.text in save["recipes"]))
return 1;
return save["recipes"][a.text].length - save["recipes"][b.text].length;
})
console.log("elems after sort",elem3);
return elem3;
}
console.log("elems after sort are null",elements2);
return elements2;
}
else
{
let elements2=[...complex_filter.call(this)];
console.log("By:",unsafeWindow.$nuxt.$root.$children[2].$children[0].$children[0]._data.sortBy);
console.log("elem normal:",elements2);
return elements2 ;
}
},unsafeWindow);
const sortButtonObserver = new MutationObserver((mutations) => {
console.log("mutation:",unsafeWindow.$nuxt.$root.$children[2].$children[0].$children[0]._data.sortBy);
if(unsafeWindow.$nuxt.$root.$children[2].$children[0].$children[0]._data.sortBy === "recip")
{ let img=document.querySelector(".sidebar-sort > img");
if(img.src.trim()=="https://neal.fun/infinite-craft/recip.svg")
{
img.src=new_svg;
img.style.filter="invert(1)";
//img.style.filter="none";
}
}else
{
let img=document.querySelector(".sidebar-sort > img");
img.style.filter="invert(1)";
}
});
let img=document.querySelector(".sidebar-sort > img");
console.log(img,img.textContent)
var config = { characterData: false, attributes: true, childList: false, subtree: false };
sortButtonObserver.observe(img,config);
let parent=document.querySelector(".settings-content");
let button=document.createElement("div");
button.appendChild(document.createTextNode("Fetch savefile for sorting"));
button.addEventListener("click",async ()=>{save=await getSave().then(x=>x.json());
alert("Save file fetched")
});
parent.appendChild(button);
// console.log(unsafeWindow.$nuxt.$root.$children[2].$children[0].$children[0]);
console.log(img);
}, false);
})();