(
type = Types.addReact,
reaction = Reactions.love,
maxPosts = Infinity
)
| 80 | }; |
| 81 | |
| 82 | async function startAutoLike( |
| 83 | type = Types.addReact, |
| 84 | reaction = Reactions.love, |
| 85 | maxPosts = Infinity |
| 86 | ) { |
| 87 | isRunning(true); |
| 88 | |
| 89 | const notify = UfsGlobal.DOM.notify({ |
| 90 | msg: "Đang chuẩn bị ...", |
| 91 | duration: 999999, |
| 92 | }); |
| 93 | |
| 94 | let count = 0; |
| 95 | |
| 96 | const btns = []; |
| 97 | const unobserver = UfsGlobal.DOM.onElementsAdded( |
| 98 | ["en", "vi"] |
| 99 | .map((l) => |
| 100 | type === Types.removeReact |
| 101 | ? Object.values(Reactions).map( |
| 102 | (r) => |
| 103 | `[aria-label='${type[l]}${r[l]}']:not(li *):not([hidden] *)` |
| 104 | ) |
| 105 | : `[aria-label='${type[l]}']:not(li *)` |
| 106 | ) |
| 107 | .flat() |
| 108 | .join(", "), |
| 109 | (nodes) => { |
| 110 | btns.push(...nodes); |
| 111 | } |
| 112 | ); |
| 113 | |
| 114 | let scrollTried = 0; |
| 115 | while (true) { |
| 116 | if (!isRunning()) { |
| 117 | alert("Stopped Auto react !\n\nĐã dừng tự động thích!"); |
| 118 | break; |
| 119 | } |
| 120 | if (!btns.length) { |
| 121 | scrollTried++; |
| 122 | if (scrollTried > 50) break; |
| 123 | notify.setText("Scrolling to bottom... " + scrollTried, 99999); |
| 124 | scrollToBottom(); |
| 125 | await sleep(2000); |
| 126 | continue; |
| 127 | } |
| 128 | scrollTried = 0; |
| 129 | |
| 130 | const btn = btns.shift(); |
| 131 | btn.scrollIntoView({ |
| 132 | block: "center", |
| 133 | behavior: "smooth", |
| 134 | }); |
| 135 | |
| 136 | let waitFor = rand(1000, 4000); |
| 137 | count++; |
| 138 | if (count >= maxPosts) break; |
| 139 | notify.setText( |
no test coverage detected