Auto Scroll Button

Adds a button to scroll down the page when new content is loaded or by a certain interval

  1. // ==UserScript==
  2. // @name Auto Scroll Button
  3. // @namespace https://github.com/Jkker/tampermonkey-auto-scroll
  4. // @version 1.1.1
  5. // @description Adds a button to scroll down the page when new content is loaded or by a certain interval
  6. // @author Jkker
  7. // @license MIT
  8. // @match *://*/*
  9. // @icon https://raw.githubusercontent.com/Jkker/tampermonkey-auto-scroll/master/src/icons/Unfold.svg
  10. // @grant none
  11. // @supportURL https://github.com/Jkker/tampermonkey-auto-scroll/issues
  12. // ==/UserScript==
  13.  
  14. (function(global, factory) {
  15. typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global["auto-scroll"] = factory());
  16. })(this, function() {
  17. "use strict";
  18. const app = "";
  19. function noop() {
  20. }
  21. function run(fn) {
  22. return fn();
  23. }
  24. function blank_object() {
  25. return /* @__PURE__ */ Object.create(null);
  26. }
  27. function run_all(fns) {
  28. fns.forEach(run);
  29. }
  30. function is_function(thing) {
  31. return typeof thing === "function";
  32. }
  33. function safe_not_equal(a, b) {
  34. return a != a ? b == b : a !== b || (a && typeof a === "object" || typeof a === "function");
  35. }
  36. let src_url_equal_anchor;
  37. function src_url_equal(element_src, url) {
  38. if (!src_url_equal_anchor) {
  39. src_url_equal_anchor = document.createElement("a");
  40. }
  41. src_url_equal_anchor.href = url;
  42. return element_src === src_url_equal_anchor.href;
  43. }
  44. function is_empty(obj) {
  45. return Object.keys(obj).length === 0;
  46. }
  47. function append(target, node) {
  48. target.appendChild(node);
  49. }
  50. function insert(target, node, anchor) {
  51. target.insertBefore(node, anchor || null);
  52. }
  53. function detach(node) {
  54. node.parentNode.removeChild(node);
  55. }
  56. function element(name) {
  57. return document.createElement(name);
  58. }
  59. function text(data) {
  60. return document.createTextNode(data);
  61. }
  62. function space() {
  63. return text(" ");
  64. }
  65. function listen(node, event, handler, options) {
  66. node.addEventListener(event, handler, options);
  67. return () => node.removeEventListener(event, handler, options);
  68. }
  69. function attr(node, attribute, value) {
  70. if (value == null)
  71. node.removeAttribute(attribute);
  72. else if (node.getAttribute(attribute) !== value)
  73. node.setAttribute(attribute, value);
  74. }
  75. function children(element2) {
  76. return Array.from(element2.childNodes);
  77. }
  78. function set_input_value(input, value) {
  79. input.value = value == null ? "" : value;
  80. }
  81. let current_component;
  82. function set_current_component(component) {
  83. current_component = component;
  84. }
  85. const dirty_components = [];
  86. const binding_callbacks = [];
  87. const render_callbacks = [];
  88. const flush_callbacks = [];
  89. const resolved_promise = Promise.resolve();
  90. let update_scheduled = false;
  91. function schedule_update() {
  92. if (!update_scheduled) {
  93. update_scheduled = true;
  94. resolved_promise.then(flush);
  95. }
  96. }
  97. function add_render_callback(fn) {
  98. render_callbacks.push(fn);
  99. }
  100. const seen_callbacks = /* @__PURE__ */ new Set();
  101. let flushidx = 0;
  102. function flush() {
  103. const saved_component = current_component;
  104. do {
  105. while (flushidx < dirty_components.length) {
  106. const component = dirty_components[flushidx];
  107. flushidx++;
  108. set_current_component(component);
  109. update(component.$$);
  110. }
  111. set_current_component(null);
  112. dirty_components.length = 0;
  113. flushidx = 0;
  114. while (binding_callbacks.length)
  115. binding_callbacks.pop()();
  116. for (let i = 0; i < render_callbacks.length; i += 1) {
  117. const callback = render_callbacks[i];
  118. if (!seen_callbacks.has(callback)) {
  119. seen_callbacks.add(callback);
  120. callback();
  121. }
  122. }
  123. render_callbacks.length = 0;
  124. } while (dirty_components.length);
  125. while (flush_callbacks.length) {
  126. flush_callbacks.pop()();
  127. }
  128. update_scheduled = false;
  129. seen_callbacks.clear();
  130. set_current_component(saved_component);
  131. }
  132. function update($$) {
  133. if ($$.fragment !== null) {
  134. $$.update();
  135. run_all($$.before_update);
  136. const dirty = $$.dirty;
  137. $$.dirty = [-1];
  138. $$.fragment && $$.fragment.p($$.ctx, dirty);
  139. $$.after_update.forEach(add_render_callback);
  140. }
  141. }
  142. const outroing = /* @__PURE__ */ new Set();
  143. function transition_in(block, local) {
  144. if (block && block.i) {
  145. outroing.delete(block);
  146. block.i(local);
  147. }
  148. }
  149. function mount_component(component, target, anchor, customElement) {
  150. const { fragment, on_mount, on_destroy, after_update } = component.$$;
  151. fragment && fragment.m(target, anchor);
  152. if (!customElement) {
  153. add_render_callback(() => {
  154. const new_on_destroy = on_mount.map(run).filter(is_function);
  155. if (on_destroy) {
  156. on_destroy.push(...new_on_destroy);
  157. } else {
  158. run_all(new_on_destroy);
  159. }
  160. component.$$.on_mount = [];
  161. });
  162. }
  163. after_update.forEach(add_render_callback);
  164. }
  165. function destroy_component(component, detaching) {
  166. const $$ = component.$$;
  167. if ($$.fragment !== null) {
  168. run_all($$.on_destroy);
  169. $$.fragment && $$.fragment.d(detaching);
  170. $$.on_destroy = $$.fragment = null;
  171. $$.ctx = [];
  172. }
  173. }
  174. function make_dirty(component, i) {
  175. if (component.$$.dirty[0] === -1) {
  176. dirty_components.push(component);
  177. schedule_update();
  178. component.$$.dirty.fill(0);
  179. }
  180. component.$$.dirty[i / 31 | 0] |= 1 << i % 31;
  181. }
  182. function init(component, options, instance2, create_fragment2, not_equal, props, append_styles, dirty = [-1]) {
  183. const parent_component = current_component;
  184. set_current_component(component);
  185. const $$ = component.$$ = {
  186. fragment: null,
  187. ctx: null,
  188. props,
  189. update: noop,
  190. not_equal,
  191. bound: blank_object(),
  192. on_mount: [],
  193. on_destroy: [],
  194. on_disconnect: [],
  195. before_update: [],
  196. after_update: [],
  197. context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
  198. callbacks: blank_object(),
  199. dirty,
  200. skip_bound: false,
  201. root: options.target || parent_component.$$.root
  202. };
  203. append_styles && append_styles($$.root);
  204. let ready = false;
  205. $$.ctx = instance2 ? instance2(component, options.props || {}, (i, ret, ...rest) => {
  206. const value = rest.length ? rest[0] : ret;
  207. if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
  208. if (!$$.skip_bound && $$.bound[i])
  209. $$.bound[i](value);
  210. if (ready)
  211. make_dirty(component, i);
  212. }
  213. return ret;
  214. }) : [];
  215. $$.update();
  216. ready = true;
  217. run_all($$.before_update);
  218. $$.fragment = create_fragment2 ? create_fragment2($$.ctx) : false;
  219. if (options.target) {
  220. if (options.hydrate) {
  221. const nodes = children(options.target);
  222. $$.fragment && $$.fragment.l(nodes);
  223. nodes.forEach(detach);
  224. } else {
  225. $$.fragment && $$.fragment.c();
  226. }
  227. if (options.intro)
  228. transition_in(component.$$.fragment);
  229. mount_component(component, options.target, options.anchor, options.customElement);
  230. flush();
  231. }
  232. set_current_component(parent_component);
  233. }
  234. class SvelteComponent {
  235. $destroy() {
  236. destroy_component(this, 1);
  237. this.$destroy = noop;
  238. }
  239. $on(type, callback) {
  240. const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
  241. callbacks.push(callback);
  242. return () => {
  243. const index = callbacks.indexOf(callback);
  244. if (index !== -1)
  245. callbacks.splice(index, 1);
  246. };
  247. }
  248. $set($$props) {
  249. if (this.$$set && !is_empty($$props)) {
  250. this.$$.skip_bound = true;
  251. this.$$set($$props);
  252. this.$$.skip_bound = false;
  253. }
  254. }
  255. }
  256. const ArrowBackIcon = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTZweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMTZweCIgZmlsbD0iI2ZmZiI+CiAgPHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIiBvcGFjaXR5PSIuODciLz4KICA8cGF0aCBkPSJNMTcuNTEgMy44N0wxNS43MyAyLjEgNS44NCAxMmw5LjkgOS45IDEuNzctMS43N0w5LjM4IDEybDguMTMtOC4xM3oiLz4KPC9zdmc+";
  257. const SettingsIcon = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjBwe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VjhoOG0yLTJINnYxMmgxMlY2eiIvPgo8L3N2Zz4=";
  259. const AutoScrollIcon = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjRweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjRweCIgZmlsbD0iI2ZmZiI+CiAgPHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+CiAgPHBhdGggZD0iTTEyIDUuODNMMTUuMTcgOWwxLjQxLTEuNDFMMTIgMyA3LjQxIDcuNTkgOC44MyA5IDEyIDUuODN6bTAgMTIuMzRMOC44MyAxNWwtMS40MSAxLjQxTDEyIDIxbDQuNTktNC41OUwxNS4xNyAxNSAxMiAxOC4xN3oiLz4KPC9zdmc+";
  260. const ClearIcon = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTZweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMTZweCIgZmlsbD0iI2ZmZiI+CiAgPHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+CiAgPHBhdGggZD0iTTE5IDYuNDFMMTcuNTkgNSAxMiAxMC41OSA2LjQxIDUgNSA2LjQxIDEwLjU5IDEyIDUgMTcuNTkgNi40MSAxOSAxMiAxMy40MSAxNy41OSAxOSAxOSAxNy41OSAxMy40MSAxMiAxOSA2LjQxeiIvPgo8L3N2Zz4=";
  261. const CheckIcon = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMTZweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMTZweCIgZmlsbD0id2hpdGUiPjxwYXRoIGQ9Ik0wIDBoMjR2MjRIMFYweiIgZmlsbD0ibm9uZSIvPjxwYXRoIGQ9Ik05IDE2LjE3TDQuODMgMTJsLTEuNDIgMS40MUw5IDE5IDIxIDdsLTEuNDEtMS40MUw5IDE2LjE3eiIvPjwvc3ZnPg==";
  262. const CloseIcon = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjBweCIgdmlld0JveD0iMCAwIDI0IDI0IiB3aWR0aD0iMjBweCIgZmlsbD0iI2ZmZiI+CiAgPHBhdGggZD0iTTAgMGgyNHYyNEgwVjB6IiBmaWxsPSJub25lIi8+CiAgPHBhdGggZD0iTTE5IDYuNDFMMTcuNTkgNSAxMiAxMC41OSA2LjQxIDUgNSA2LjQxIDEwLjU5IDEyIDUgMTcuNTkgNi40MSAxOSAxMiAxMy40MSAxNy41OSAxOSAxOSAxNy41OSAxMy40MSAxMiAxOSA2LjQxeiIvPgo8L3N2Zz4=";
  263. function create_if_block_1(ctx) {
  264. let button0;
  265. let img;
  266. let img_src_value;
  267. let t0;
  268. let button1;
  269. let t1;
  270. let t2;
  271. let button2;
  272. let t3;
  273. let t4;
  274. let button3;
  275. let t5;
  276. let mounted;
  277. let dispose;
  278. return {
  279. c() {
  280. button0 = element("button");
  281. img = element("img");
  282. t0 = space();
  283. button1 = element("button");
  284. t1 = text("Auto");
  285. t2 = space();
  286. button2 = element("button");
  287. t3 = text("500ms");
  288. t4 = space();
  289. button3 = element("button");
  290. t5 = text("1.5s");
  291. if (!src_url_equal(img.src, img_src_value = ctx[1] ? CloseIcon : SettingsIcon))
  292. attr(img, "src", img_src_value);
  293. attr(img, "alt", "Settings");
  294. attr(button0, "style", ctx[12].button);
  295. attr(button1, "style", ctx[12].button);
  296. attr(button2, "style", ctx[12].button);
  297. attr(button3, "style", ctx[12].button);
  298. },
  299. m(target, anchor) {
  300. insert(target, button0, anchor);
  301. append(button0, img);
  302. insert(target, t0, anchor);
  303. insert(target, button1, anchor);
  304. append(button1, t1);
  305. insert(target, t2, anchor);
  306. insert(target, button2, anchor);
  307. append(button2, t3);
  308. insert(target, t4, anchor);
  309. insert(target, button3, anchor);
  310. append(button3, t5);
  311. if (!mounted) {
  312. dispose = [
  313. listen(button0, "click", ctx[6]),
  314. listen(button1, "click", ctx[11]("resize")),
  315. listen(button2, "click", ctx[11]("interval", 500)),
  316. listen(button3, "click", ctx[11]("interval", 1500))
  317. ];
  318. mounted = true;
  319. }
  320. },
  321. p(ctx2, dirty) {
  322. if (dirty & 2 && !src_url_equal(img.src, img_src_value = ctx2[1] ? CloseIcon : SettingsIcon)) {
  323. attr(img, "src", img_src_value);
  324. }
  325. },
  326. d(detaching) {
  327. if (detaching)
  328. detach(button0);
  329. if (detaching)
  330. detach(t0);
  331. if (detaching)
  332. detach(button1);
  333. if (detaching)
  334. detach(t2);
  335. if (detaching)
  336. detach(button2);
  337. if (detaching)
  338. detach(t4);
  339. if (detaching)
  340. detach(button3);
  341. mounted = false;
  342. run_all(dispose);
  343. }
  344. };
  345. }
  346. function create_if_block(ctx) {
  347. let div1;
  348. let label;
  349. let t0;
  350. let t1;
  351. let div0;
  352. let input;
  353. let t2;
  354. let button;
  355. let img;
  356. let img_src_value;
  357. let t3;
  358. let style;
  359. let mounted;
  360. let dispose;
  361. return {
  362. c() {
  363. div1 = element("div");
  364. label = element("label");
  365. t0 = text("Stop scrolling if");
  366. t1 = space();
  367. div0 = element("div");
  368. input = element("input");
  369. t2 = space();
  370. button = element("button");
  371. img = element("img");
  372. t3 = space();
  373. style = element("style");
  374. style.textContent = "#auto-scroll-wait-until-element-input::placeholder{color:rgba(255, 255, 255, 0.8);}";
  375. attr(label, "style", ctx[12].inputLabel);
  376. attr(label, "for", "auto-scroll-wait-until-element-input");
  377. attr(input, "id", "auto-scroll-wait-until-element-input");
  378. attr(input, "style", ctx[12].input);
  379. input.autofocus = true;
  380. attr(input, "placeholder", "text appears");
  381. if (!src_url_equal(img.src, img_src_value = ctx[3] ? ClearIcon : CheckIcon))
  382. attr(img, "src", img_src_value);
  383. attr(img, "alt", "Clear input");
  384. attr(button, "style", ctx[12].inputButton);
  385. attr(div0, "style", ctx[12].inputContainer);
  386. attr(div1, "style", ctx[12].menu);
  387. },
  388. m(target, anchor) {
  389. insert(target, div1, anchor);
  390. append(div1, label);
  391. append(label, t0);
  392. append(div1, t1);
  393. append(div1, div0);
  394. append(div0, input);
  395. set_input_value(input, ctx[2]);
  396. append(div0, t2);
  397. append(div0, button);
  398. append(button, img);
  399. append(div0, t3);
  400. append(div0, style);
  401. input.focus();
  402. if (!mounted) {
  403. dispose = [
  404. listen(input, "input", ctx[13]),
  405. listen(input, "change", ctx[8]),
  406. listen(input, "input", ctx[9]),
  407. listen(input, "keypress", ctx[14]),
  408. listen(button, "click", function() {
  409. if (is_function(ctx[3] ? ctx[7] : ctx[8]))
  410. (ctx[3] ? ctx[7] : ctx[8]).apply(this, arguments);
  411. })
  412. ];
  413. mounted = true;
  414. }
  415. },
  416. p(new_ctx, dirty) {
  417. ctx = new_ctx;
  418. if (dirty & 4 && input.value !== ctx[2]) {
  419. set_input_value(input, ctx[2]);
  420. }
  421. if (dirty & 8 && !src_url_equal(img.src, img_src_value = ctx[3] ? ClearIcon : CheckIcon)) {
  422. attr(img, "src", img_src_value);
  423. }
  424. },
  425. d(detaching) {
  426. if (detaching)
  427. detach(div1);
  428. mounted = false;
  429. run_all(dispose);
  430. }
  431. };
  432. }
  433. function create_fragment(ctx) {
  434. let div1;
  435. let div0;
  436. let t0;
  437. let button;
  438. let img;
  439. let img_src_value;
  440. let div0_style_value;
  441. let t1;
  442. let mounted;
  443. let dispose;
  444. let if_block0 = ctx[0] && create_if_block_1(ctx);
  445. let if_block1 = ctx[0] && ctx[1] && create_if_block(ctx);
  446. return {
  447. c() {
  448. div1 = element("div");
  449. div0 = element("div");
  450. if (if_block0)
  451. if_block0.c();
  452. t0 = space();
  453. button = element("button");
  454. img = element("img");
  455. t1 = space();
  456. if (if_block1)
  457. if_block1.c();
  458. if (!src_url_equal(img.src, img_src_value = ctx[4] ? StopIcon : ctx[0] ? ArrowBackIcon : AutoScrollIcon))
  459. attr(img, "src", img_src_value);
  460. attr(img, "alt", "Logo");
  461. attr(button, "style", ctx[12].button);
  462. attr(div0, "style", div0_style_value = ctx[12].container + `left: ${ctx[0] ? "0" : "-8px"};`);
  463. },
  464. m(target, anchor) {
  465. insert(target, div1, anchor);
  466. append(div1, div0);
  467. if (if_block0)
  468. if_block0.m(div0, null);
  469. append(div0, t0);
  470. append(div0, button);
  471. append(button, img);
  472. append(div1, t1);
  473. if (if_block1)
  474. if_block1.m(div1, null);
  475. if (!mounted) {
  476. dispose = listen(button, "click", function() {
  477. if (is_function(ctx[4] ? ctx[10] : ctx[5]))
  478. (ctx[4] ? ctx[10] : ctx[5]).apply(this, arguments);
  479. });
  480. mounted = true;
  481. }
  482. },
  483. p(new_ctx, [dirty]) {
  484. ctx = new_ctx;
  485. if (ctx[0]) {
  486. if (if_block0) {
  487. if_block0.p(ctx, dirty);
  488. } else {
  489. if_block0 = create_if_block_1(ctx);
  490. if_block0.c();
  491. if_block0.m(div0, t0);
  492. }
  493. } else if (if_block0) {
  494. if_block0.d(1);
  495. if_block0 = null;
  496. }
  497. if (dirty & 17 && !src_url_equal(img.src, img_src_value = ctx[4] ? StopIcon : ctx[0] ? ArrowBackIcon : AutoScrollIcon)) {
  498. attr(img, "src", img_src_value);
  499. }
  500. if (dirty & 1 && div0_style_value !== (div0_style_value = ctx[12].container + `left: ${ctx[0] ? "0" : "-8px"};`)) {
  501. attr(div0, "style", div0_style_value);
  502. }
  503. if (ctx[0] && ctx[1]) {
  504. if (if_block1) {
  505. if_block1.p(ctx, dirty);
  506. } else {
  507. if_block1 = create_if_block(ctx);
  508. if_block1.c();
  509. if_block1.m(div1, null);
  510. }
  511. } else if (if_block1) {
  512. if_block1.d(1);
  513. if_block1 = null;
  514. }
  515. },
  516. i: noop,
  517. o: noop,
  518. d(detaching) {
  519. if (detaching)
  520. detach(div1);
  521. if (if_block0)
  522. if_block0.d();
  523. if (if_block1)
  524. if_block1.d();
  525. mounted = false;
  526. dispose();
  527. }
  528. };
  529. }
  530. function instance($$self, $$props, $$invalidate) {
  531. const getLastElementByText = (text2) => {
  532. const iter = document.evaluate(`//*[contains(text(),"${text2}")]`, document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
  533. let curr, prev;
  534. try {
  535. curr = iter.iterateNext();
  536. while (curr) {
  537. prev = curr;
  538. curr = iter.iterateNext();
  539. }
  540. } catch (e) {
  541. console.error(`Auto Scroll Button Error: Document tree modified during iteration ${e}`);
  542. }
  543. return prev;
  544. };
  545. let menuOpen = false;
  546. const toggleMenu = () => $$invalidate(0, menuOpen = !menuOpen);
  547. let settingsOpen = false;
  548. const toggleSettings = () => $$invalidate(1, settingsOpen = !settingsOpen);
  549. let inputValue = "";
  550. let untilTarget;
  551. const clearScrollUntilCondition = () => $$invalidate(3, untilTarget = void 0);
  552. const activateScrollUntilCondition = () => {
  553. $$invalidate(3, untilTarget = inputValue);
  554. toggleSettings();
  555. };
  556. const onInput = () => {
  557. $$invalidate(3, untilTarget = void 0);
  558. };
  559. let lastFound = null;
  560. function checkStopCondition() {
  561. if (!untilTarget)
  562. return false;
  563. const last = getLastElementByText(untilTarget);
  564. if (!last)
  565. return false;
  566. if (last !== lastFound) {
  567. lastFound = last;
  568. last.scrollIntoView();
  569. return true;
  570. } else {
  571. return false;
  572. }
  573. }
  574. const scroll = () => {
  575. if (checkStopCondition()) {
  576. cancelCurrentScroll();
  577. return;
  578. }
  579. window.scroll({
  580. top: document.body.scrollHeight,
  581. left: 0,
  582. behavior: "smooth"
  583. });
  584. };
  585. const resizeObserver = new ResizeObserver(() => setTimeout(scroll, 100));
  586. let intervalId;
  587. let scrolling = false;
  588. const startScroll = (type, interval = 1e3) => {
  589. if (type === "resize")
  590. resizeObserver.observe(document.body);
  591. else if (type === "interval")
  592. intervalId = setInterval(scroll, interval);
  593. $$invalidate(4, scrolling = type);
  594. $$invalidate(0, menuOpen = !menuOpen);
  595. };
  596. const cancelScroll = (type) => {
  597. if (type === "resize")
  598. resizeObserver.unobserve(document.body);
  599. else if (type === "interval")
  600. clearInterval(intervalId);
  601. $$invalidate(4, scrolling = false);
  602. };
  603. const cancelCurrentScroll = () => {
  604. if (scrolling)
  605. cancelScroll(scrolling);
  606. };
  607. const toggleScroll = (type, intervalSecond = 1e3) => () => {
  608. if (scrolling) {
  609. cancelScroll(type);
  610. } else {
  611. startScroll(type, intervalSecond);
  612. }
  613. };
  614. const styles = {
  615. button: "height: 40px; padding: 8px; display: flex; justify-content: center; align-items: center; border: none; outline: none; background: transparent; cursor: pointer; color: white",
  616. menu: "position: fixed; bottom: 62px; left: 6px; background: rgba(0,0,0,0.4); backdrop-filter: blur(10px); padding: 8px; border-radius: 8px; padding-bottom: 12px;",
  617. inputLabel: "color: white; font-size: 15px",
  618. inputContainer: "display: flex; position: relative; margin-top: 8px",
  619. input: "height: 24px; border: 1px solid white; outline: none; background: transparent; border-radius: 4px; padding-left: 4px; padding-right: 32px; color: white",
  620. inputButton: "height: 100%; width: 28px; padding: 8px; display: flex; justify-content: center; align-items: center; border: none; outline: none; cursor: pointer; position: absolute; top: 0; right: 0; border-left: 1px solid white; background: transparent",
  621. container: "position: fixed; bottom: 16px; z-index: 99999999; background: rgba(0,0,0,0.4); backdrop-filter: blur(10px); display: flex; border-radius: 0 20px 20px 0;"
  622. };
  623. function input_input_handler() {
  624. inputValue = this.value;
  625. $$invalidate(2, inputValue);
  626. }
  627. const keypress_handler = (e) => {
  628. if (e.key === "Enter")
  629. activateScrollUntilCondition();
  630. };
  631. return [
  632. menuOpen,
  633. settingsOpen,
  634. inputValue,
  635. untilTarget,
  636. scrolling,
  637. toggleMenu,
  638. toggleSettings,
  639. clearScrollUntilCondition,
  640. activateScrollUntilCondition,
  641. onInput,
  642. cancelCurrentScroll,
  643. toggleScroll,
  644. styles,
  645. input_input_handler,
  646. keypress_handler
  647. ];
  648. }
  649. class App extends SvelteComponent {
  650. constructor(options) {
  651. super();
  652. init(this, options, instance, create_fragment, safe_not_equal, {});
  653. }
  654. }
  655. const main = new App({
  656. target: document.body
  657. });
  658. return main;
  659. });

QingJ © 2025

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