├── LICENSE
├── README.md
├── changelogs.json
├── dist
└── AddonManager.js
├── manifest.json
└── src
├── components
├── Detail.tsx
├── Export.tsx
├── Home.tsx
├── HyperLink.tsx
├── Import.tsx
├── Page.tsx
├── Plugins.tsx
├── Settings.tsx
├── Themes.tsx
└── Update.tsx
├── index.tsx
└── utils
├── addon.tsx
├── backup.tsx
├── common.tsx
├── fetch.tsx
├── icons.tsx
├── native.tsx
├── update.tsx
└── updater.tsx
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AddonManager
2 | A plugin of Enmity (Custom Discord Client for iOS) to manage addons easily.
3 |
4 | ## Installation
5 | https://raw.githubusercontent.com/m4fn3/AddonManager/master/dist/AddonManager.js
6 |
7 | ## Usage
8 | Use /addon command or open plugin setting page.
9 |
10 | 
11 | 
--------------------------------------------------------------------------------
/changelogs.json:
--------------------------------------------------------------------------------
1 | {
2 | "1.1.4": "Added hacky fixes for iPad users and a updater of the plugin itself.",
3 | "1.1.5": "Added new option to insert AddonManager to settings",
4 | "1.1.6": "Added new feature to show 'download as plugin/theme' option on long press links",
5 | "1.1.7": "Fixed a crash on 190+",
6 | "1.1.8": "Fixed. うん。"
7 | }
--------------------------------------------------------------------------------
/dist/AddonManager.js:
--------------------------------------------------------------------------------
1 | function rt(e){window.enmity.plugins.registerPlugin(e)}function F(e){return window.enmity.plugins.getPlugin(e)}function re(){return window.enmity.plugins.getPlugins()}const g=window.enmity.modules.common.Constants;window.enmity.modules.common.Clipboard,window.enmity.modules.common.Assets,window.enmity.modules.common.Messages,window.enmity.modules.common.Clyde,window.enmity.modules.common.Avatars;const it=window.enmity.modules.common.Native,t=window.enmity.modules.common.React;window.enmity.modules.common.Dispatcher,window.enmity.modules.common.Storage;const A=window.enmity.modules.common.Toasts,ie=window.enmity.modules.common.Dialog,lt=window.enmity.modules.common.Token,D=window.enmity.modules.common.REST;window.enmity.modules.common.Settings,window.enmity.modules.common.Users;const le=window.enmity.modules.common.Navigation,st=window.enmity.modules.common.NavigationNative,me=window.enmity.modules.common.NavigationStack;window.enmity.modules.common.Theme;const W=window.enmity.modules.common.Linking,C=window.enmity.modules.common.StyleSheet;window.enmity.modules.common.ColorMap,window.enmity.modules.common.Components,window.enmity.modules.common.Locale,window.enmity.modules.common.Profiles,window.enmity.modules.common.Lodash,window.enmity.modules.common.Logger,window.enmity.modules.common.Flux;const U=window.enmity.modules.common.SVG,ct=window.enmity.modules.common.Scenes;window.enmity.modules.common.Moment;function dt(e){return window.enmity.patcher.create(e)}var m="AddonManager",Ce="1.1.8",mt="Manage plugins & themes easily!",ut=[{name:"mafu",id:"519760564755365888"}],gt="#00ffff",ht={name:m,version:Ce,description:mt,authors:ut,color:gt};function b(e,n,o){window.enmity.settings.set(e,n,o)}function S(e,n,o){return window.enmity.settings.get(e,n,o)}const j="https://raw.githubusercontent.com/m4fn3/AddonManagerDatabase/master/",pt=j+"plugins.json",Et=j+"themes.json",wt=j+"plugins_update.txt",yt=j+"themes_update.txt",ft=j+"compatibility.json";function G(e){return`${e}?${Date.now()}`}function bt(e,n){return`${j}${e}s/${n}.json`}function ue(e){try{return JSON.parse(S(m,e,"{}").toString())}catch{return{}}}function X(){return ue("plugins")}function J(){return ue("themes")}function vt(){return ue("compatibility")}function Me(){D.get(G(pt)).then(e=>{b(m,"plugins",e.text)})}function Pe(){D.get(G(Et)).then(e=>{b(m,"themes",e.text)})}function St(){D.get(G(wt)).then(e=>{let n=e.text,o=S(m,"plugins_ver");o?o!=n&&(b(m,"plugins_ver",n),Me()):(b(m,"plugins_ver",n),Me())})}function Tt(){D.get(G(yt)).then(e=>{let n=e.text,o=S(m,"themes_ver");o?o!=n&&(b(m,"themes_ver",n),Pe()):(b(m,"themes_ver",n),Pe())})}const{components:u}=window.enmity;u.Alert;const _t=u.Button,Ct=u.FlatList,Re=u.Image;u.ImageBackground,u.KeyboardAvoidingView,u.Modal,u.Pressable,u.RefreshControl;const L=u.ScrollView;u.SectionList,u.StatusBar,u.StyleSheet,u.Switch;const k=u.Text,Mt=u.TextInput;u.TouchableHighlight;const Ne=u.TouchableOpacity;u.TouchableWithoutFeedback,u.Touchable;const ge=u.View;u.VirtualizedList,u.Form;const Pt=u.FormArrow;u.FormCTA,u.FormCTAButton,u.FormCardSection,u.FormCheckbox;const Rt=u.FormDivider;u.FormHint,u.FormIcon,u.FormInput,u.FormLabel,u.FormRadio;const r=u.FormRow,P=u.FormSection;u.FormSelect,u.FormSubLabel;const q=u.FormSwitch;u.FormTernaryCheckBox,u.FormText,u.FormTextColors,u.FormTextSizes;function T(e){return window.enmity.assets.getIDByName(e)}const B={byProps:(...e)=>window.enmity.modules.filters.byProps(...e),byName:(e,n)=>window.enmity.modules.filters.byName(e,n),byTypeName:(e,n)=>window.enmity.modules.filters.byTypeName(e,n),byDisplayName:(e,n)=>window.enmity.modules.filters.byDisplayName(e,n)};function Nt(e,n){return window.enmity.modules.getModule(e,n)}function Ie(...e){return window.enmity.modules.bulk(...e)}function H(...e){return window.enmity.modules.getByProps(...e)}function Ae(...e){return window.enmity.modules.getByName(...e)}function It(...e){return window.enmity.modules.getByKeyword(...e)}window.enmity.modules.common;const Z=It("getFocusedRoute"),ke=Ae("StaticSearchBarContainer"),At=H("acceptInviteAndTransitionToInviteChannel"),kt=H("AppState"),$t=H("DRMType","FilterType").default,$e=H("setString"),p={Copy:T("ic_message_copy"),GitHub:T("img_account_sync_github_white"),Twitter:T("img_account_sync_twitter_white"),Discord:T("Discord"),Update:T("toast_image_saved"),Export:T("ic_reply_24px"),Import:T("ic_leave_stage"),Fail:T("Small"),Download:T("ic_download_24px"),Check:T("ic_check_24px"),Clear:T("ic_input_clear_24px"),Uninstall:T("ic_trash_24px"),Settings:T("ic_settings_white_24px"),Add:T("hub-add"),SettingIcon:T("ic_rulebook"),Link:T("ic_link")},Q=C.createThemedStyleSheet({cardStyle:{backgroundColor:g.ThemeColorMap.BACKGROUND_MOBILE_PRIMARY,color:g.ThemeColorMap.TEXT_NORMAL},header:{backgroundColor:g.ThemeColorMap.BACKGROUND_MOBILE_SECONDARY,shadowColor:"transparent",elevation:0},headerText:{color:g.ThemeColorMap.HEADER_PRIMARY}}),xt={cardStyle:Q.cardStyle,headerStyle:Q.header,headerTitleContainerStyle:Q.headerText,headerTitleStyle:Q.headerText,headerBackTitleStyle:Q.headerText,headerBackImage:()=>t.createElement(r.Icon,{source:T("ios-back")}),headerTitleAlign:"center",safeAreaInsets:{top:0}};function Dt(e,n,o,a=186){let s=e.replace("#","");const c=(d,l,f)=>parseInt(d.substring(l[0],l[1]),f),h=c(s,[0,2],16),E=c(s,[2,4],16),i=c(s,[4,6],16);return(h+E+i)/(255*3)>a?o:n}function Y(e,n,o=()=>{}){window.enmity.plugins.installPlugin(n,a=>{a.name===void 0?A.open({content:`Failed to install ${e}`,source:p.Fail}):(A.open({content:`Successfully installed ${e}!`,source:p.Check}),o())})}function xe(e,n=()=>{}){window.enmity.plugins.uninstallPlugin(e,o=>{A.open({content:`Successfully uninstalled ${e}!`,source:p.Check}),n()})}function ee(e,n,o=()=>{}){window.enmity.themer.installTheme(n,a=>{A.open({content:`Successfully installed ${e}!`,source:p.Check}),o()})}function Lt(e,n=()=>{}){window.enmity.themer.uninstallTheme(e,o=>{A.open({content:`Successfully uninstalled ${e}!`,source:p.Check}),n()})}function V(e){return window.enmity.themer.getThemeByName(e)}function se(){return window.enmity.themer.listThemes()}function Bt(e){try{let n=V(window.enmity.themer.getTheme());return n?n.colours[e]:void 0}catch{return}}function ce(e,n){let o=he("plugin");o.push(n),b(m,`_updated_${e}s`,JSON.stringify(o))}function Ot(e){b(m,`_updated_${e}s`,"[]")}function he(e){return JSON.parse(S(m,`_updated_${e}s`,"[]").toString())}function Ft(){let e=S(m,"check_updates");if(e===void 0)b(m,"check_updates",!1);else if(e){const n=X(),o=J();let a=Ee(n),s=we(o);if(a.length||s.length){let c=a.concat(s).join(", ");A.open({content:`Updates are available for ${c}`,source:p.Download})}}}function pe(e,n){return n.localeCompare(e,void 0,{numeric:!0})}function De(e,n){return pe(e,n)===1}function Ee(e){return re().map(n=>n.name).filter(n=>Object.keys(e).includes(n)&&Object.keys(e[n]).includes("version")&&F(n).version&&De(F(n).version,e[n].version))}function we(e){return se().map(n=>n.name).filter(n=>Object.keys(e).includes(n)&&Object.keys(e[n]).includes("version")&&V(n).version&&De(V(n).version,e[n].version))}const Ut=H("updateNote");async function jt(e){let n=await(await fetch(`https://discord.com/api/v9/users/@me/notes/${e}`,{method:"GET",credentials:"include",headers:{authorization:lt.getToken()}})).json();return Object.keys(n).includes("note")?n.note:""}function Gt(e,n){Ut.updateNote(e,n)}function Le(){Gt("1048982327809818706",Be())}async function Ht(){return jt("1048982327809818706")}function Be(){let e=re().map(o=>o.name).join(";"),n=se().map(o=>o.name).join(";");return`${e}|${n}`}W.addEventListener("url",e=>{let n=e.url;n=decodeURIComponent(n.replace("com.hammerandchisel.discord://",""));try{const o=JSON.parse(n);S(m,"auto_backup")&&typeof o.data=="string"&&["installed_theme","overridden_theme","installed_plugin","overridden_plugin"].includes(o.data)&&Le()}catch{return}});function Oe({height:e,width:n,...o}){const a=C.createThemedStyleSheet({icon:{color:g.ThemeColorMap.INTERACTIVE_NORMAL,opacity:.75,marginLeft:.5}});return t.createElement(U.Svg,{viewBox:"0 0 24 24",style:{height:e,width:n,...a.icon},fill:"currentColor",...o},t.createElement(U.Path,{d:"M0 0h24v24H0z",fill:"none"}),t.createElement(U.Path,{d:"M20.5 11H19V7c0-1.1-.9-2-2-2h-4V3.5C13 2.12 11.88 1 10.5 1S8 2.12 8 3.5V5H4c-1.1 0-1.99.9-1.99 2v3.8H3.5c1.49 0 2.7 1.21 2.7 2.7s-1.21 2.7-2.7 2.7H2V20c0 1.1.9 2 2 2h3.8v-1.5c0-1.49 1.21-2.7 2.7-2.7 1.49 0 2.7 1.21 2.7 2.7V22H17c1.1 0 2-.9 2-2v-4h1.5c1.38 0 2.5-1.12 2.5-2.5S21.88 11 20.5 11z"}))}function Fe({height:e,width:n,...o}){const a=C.createThemedStyleSheet({icon:{color:g.ThemeColorMap.INTERACTIVE_NORMAL,opacity:.75,marginLeft:.5}});return t.createElement(U.Svg,{viewBox:"0 0 24 24",style:{height:e,width:n,...a.icon},fill:"currentColor",...o},t.createElement(U.Path,{d:"M0 0h24v24H0z",fill:"none"}),t.createElement(U.Path,{d:"M12 3c-4.97 0-9 4.03-9 9s4.03 9 9 9c.83 0 1.5-.67 1.5-1.5 0-.39-.15-.74-.39-1.01-.23-.26-.38-.61-.38-.99 0-.83.67-1.5 1.5-1.5H16c2.76 0 5-2.24 5-5 0-4.42-4.03-8-9-8zm-5.5 9c-.83 0-1.5-.67-1.5-1.5S5.67 9 6.5 9 8 9.67 8 10.5 7.33 12 6.5 12zm3-4C8.67 8 8 7.33 8 6.5S8.67 5 9.5 5s1.5.67 1.5 1.5S10.33 8 9.5 8zm5 0c-.83 0-1.5-.67-1.5-1.5S13.67 5 14.5 5s1.5.67 1.5 1.5S15.33 8 14.5 8zm3 4c-.83 0-1.5-.67-1.5-1.5S16.67 9 17.5 9s1.5.67 1.5 1.5-.67 1.5-1.5 1.5z"}))}const{native:te}=window.enmity;function Yt(){te.reload()}const ye=te.version;te.build,te.device,te.version;var Ue=({content:e,addonType:n,addonName:o})=>{const a=C.createThemedStyleSheet({hyperLink:{color:g.ThemeColorMap.TEXT_LINK}});return e.replace(/(\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*)/ig,"$1").split("").map(s=>s.startsWith("http")?t.createElement(k,{style:a.hyperLink,onPress:()=>{let c=n=="plugin"?".js":".json";s.endsWith(c)?n=="plugin"?Y(o,s):ee(o,s):W.openURL(s)},onLongPress:()=>{$e.setString(s),A.open({content:"Copied URL to clipboard",source:p.Copy})}},s):t.createElement(k,null,s))};function K({addonType:e}){let n=Bt("PRIMARY_DARK_500"),o=n?Dt(n,g.ThemeColorMap.TEXT_NORMAL[0],g.ThemeColorMap.TEXT_NORMAL[1]):g.ThemeColorMap.HEADER_PRIMARY;n=n||g.ThemeColorMap.BACKGROUND_SECONDARY;const a=C.createThemedStyleSheet({container:{flex:1,backgroundColor:g.ThemeColorMap.BACKGROUND_PRIMARY,padding:10},previews:{marginTop:20,justifyContent:"center"},addonName:{color:g.ThemeColorMap.TEXT_NORMAL,fontFamily:g.Fonts.PRIMARY_SEMIBOLD,fontSize:20},addonText:{borderBottomWidth:1,borderBottomColor:g.ThemeColorMap.HEADER_PRIMARY,paddingBottom:20},sectionTitle:{marginTop:20,marginLeft:15,color:g.ThemeColorMap.HEADER_PRIMARY},sectionContent:{margin:10,borderRadius:10,borderWidth:1,borderColor:g.ThemeColorMap.HEADER_PRIMARY,color:g.ThemeColorMap.TEXT_NORMAL,padding:10},addonEdit:{backgroundColor:n,paddingTop:10,paddingBottom:10,borderRadius:20,borderWidth:1,width:80,alignItems:"center",borderColor:n,overflow:"hidden"},addonEditText:{color:o,fontFamily:g.Fonts.PRIMARY_SEMIBOLD},hyperLink:{color:g.ThemeColorMap.TEXT_LINK}}),s=kt.useWindowDimensions().width,[c,h]=t.useState("Loading description..."),[E,i]=t.useState([]),d=S(m,`_selected_${e}`).toString(),l=e=="plugin"?X():J(),f=l[d];let $=e=="plugin"?Ee(l):we(l),R=e=="plugin"?Boolean(F(d)):Boolean(V(d)),w=$.includes(d);const[y,oe]=t.useState(w),[ae,x]=t.useState(R?y?"UPDATE":"REMOVE":"GET"),[_e,at]=t.useState(void 0);return t.useEffect(()=>{D.get(G(bt(e,d))).then(_=>{let v=JSON.parse(_.text);h(v.description);let N=Object.assign(v.images.map(I=>({url:I,width:1,height:1,type:"image"})),v.videos.map(I=>({url:I,width:null,height:null,type:"video"})));i(N)}).catch(_=>{_.status===404&&h("No description.")});const M=vt();if(d in M[e]){let _=!0;if(M[e][d].ver.includes("~")){let v=M[e][d].ver.split("~"),N=v[0]?v[0]:"0.0",I=v[1]?v[1]:"999.0";pe(N,ye)>=0&&pe(ye,I)>=0&&(_=!1)}_&&at(M[e][d].text+`
2 |
3 | Compatibility: ${M[e][d].ver} (currently on ${ye})`)}},[]),t.createElement(L,{style:a.container},t.createElement(r,{style:a.addonText,label:()=>t.createElement(k,{style:a.addonName},d),leading:e=="plugin"?t.createElement(Oe,{width:32,height:32}):t.createElement(Fe,{width:32,height:32}),trailing:t.createElement(Ne,{style:a.addonEdit,onPress:()=>{e=="plugin"?F(d)&&!y?xe(d,()=>x("GET")):Y(d,f.url,()=>{oe(!1),ce(e,d),x("REMOVE")}):V(d)&&!y?Lt(d,()=>x("GET")):ee(d,f.url,()=>{oe(!1),ce(e,d),x("REMOVE")})}},t.createElement(k,{style:a.addonEditText},ae)),subLabel:f.description}),[1].filter(M=>Boolean(_e)).map(M=>t.createElement(t.Fragment,null,t.createElement(k,{style:[a.sectionTitle,{color:"#e74c3c",fontFamily:g.Fonts.PRIMARY_SEMIBOLD}]},"Notice"),t.createElement(k,{style:[a.sectionContent,{borderColor:"#e74c3c"}]},t.createElement(Ue,{content:_e,addonType:e,addonName:d})))),t.createElement(Ct,{horizontal:!0,data:E,style:a.previews,renderItem:({index:M,item:_})=>{if(_.type=="image")return t.createElement(Re,{style:{width:_.width,height:_.height,margin:5},source:{uri:_.url},onLoad:({nativeEvent:{source:{width:v,height:N}}})=>{let I=v/N;v=I<1?s*2/5:s*2/3,N=v/I;let O=Object.assign([],E);O[M].width=v,O[M].height=N,i(O)}});if(_.type=="video")return t.createElement($t,{style:{width:_.width,height:_.height},source:{uri:_.url},controls:!0,paused:!0,onLoad:({naturalSize:{width:v,height:N}})=>{let I=v/N;v=I<1?s*2/5:s*2/3,N=v/I;let O=Object.assign([],E);O[M].width=v,O[M].height=N,i(O)}})},showsHorizontalScrollIndicator:!0}),t.createElement(k,{style:a.sectionTitle},"Description"),t.createElement(k,{style:a.sectionContent},t.createElement(Ue,{content:c,addonType:e,addonName:d})))}function je({isSetting:e=!1}){const n=C.createThemedStyleSheet({container:{flex:1,backgroundColor:g.ThemeColorMap.BACKGROUND_PRIMARY}}),o=Z.useNavigation(),a=X(),[s,c]=t.useState(""),[h,E]=t.useState(re().map(i=>i.name));return t.createElement(t.Fragment,null,t.createElement(ke,{placeholder:"Search plugins",onChangeText:i=>c(i)}),t.createElement(L,{style:n.container},Object.keys(a).sort().filter(i=>i.toLowerCase().includes(s.toLowerCase())).map(i=>t.createElement(r,{label:a[i].version?`${i} - v${a[i].version}`:i,subLabel:a[i].description,leading:h.includes(i)?t.createElement(r.Icon,{source:p.Uninstall}):t.createElement(r.Icon,{source:p.Download}),trailing:r.Arrow,onPress:()=>{b(m,"_selected_plugin",i),e?o.push("EnmityCustomPage",{Navigation:o,pageName:" ",pagePanel:()=>t.createElement(K,{addonType:"plugin"})}):o.navigate("PluginDetail")},onLongPress:()=>{h.includes(i)?xe(i,()=>{let d=Object.assign([],h);d.splice(d.indexOf(i),1),E(d)}):Y(i,a[i].url,()=>{let d=Object.assign([],h);d.push(i),E(d)})}}))))}function Ge({isSetting:e=!1}){const n=C.createThemedStyleSheet({container:{flex:1,backgroundColor:g.ThemeColorMap.BACKGROUND_PRIMARY}}),o=Z.useNavigation(),a=J(),[s,c]=t.useState(""),[h,E]=t.useState(se().map(i=>i.name));return t.createElement(t.Fragment,null,t.createElement(ke,{placeholder:"Search themes",onChangeText:i=>c(i)}),t.createElement(L,{style:n.container},Object.keys(a).sort().filter(i=>i.toLowerCase().includes(s.toLowerCase())).map(i=>t.createElement(r,{label:a[i].version?`${i} - v${a[i].version}`:i,subLabel:a[i].description,leading:h.includes(i)?t.createElement(r.Icon,{source:p.Uninstall}):t.createElement(r.Icon,{source:p.Download}),trailing:r.Arrow,onPress:()=>{b(m,"_selected_theme",i),e?o.push("EnmityCustomPage",{Navigation:o,pageName:" ",pagePanel:()=>t.createElement(K,{addonType:"theme"})}):o.navigate("ThemeDetail")}}))))}function He({isSetting:e=!1}){const n=C.createThemedStyleSheet({container:{flex:1,backgroundColor:g.ThemeColorMap.BACKGROUND_PRIMARY}}),o=Z.useNavigation(),a=Z.useIsFocused(),s=X(),c=J(),h=Ee(s),E=we(c);let[i,d]=t.useState(h.length?h:["@"]),[l,f]=t.useState(E.length?E:["@"]);const[$,R]=t.useState(Boolean(S(m,"check_updates",!0)));return t.useEffect(()=>{let w=he("plugin"),y=Object.assign([],i.filter(x=>!w.includes(x)));d(y.length?y:["@"]);let oe=he("theme"),ae=Object.assign([],l.filter(x=>!oe.includes(x)));f(ae.length?ae:["@"])},[a]),t.createElement(L,{style:n.container},t.createElement(P,{title:"UPDATE"},t.createElement(r,{label:"Check updates on startup",leading:t.createElement(r.Icon,{source:p.Update}),trailing:t.createElement(q,{value:$,onValueChange:w=>{R(w),b(m,"check_updates",w)}})})),t.createElement(P,{title:"PLUGINS"},i.map(w=>w==="@"?t.createElement(r,{label:"No updates are found for plugins"}):t.createElement(r,{label:w&&`${w} - v${F(w).version} -> v${s[w].version}`,subLabel:s[w].description,leading:t.createElement(r.Icon,{source:p.Download}),trailing:r.Arrow,onPress:()=>{b(m,"_selected_plugin",w),e?o.push("EnmityCustomPage",{Navigation:o,pageName:" ",pagePanel:()=>t.createElement(K,{addonType:"plugin"})}):o.navigate("PluginDetail")},onLongPress:()=>{Y(w,s[w].url,()=>{ce("plugin",w);let y=Object.assign([],i);y.splice(y.indexOf(w),1),d(y.length?y:["@"])})}}))),t.createElement(P,{title:"THEMES"},l.map(w=>w==="@"?t.createElement(r,{label:"No updates are found for themes"}):t.createElement(r,{label:w&&`${w} - v${V(w).version} -> v${c[w].version}`,subLabel:c[w].description,leading:t.createElement(r.Icon,{source:p.Download}),trailing:r.Arrow,onPress:()=>{b(m,"_selected_theme",w),e?o.push("EnmityCustomPage",{Navigation:o,pageName:" ",pagePanel:()=>t.createElement(K,{addonType:"theme"})}):o.navigate("ThemeDetail")},onLongPress:()=>{ee(w,c[w].url,()=>{ce("theme",w);let y=Object.assign([],l);y.splice(y.indexOf(w),1),f(y.length?y:["@"])})}}))))}function Ye(){const e=C.createThemedStyleSheet({container:{flex:1,backgroundColor:g.ThemeColorMap.BACKGROUND_PRIMARY},importText:{color:"white",height:40,paddingLeft:15}}),n=X(),o=J(),[a,s]=t.useState({"":{}}),[c,h]=t.useState({"":{}});function E(l){const f=re().map(y=>y.name),$=se().map(y=>y.name);let R={},w={};l[0].split(";").filter(y=>Object.keys(n).includes(y)).forEach(y=>{R[y]=Object.assign(n[y],{installed:f.includes(y)})}),s(Object.keys(R).length?R:{"":{}}),l[1].split(";").filter(y=>Object.keys(o).includes(y)).forEach(y=>{w[y]=Object.assign(o[y],{installed:$.includes(y)})}),h(Object.keys(w).length?w:{"":{}})}function i(l,f=void 0){let $=l.split("|");if($.length!=2){let R=f||"Invalid text format. Please make sure that you entered correct text.";return A.open({content:R,source:p.Fail}),!1}else return $}let d;return t.createElement(L,{style:e.container},t.createElement(P,{title:"IMPORT"},t.createElement(r,{style:e.importBackup,label:"Import from backup",subLabel:"Import installed addons from backup that linked to your discord account.",leading:t.createElement(r.Icon,{source:p.Import}),trailing:r.Arrow,onPress:()=>{Ht().then(l=>{let f=i(l,"No backup was found.");f&&(E(f),A.open({content:"Successfully imported addons from backup!",source:p.Check}))})}})),t.createElement(P,null,t.createElement(Mt,{style:e.importText,ref:l=>{d=l},placeholder:"Paste exported text",onSubmitEditing:l=>{let f=i(l.nativeEvent.text);f&&E(f)}}),t.createElement(r,{label:"Clear Input",trailing:r.Arrow,onPress:()=>{d.clear(),s({"":{}}),h({"":{}})}})),t.createElement(P,{title:"PLUGINS"},Object.keys(a).map(l=>a[l].url?t.createElement(r,{label:a[l].version?`${l} - v${a[l].version}`:l,subLabel:a[l].description,leading:a[l].installed?t.createElement(r.Icon,{source:p.Check}):t.createElement(r.Icon,{source:p.Download}),trailing:a[l].installed?void 0:r.Arrow,onPress:()=>{Y(l,n[l].url,()=>{let f=Object.assign({},a);f[l].installed=!0,s(f)})}}):t.createElement(r,{label:"There are no imported plugins yet"}))),t.createElement(P,{title:"THEMES"},Object.keys(c).map(l=>c[l].url?t.createElement(r,{label:c[l].version?`${l} - v${c[l].version}`:l,subLabel:c[l].description,leading:c[l].installed?t.createElement(r.Icon,{source:p.Check}):t.createElement(r.Icon,{source:p.Download}),trailing:c[l].installed?void 0:r.Arrow,onPress:()=>{ee(l,o[l].url,()=>{let f=Object.assign({},c);f[l].installed=!0,h(f)})}}):t.createElement(r,{label:"There are no imported themes yet"}))))}function Ve(){const e=C.createThemedStyleSheet({container:{flex:1,backgroundColor:g.ThemeColorMap.BACKGROUND_PRIMARY}}),[n,o]=t.useState(Boolean(S(m,"auto_backup")));return t.createElement(L,{style:e.container},t.createElement(P,{title:"EXPORT"},t.createElement(r,{label:"Automatically create backup",subLabel:"Automatically save backup of installed addons. It will be linked with your discord account.",leading:t.createElement(r.Icon,{source:p.Export}),trailing:t.createElement(q,{value:n,onValueChange:a=>{o(a),a&&Le(),b(m,"auto_backup",a)}})})),t.createElement(P,{title:"ADVANCED"},t.createElement(r,{label:"Export addons as text",subLabel:"Export installed addons as text that you can import manually.",leading:t.createElement(r.Icon,{source:p.Copy}),trailing:r.Arrow,onPress:()=>{$e.setString(Be()),A.open({content:"Copied addon list to clipboard!",source:p.Copy})}})))}const Vt="https://github.com/m4fn3/AddonManager",Kt="https://raw.githubusercontent.com/m4fn3/AddonManager/master/manifest.json",zt="https://raw.githubusercontent.com/m4fn3/AddonManager/master/dist/AddonManager.js",Wt="https://raw.githubusercontent.com/m4fn3/AddonManager/master/changelogs.json";function Ke(e,n){window.enmity.plugins.installPlugin(zt,()=>{ie.show({title:"AddonManager",body:`Updated from ${e} to ${n}!
4 | Do you want to reload Discord now?`,confirmText:"Yes",cancelText:"Later",onConfirm:()=>Yt()})})}function ze(e=!1){D.get(Kt).then(n=>{const o=JSON.parse(n.text),a=F(o.name);o.version.localeCompare(a.version,void 0,{numeric:!0})===1?(e||!e&&S(m,"ignored",null)!=o.version)&&D.get(Wt).then(s=>{const c=JSON.parse(s.text);let h="";c[o.version]&&(h=`
5 |
6 | - Changelogs
7 | ${c[o.version]}`),ie.show({title:"AddonManager",body:`New version v${o.version} is available!${h}`,confirmText:"Update",cancelText:"Ignore",onConfirm:()=>{b(m,"_updating",!0),Ke(a.version,o.version)},onCancel:()=>b(m,"ignored",o.version)})}):e?ie.show({title:"AddonManager",body:`You are using latest version v${a.version}!`,confirmText:"OK"}):b(m,"ignored",null)}).catch(n=>{n.status===404&&ie.show({title:"AddonManager",body:"Failed to check for updates. Please check GitHub manually.",confirmText:"GitHub",cancelText:"Close",onConfirm:()=>W.openURL(Vt)})})}function We(){const e=C.createThemedStyleSheet({container:{flex:1,backgroundColor:g.ThemeColorMap.BACKGROUND_PRIMARY}}),[n,o]=t.useState(Boolean(S(m,"check_updates_me",!0))),[a,s]=t.useState(Boolean(S(m,"add_to_settings",!0))),[c,h]=t.useState(Boolean(S(m,"long_press_downloader",!0)));return t.createElement(L,{style:e.container},t.createElement(P,{title:"OPTIONS"},t.createElement(r,{label:"Check updates of AddonManager itself on startup",subLabel:"You can also click here to check updates manually",leading:t.createElement(r.Icon,{source:p.Update}),trailing:t.createElement(q,{value:n,onValueChange:E=>{o(E),b(m,"check_updates_me",E)}}),onPress:()=>{ze(!0)}}),t.createElement(r,{label:"Add the AddonManager section to settings",leading:t.createElement(r.Icon,{source:p.Add}),trailing:t.createElement(q,{value:a,onValueChange:E=>{s(E),b(m,"add_to_settings",E)}})}),t.createElement(r,{label:"Show a download option on long press links",leading:t.createElement(r.Icon,{source:p.Link}),trailing:t.createElement(q,{value:c,onValueChange:E=>{h(E),b(m,"long_press_downloader",E)}})})))}const Xt=Ae("HelpMessage"),ne=me.createStackNavigator();function fe(){return t.createElement(ne.Navigator,{initialRouteName:"Home",headerMode:"screen",screenOptions:{...xt}},t.createElement(ne.Screen,{name:"Home",component:Xe,options:{headerShown:!1}}),[[je,"Plugins"],[Ge,"Themes"],[Ve,"Export"],[Ye,"Import"],[He,"Update"],[We,"Settings"]].map(([e,n])=>t.createElement(ne.Screen,{name:n,component:e})),t.createElement(ne.Screen,{name:"PluginDetail",component:()=>t.createElement(K,{addonType:"plugin"}),options:{title:""}}),t.createElement(ne.Screen,{name:"ThemeDetail",component:()=>t.createElement(K,{addonType:"theme"}),options:{title:""}}))}function Xe({settings:e}){const n=C.createThemedStyleSheet({container:{backgroundColor:g.ThemeColorMap.BACKGROUND_PRIMARY},header:{flexDirection:"row",justifyContent:"center",alignItems:"center"},image:{width:70,height:70,marginTop:20,marginLeft:20},title:{flexDirection:"column"},notice:{marginTop:30,marginLeft:20,marginRight:20},name:{fontSize:30,paddingTop:20,paddingLeft:20,paddingRight:30,color:g.ThemeColorMap.HEADER_PRIMARY},author:{fontSize:15,paddingLeft:50,color:g.ThemeColorMap.HEADER_SECONDARY},info:{height:45,paddingTop:3,paddingBottom:3,justifyContent:"center",alignItems:"center"},footer:{color:g.ThemeColorMap.HEADER_SECONDARY,textAlign:"center",paddingTop:10,paddingBottom:20}}),o=Z.useNavigation(),a=S(m,"ignored",null);return t.useEffect(()=>{D.get(G(ft)).then(s=>{b(m,"compatibility",s.text)})},[]),t.createElement(L,{style:n.container},t.createElement(ge,{style:n.header},t.createElement(Re,{source:{uri:"https://avatars.githubusercontent.com/u/43488869"},style:n.image}),t.createElement(ge,{style:n.title},t.createElement(k,{style:n.name},"AddonManager"),t.createElement(k,{style:n.author},"by mafu"))),a?t.createElement(Ne,{style:n.notice,onPress:()=>{const s=F(m);Ke(s.version,a)}},t.createElement(Xt,{messageType:0},`New version of AddonManager is available. Click here to update to v${a}!`)):t.createElement(t.Fragment,null),t.createElement(P,{title:"STORE"},t.createElement(r,{label:"Browse plugins",leading:t.createElement(Oe,{width:24,height:24}),trailing:r.Arrow,onPress:()=>{e?o.push("EnmityCustomPage",{Navigation:o,pageName:"Plugins",pagePanel:()=>t.createElement(je,{isSetting:!0})}):o.navigate("Plugins")}}),t.createElement(r,{label:"Browse themes",leading:t.createElement(Fe,{width:24,height:24}),trailing:r.Arrow,onPress:()=>{e?o.push("EnmityCustomPage",{Navigation:o,pageName:"Themes",pagePanel:()=>t.createElement(Ge,{isSetting:!0})}):o.navigate("Themes")}}),t.createElement(r,{label:"Export addons",leading:t.createElement(r.Icon,{source:p.Export}),trailing:r.Arrow,onPress:()=>{e?o.push("EnmityCustomPage",{Navigation:o,pageName:"Export",pagePanel:Ve}):o.navigate("Export")}}),t.createElement(r,{label:"Import addons",leading:t.createElement(r.Icon,{source:p.Import}),trailing:r.Arrow,onPress:()=>{e?o.push("EnmityCustomPage",{Navigation:o,pageName:"Import",pagePanel:Ye}):o.navigate("Import")}}),t.createElement(r,{label:"Update addons",leading:t.createElement(r.Icon,{source:p.Update}),trailing:r.Arrow,onPress:()=>{e?o.push("EnmityCustomPage",{Navigation:o,pageName:"Update",pagePanel:()=>t.createElement(He,{isSetting:!0})}):o.navigate("Update")}}),t.createElement(r,{label:"Settings",leading:t.createElement(r.Icon,{source:p.Settings}),trailing:r.Arrow,onPress:()=>{e?o.push("EnmityCustomPage",{Navigation:o,pageName:"Settings",pagePanel:()=>t.createElement(We,{isSetting:!0})}):o.navigate("Settings")}})),t.createElement(P,{title:"INFORMATION"},t.createElement(r,{label:"Follow me on Twitter",style:n.info,trailing:r.Arrow,leading:t.createElement(r.Icon,{source:p.Twitter}),onPress:()=>{W.openURL("https://twitter.com/m4fn3")}}),t.createElement(r,{label:"Visit my server for help",style:n.info,trailing:r.Arrow,leading:t.createElement(r.Icon,{source:p.Discord}),onPress:()=>{At.acceptInviteAndTransitionToInviteChannel({inviteKey:"TrCqPTCrdq",context:{location:"Invite Button Embed"},callback:()=>{o.pop()}})}}),t.createElement(r,{label:"Check Source on GitHub",style:n.info,trailing:r.Arrow,leading:t.createElement(r.Icon,{source:p.GitHub}),onPress:()=>{W.openURL("https://github.com/m4fn3/AddonManager")}})),t.createElement(k,{style:n.footer},`v${Ce}`))}var Je;(function(e){e[e.BuiltIn=0]="BuiltIn",e[e.Guild=1]="Guild",e[e.DM=2]="DM"})(Je||(Je={}));var be;(function(e){e[e.Chat=1]="Chat",e[e.User=2]="User",e[e.Message=3]="Message"})(be||(be={}));var qe;(function(e){e[e.BuiltIn=0]="BuiltIn",e[e.BuiltInText=1]="BuiltInText",e[e.BuiltInIntegration=2]="BuiltInIntegration",e[e.Bot=3]="Bot",e[e.Placeholder=4]="Placeholder"})(qe||(qe={}));var Ze;(function(e){e[e.Role=1]="Role",e[e.User=2]="User"})(Ze||(Ze={}));var Qe;(function(e){e[e.SubCommand=1]="SubCommand",e[e.SubCommandGroup=2]="SubCommandGroup",e[e.String=3]="String",e[e.Integer=4]="Integer",e[e.Boolean=5]="Boolean",e[e.User=6]="User",e[e.Channel=7]="Channel",e[e.Role=8]="Role",e[e.Mentionnable=9]="Mentionnable",e[e.Number=10]="Number",e[e.Attachment=11]="Attachment"})(Qe||(Qe={}));var et;(function(e){e[e.ApplicationCommand=2]="ApplicationCommand",e[e.MessageComponent=3]="MessageComponent"})(et||(et={}));const tt=me.createStackNavigator();var Jt=({name:e="AddonManager",component:n=ge}={})=>{const o=C.createThemedStyleSheet({container:{backgroundColor:g.ThemeColorMap.BACKGROUND_MOBILE_SECONDARY,flex:1},cardStyle:{backgroundColor:g.ThemeColorMap.BACKGROUND_MOBILE_PRIMARY,color:g.ThemeColorMap.TEXT_NORMAL},header:{backgroundColor:g.ThemeColorMap.BACKGROUND_MOBILE_SECONDARY,shadowColor:"transparent",elevation:0},headerText:{color:g.ThemeColorMap.HEADER_PRIMARY},headerButton:{color:g.ThemeColorMap.HEADER_PRIMARY}});return t.createElement(st.NavigationContainer,{independent:!0},t.createElement(tt.Navigator,{initialRouteName:e,style:o.container,screenOptions:{cardOverlayEnabled:!1,cardShadowEnabled:!1,cardStyle:o.cardStyle,headerStyle:o.header,headerTitleAlign:"center",safeAreaInsets:{top:0}}},t.createElement(tt.Screen,{name:e,component:n,options:{headerTitleStyle:{color:"white"},headerLeft:()=>t.createElement(_t,{color:o.headerButton.color,title:"Close",onPress:()=>le.pop()}),...me.TransitionPresets.ModalPresentationIOS}})))};function de(e,n,o){return window.enmity.utilities.findInReactTree(e,n,o)}const qt=Nt(e=>{var n,o,a;return(a=(o=(n=e._dispatcher)==null?void 0:n._actionHandlers)==null?void 0:o._dependencyGraph)==null?void 0:a.nodes});qt._dispatcher._actionHandlers._dependencyGraph.nodes;function Zt(e,n,o,a=!1){const[s,c]=Ie(B.byProps("EmojiRow"),B.byName("ActionSheet",!1)),{Version:h}=it.InfoDictionaryManager;parseInt(h.substring(0,3))>164?typeof c.default=="function"&&e.after(c,"default",(E,i,d)=>{const l=de(d,f=>f.sheetKey);!(l!=null&&l.sheetKey)||!l.sheetKey.includes(n)||(a?e.before:e.after)(l==null?void 0:l.content,"type",(f,$,R)=>{o($,R)})}):typeof s.default=="function"&&e.after(s,"default",(E,[i],d)=>{o(i,d)})}const[Qt,en,tn,nn,on,nt]=Ie(B.byName("MessagesConnected",!1),B.byName("MessagesWrapperConnected",!1),B.byProps("openPrivateChannel"),B.byName("UserSettingsOverviewWrapper",!1),B.byProps("transitionTo"),B.byProps("openLazy","hideActionSheet")),{Platform:{isPad:ve}}=H("View","Text");let Se=!1;const an=T("ic_information_24px"),ot="643945264868098049";function Te(){A.open({content:"nvm. It is the normal behaviour on iPad as of now.",source:an}),Se=!0,on.transitionTo("/channels/@me",void 0),tn.openPrivateChannel(ot)}const z=dt("AddonManager"),rn={...ht,onStart(){const e={id:"addon",name:"addon",displayName:"addon",description:"Open AddonManager",displayDescription:"Open AddonManager",type:be.Chat,execute:async function(a,s){ve?Te():le.push(Jt,{component:fe,name:"AddonManager"})}};this.commands=[e];try{Zt(z,"LongPressUrl",(a,s)=>{if(S(m,"long_press_downloader",!0)){let c=a[0].header.title;if(a[0].options.filter(h=>h.label.includes("Download")).length)return;if(c.startsWith("http")){if(c.endsWith(".js")){let h=c.split("/").slice(-1)[0].replace(".js","");a[0].options.unshift({label:"Download as a plugin",onPress:()=>{Y(h,c),nt.hideActionSheet()}})}else if(c.endsWith(".json")){let h=c.split("/").slice(-1)[0].replace(".json","");a[0].options.unshift({label:"Download as a theme",onPress:()=>{ee(h,c),nt.hideActionSheet()}})}}}},!0)}catch{}const n=z.after(nn,"default",(a,s,c)=>{const h=de(c,E=>{var i;return((i=E.type)==null?void 0:i.name)==="UserSettingsOverview"});z.after(h.type.prototype,"render",({props:{navigation:E}},i,d)=>{const l=de(d,f=>f.key==="Enmity");!de(d,f=>f.label==="AddonManager")&&S(m,"add_to_settings",!0)&&l.props.children.push(t.createElement(Rt,null),t.createElement(r,{label:"AddonManager",leading:t.createElement(r.Icon,{source:p.SettingIcon}),trailing:t.createElement(Pt,null),onPress:()=>{ve?(le.pop(),Te()):E.push("AddonManager",{navigation:E})}})),n()})});z.after(ct,"default",(a,s,c)=>({...c,AddonManager:{key:"AddonManager",title:"AddonManager",render:()=>t.createElement(fe,null)}}));const o=Qt||en;z.after(o,"default",(a,s,c)=>{var h,E;if(Se&&((E=(h=s[0].channel)==null?void 0:h.recipients)==null?void 0:E.includes(ot)))return t.createElement(fe,null);Se=!1}),S(m,"check_updates_me",!0)&&(S(m,"_updating",!1)?b(m,"_updating",!1):ze()),["plugin","theme"].forEach(a=>Ot(a)),St(),Tt(),Ft()},onStop(){z.unpatchAll()},getSettingsPanel({settings:e}){return ve&&(le.pop(),Te()),t.createElement(Xe,{settings:e})}};rt(rn);
8 |
--------------------------------------------------------------------------------
/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "AddonManager",
3 | "version": "1.1.8",
4 | "description": "Manage plugins & themes easily!",
5 | "authors": [
6 | {
7 | "name": "mafu",
8 | "id": "519760564755365888"
9 | }
10 | ],
11 | "color": "#00ffff"
12 | }
--------------------------------------------------------------------------------
/src/components/Detail.tsx:
--------------------------------------------------------------------------------
1 | import {ScrollView, Text, Image, FlatList, FormRow, TouchableOpacity} from 'enmity/components'
2 | import {React, Constants, REST, Linking, StyleSheet, Toasts} from 'enmity/metro/common'
3 | import {getPlugin} from "enmity/managers/plugins"
4 | import {version} from "enmity/api/native"
5 | import {get} from "enmity/api/settings"
6 | // @ts-ignore
7 | import {name as plugin_name} from '../../manifest.json'
8 | import {getCompatibility, getDetailURL, getPluginDatabase, getThemeDatabase, randomizeURL} from "../utils/fetch"
9 | import {PluginIcon, ThemeIcon} from "../utils/icons"
10 | import {getTheme, getThemeColors, installPlugin, installTheme, addCachedUpdated, uninstallPlugin, uninstallTheme} from "../utils/addon"
11 | import {compare, getUpdatablePlugins, getUpdatableThemes} from "../utils/update"
12 | import {filterColor, ReactNative, Video} from "../utils/common"
13 | import HyperLink from "./HyperLink";
14 |
15 | function Detail({addonType}) {
16 | let editTextBgColor = getThemeColors("PRIMARY_DARK_500") // -> "#..." テーマに存在しない場合はデフォルトに変更(undefined)
17 | let editTextColor = editTextBgColor ? filterColor(editTextBgColor, Constants.ThemeColorMap.TEXT_NORMAL[0], Constants.ThemeColorMap.TEXT_NORMAL[1]) : Constants.ThemeColorMap.HEADER_PRIMARY
18 | editTextBgColor = editTextBgColor ? editTextBgColor : Constants.ThemeColorMap.BACKGROUND_SECONDARY
19 | const styles = StyleSheet.createThemedStyleSheet({
20 | container: {
21 | flex: 1,
22 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_PRIMARY,
23 | padding: 10
24 | },
25 | previews: {
26 | marginTop: 20,
27 | justifyContent: 'center'
28 | },
29 | addonName: {
30 | color: Constants.ThemeColorMap.TEXT_NORMAL,
31 | fontFamily: Constants.Fonts.PRIMARY_SEMIBOLD,
32 | fontSize: 20
33 | },
34 | addonText: {
35 | borderBottomWidth: 1,
36 | borderBottomColor: Constants.ThemeColorMap.HEADER_PRIMARY,
37 | paddingBottom: 20
38 | },
39 | sectionTitle: {
40 | marginTop: 20,
41 | marginLeft: 15,
42 | color: Constants.ThemeColorMap.HEADER_PRIMARY,
43 | },
44 | sectionContent: {
45 | margin: 10,
46 | borderRadius: 10,
47 | borderWidth: 1,
48 | borderColor: Constants.ThemeColorMap.HEADER_PRIMARY,
49 | color: Constants.ThemeColorMap.TEXT_NORMAL,
50 | padding: 10
51 | },
52 | addonEdit: {
53 | backgroundColor: editTextBgColor,
54 | paddingTop: 10,
55 | paddingBottom: 10,
56 | borderRadius: 20,
57 | borderWidth: 1,
58 | width: 80,
59 | alignItems: 'center',
60 | borderColor: editTextBgColor,
61 | overflow: "hidden"
62 | },
63 | addonEditText: {
64 | color: editTextColor,
65 | fontFamily: Constants.Fonts.PRIMARY_SEMIBOLD
66 | },
67 | hyperLink: {
68 | color: Constants.ThemeColorMap.TEXT_LINK
69 | }
70 | })
71 |
72 | const screen_width = ReactNative.useWindowDimensions().width
73 | const [description, setDescription] = React.useState("Loading description...")
74 | const [previews, setPreviews] = React.useState([])
75 | const addonName = get(plugin_name, `_selected_${addonType}`).toString()
76 |
77 | const addons = addonType == "plugin" ? getPluginDatabase() : getThemeDatabase()
78 | const data = addons[addonName]
79 | let updatableAddons = addonType == "plugin" ? getUpdatablePlugins(addons) : getUpdatableThemes(addons)
80 |
81 | let installed = addonType == "plugin" ? Boolean(getPlugin(addonName)) : Boolean(getTheme(addonName))
82 | let isUpdatable = updatableAddons.includes(addonName)
83 | const [updatable, setUpdatable] = React.useState(isUpdatable)
84 | const [editText, setEditText] = React.useState(installed ? (updatable ? "UPDATE" : "REMOVE") : "GET")
85 | const [notice, setNotice] = React.useState(undefined)
86 |
87 |
88 | React.useEffect(() => {
89 | REST.get(randomizeURL(getDetailURL(addonType, addonName))).then(raw => {
90 | let data = JSON.parse(raw.text)
91 | setDescription(data.description)
92 | let draftPreviews = Object.assign(
93 | data.images.map((url) => {
94 | return {"url": url, "width": 1, "height": 1, "type": "image"}
95 | }),
96 | data.videos.map((url) => {
97 | return {"url": url, "width": null, "height": null, "type": "video"}
98 | })
99 | )
100 | setPreviews(draftPreviews)
101 | }).catch(response => {
102 | if (response.status === 404) {
103 | setDescription("No description.")
104 | }
105 | })
106 |
107 | // 互換性
108 | const compat = getCompatibility()
109 | if (addonName in compat[addonType]) {
110 | let flag = true // バージョンテキスト出ない場合は常に表示
111 | if (compat[addonType][addonName].ver.includes("~")){
112 | let vers = compat[addonType][addonName].ver.split("~")
113 | let min_ = vers[0] ? vers[0] : "0.0"
114 | let max_ = vers[1] ? vers[1] : "999.0"
115 | if (compare(min_, version) >= 0 && compare(version, max_) >= 0) { //min <= version <= max
116 | flag = false // 対応バージョンの確認
117 | }
118 | }
119 | if (flag) setNotice(compat[addonType][addonName].text + `\n\nCompatibility: ${compat[addonType][addonName].ver} (currently on ${version})`)
120 | }
121 | }, [])
122 |
123 | return (
124 |
125 | {addonName}}
128 | leading={addonType == "plugin" ? : }
129 | trailing={
130 | {
133 | if (addonType == "plugin") {
134 | if (getPlugin(addonName) && !updatable) uninstallPlugin(addonName, () => setEditText("GET"))
135 | else installPlugin(addonName, data.url, () => {
136 | setUpdatable(false)
137 | addCachedUpdated(addonType, addonName)
138 | setEditText("REMOVE")
139 | })
140 | } else {
141 | if (getTheme(addonName) && !updatable) uninstallTheme(addonName, () => setEditText("GET"))
142 | else installTheme(addonName, data.url, () => {
143 | setUpdatable(false)
144 | addCachedUpdated(addonType, addonName)
145 | setEditText("REMOVE")
146 | })
147 | }
148 | }}>
149 | {editText}
150 | }
151 | subLabel={data.description}
152 | />
153 | {
154 | [1].filter(_ => Boolean(notice)).map(_ => (
155 | <>
156 | Notice
157 |
158 |
159 |
160 | >
161 | ))
162 | }
163 | {
168 | if (item.type == "image") {
169 | return { // 読込後に横幅/縦幅を設定
177 | let aspect = width / height
178 | width = aspect < 1 ? screen_width * 2 / 5 : screen_width * 2 / 3
179 | height = width / aspect
180 | let new_previews = Object.assign([], previews)
181 | new_previews[index].width = width
182 | new_previews[index].height = height
183 | setPreviews(new_previews)
184 | }}
185 | />
186 | } else if (item.type == "video") {
187 | return
215 | )
216 | }
217 |
218 | export {Detail}
219 |
--------------------------------------------------------------------------------
/src/components/Export.tsx:
--------------------------------------------------------------------------------
1 | import {Constants, React, StyleSheet, Toasts} from "enmity/metro/common"
2 | import {get, set} from "enmity/api/settings"
3 | import {FormRow, FormSection, FormSwitch, ScrollView} from "enmity/components"
4 |
5 | // @ts-ignore
6 | import {name as plugin_name} from '../../manifest.json'
7 | import {Clipboard, Icons} from "../utils/common"
8 | import {createBackup, createExportText} from "../utils/backup"
9 |
10 |
11 | function Export() {
12 | const styles = StyleSheet.createThemedStyleSheet({
13 | container: {
14 | flex: 1,
15 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_PRIMARY,
16 | }
17 | })
18 | const [switchVal, setSwitchVal] = React.useState(Boolean(get(plugin_name, "auto_backup"))) // 格納されている値は0,1になっているので真偽値に変換
19 |
20 |
21 | return (
22 |
23 |
24 | }
28 | trailing={
29 | {
32 | setSwitchVal(value)
33 | // create backup when it got enabled too
34 | if (value) createBackup()
35 | set(plugin_name, "auto_backup", value)
36 | }}
37 | />
38 | }
39 | />
40 |
41 |
42 | }
46 | trailing={FormRow.Arrow}
47 | onPress={() => {
48 | Clipboard.setString(createExportText())
49 | Toasts.open({
50 | content: "Copied addon list to clipboard!",
51 | source: Icons.Copy
52 | })
53 | }}
54 | />
55 |
56 |
57 | )
58 | }
59 |
60 | export {Export}
--------------------------------------------------------------------------------
/src/components/Home.tsx:
--------------------------------------------------------------------------------
1 | import {View, FormSection, FormRow, Image, Text, ScrollView, TouchableOpacity} from "enmity/components"
2 | import {Constants, NavigationStack, React, REST, StyleSheet} from "enmity/metro/common"
3 | import {Linking} from "enmity/metro/common"
4 | import {get, set} from "enmity/api/settings"
5 |
6 | // @ts-ignore
7 | import {name as plugin_name, name, version} from '../../manifest.json'
8 | import {PluginIcon, ThemeIcon} from "../utils/icons"
9 | import {Plugins} from "./Plugins"
10 | import {Themes} from "./Themes"
11 | import {Update} from "./Update"
12 | import {Import} from "./Import"
13 | import {Export} from "./Export";
14 | import {screenOptions} from "../utils/common"
15 | import {Detail} from "./Detail"
16 | import {Icons, Invites, Navigator} from "../utils/common"
17 | import {compatibilityURL, randomizeURL} from "../utils/fetch"
18 | import {getByName} from "enmity/metro"
19 | import {getPlugin} from "enmity/managers/plugins"
20 | import {updatePlugin} from "../utils/updater"
21 | import {Settings} from "./Settings"
22 |
23 | const HelpMessage = getByName("HelpMessage")
24 |
25 | const Stack = NavigationStack.createStackNavigator()
26 |
27 | function HomeStack() {
28 | return (
29 |
36 |
43 | {
44 | [[Plugins, "Plugins"], [Themes, "Themes"], [Export, "Export"], [Import, "Import"], [Update, "Update"], [Settings, "Settings"]].map(([Component, name]) =>
45 |
49 | )
50 | }
51 | }
54 | options={{
55 | title: ""
56 | }}
57 | />
58 | }
61 | options={{
62 | title: ""
63 | }}
64 | />
65 |
66 | )
67 | }
68 |
69 | function Home({settings}) {
70 | const styles = StyleSheet.createThemedStyleSheet({
71 | container: {
72 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_PRIMARY,
73 | },
74 | header: {
75 | flexDirection: "row",
76 | justifyContent: "center",
77 | alignItems: "center"
78 | },
79 | image: {
80 | width: 70,
81 | height: 70,
82 | marginTop: 20,
83 | marginLeft: 20
84 | },
85 | title: {
86 | flexDirection: "column",
87 | },
88 | notice: {
89 | marginTop: 30,
90 | marginLeft: 20,
91 | marginRight: 20
92 | },
93 | name: {
94 | fontSize: 30,
95 | paddingTop: 20,
96 | paddingLeft: 20,
97 | paddingRight: 30,
98 | color: Constants.ThemeColorMap.HEADER_PRIMARY,
99 | },
100 | author: {
101 | fontSize: 15,
102 | paddingLeft: 50,
103 | color: Constants.ThemeColorMap.HEADER_SECONDARY,
104 | },
105 | info: {
106 | height: 45,
107 | paddingTop: 3,
108 | paddingBottom: 3,
109 | justifyContent: "center",
110 | alignItems: "center"
111 | },
112 | footer: {
113 | color: Constants.ThemeColorMap.HEADER_SECONDARY,
114 | textAlign: 'center',
115 | paddingTop: 10,
116 | paddingBottom: 20
117 | }
118 | })
119 | const Navigation = Navigator.useNavigation()
120 | const ignored_ver = get(plugin_name, "ignored", null)
121 |
122 | React.useEffect(() => {
123 | REST.get(randomizeURL(compatibilityURL)).then(raw => {
124 | set(plugin_name, "compatibility", raw.text)
125 | })
126 | }, [])
127 |
128 | return (
129 |
130 |
131 |
135 |
136 | AddonManager
137 | by mafu
138 |
139 |
140 | {
141 | ignored_ver ?
142 | {
145 | const plugin = getPlugin(plugin_name)
146 | updatePlugin(plugin.version, ignored_ver)
147 | }}
148 | >
149 |
150 | {`New version of AddonManager is available. Click here to update to v${ignored_ver}!`}
151 |
152 |
153 | : <>>
154 | }
155 |
156 | }
159 | trailing={FormRow.Arrow}
160 | onPress={() => {
161 | if (settings) {
162 | Navigation.push("EnmityCustomPage", {
163 | Navigation,
164 | pageName: `Plugins`,
165 | pagePanel: () =>
166 | })
167 | } else {
168 | Navigation.navigate("Plugins")
169 | }
170 | }}
171 | />
172 | }
175 | trailing={FormRow.Arrow}
176 | onPress={() => {
177 | if (settings) {
178 | Navigation.push("EnmityCustomPage", {
179 | Navigation,
180 | pageName: `Themes`,
181 | pagePanel: () =>
182 | })
183 | } else {
184 | Navigation.navigate("Themes")
185 | }
186 | }}
187 | />
188 | }
191 | trailing={FormRow.Arrow}
192 | onPress={() => {
193 | if (settings) {
194 | Navigation.push("EnmityCustomPage", {
195 | Navigation,
196 | pageName: `Export`,
197 | pagePanel: Export
198 | })
199 | } else {
200 | Navigation.navigate("Export")
201 | }
202 | }}
203 | />
204 | }
207 | trailing={FormRow.Arrow}
208 | onPress={() => {
209 | if (settings) {
210 | Navigation.push("EnmityCustomPage", {
211 | Navigation,
212 | pageName: `Import`,
213 | pagePanel: Import
214 | })
215 | } else {
216 | Navigation.navigate("Import")
217 | }
218 | }}
219 | />
220 | }
223 | trailing={FormRow.Arrow}
224 | onPress={() => {
225 | if (settings) {
226 | Navigation.push("EnmityCustomPage", {
227 | Navigation,
228 | pageName: `Update`,
229 | pagePanel: () =>
230 | })
231 | } else {
232 | Navigation.navigate("Update")
233 | }
234 | }}
235 | />
236 | }
239 | trailing={FormRow.Arrow}
240 | onPress={() => {
241 | if (settings) {
242 | Navigation.push("EnmityCustomPage", {
243 | Navigation,
244 | pageName: `Settings`,
245 | pagePanel: () =>
246 | })
247 | } else {
248 | Navigation.navigate("Settings")
249 | }
250 | }}
251 | />
252 |
253 |
254 | }
259 | onPress={() => {
260 | Linking.openURL("https://twitter.com/m4fn3")
261 | }}
262 | />
263 | }
268 | onPress={() => {
269 | Invites.acceptInviteAndTransitionToInviteChannel({
270 | inviteKey: 'TrCqPTCrdq',
271 | context: {location: 'Invite Button Embed'},
272 | callback: () => {
273 | Navigation.pop()
274 | }
275 | })
276 | }}
277 | />
278 | }
283 | onPress={() => {
284 | Linking.openURL("https://github.com/m4fn3/AddonManager")
285 | }}
286 | />
287 |
288 |
289 | {`v${version}`}
290 |
291 |
292 | )
293 | }
294 |
295 | export {HomeStack, Home}
--------------------------------------------------------------------------------
/src/components/HyperLink.tsx:
--------------------------------------------------------------------------------
1 | import {Text} from "enmity/components";
2 | import {Constants, Linking, React, StyleSheet, Toasts} from "enmity/metro/common"
3 | import {installPlugin, installTheme} from "../utils/addon"
4 | import {Clipboard, Icons} from "../utils/common"
5 |
6 | export default ({content, addonType, addonName}) => {
7 | const styles = StyleSheet.createThemedStyleSheet({
8 | hyperLink: {
9 | color: Constants.ThemeColorMap.TEXT_LINK
10 | }
11 | })
12 | let descriptions = content.replace(/(\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*)/ig, "$1").split("")
13 | return descriptions.map((text) => {
14 | if (text.startsWith("http")) {
15 | return (
16 | {
19 | let download_link = addonType == "plugin" ? ".js" : ".json"
20 | if (text.endsWith(download_link)) {
21 | if (addonType == "plugin") installPlugin(addonName, text)
22 | else installTheme(addonName, text)
23 | } else {
24 | Linking.openURL(text)
25 | }
26 | }}
27 | onLongPress={() => {
28 | Clipboard.setString(text)
29 | Toasts.open({
30 | content: `Copied URL to clipboard`,
31 | source: Icons.Copy
32 | })
33 | }}
34 | >
35 | {text}
36 |
37 | )
38 | } else {
39 | return (
40 | {text}
41 | )
42 | }
43 | })
44 | }
--------------------------------------------------------------------------------
/src/components/Import.tsx:
--------------------------------------------------------------------------------
1 | import {FormRow, ScrollView, FormSection, TextInput} from 'enmity/components'
2 | import {React,Constants, Toasts, StyleSheet} from 'enmity/metro/common'
3 | import {getPlugins} from "enmity/managers/plugins"
4 |
5 | import {getThemes, installPlugin, installTheme} from "../utils/addon"
6 | import {getPluginDatabase, getThemeDatabase} from "../utils/fetch"
7 | import {getBackup} from "../utils/backup"
8 | import {Icons} from "../utils/common"
9 |
10 | function Import() {
11 |
12 | const styles = StyleSheet.createThemedStyleSheet({
13 | container: {
14 | flex: 1,
15 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_PRIMARY,
16 | },
17 | importText: {
18 | color: "white",
19 | height: 40,
20 | paddingLeft: 15
21 | }
22 | })
23 |
24 | const plugins = getPluginDatabase()
25 | const themes = getThemeDatabase()
26 |
27 | // {"name": {name, url, version, installed}}
28 | const [pluginList, setPluginList] = React.useState({"": {}})
29 | const [themeList, setThemeList] = React.useState({"": {}})
30 |
31 | function processExportedText(content) {
32 | const installedPlugins = getPlugins().map((plugin) => plugin.name)
33 | const installedThemes = getThemes().map((theme) => theme.name)
34 | let importedPlugins = {}
35 | let importedThemes = {}
36 | content[0].split(";").filter((name) => Object.keys(plugins).includes(name)).forEach((name) => {
37 | importedPlugins[name] = Object.assign(plugins[name], {"installed": installedPlugins.includes(name)})
38 | })
39 | setPluginList(Object.keys(importedPlugins).length ? importedPlugins : {"": {}})
40 | content[1].split(";").filter((name) => Object.keys(themes).includes(name)).forEach((name) => {
41 | importedThemes[name] = Object.assign(themes[name], {"installed": installedThemes.includes(name)})
42 | })
43 | setThemeList(Object.keys(importedThemes).length ? importedThemes : {"": {}})
44 | }
45 |
46 | function checkFormat(text, error = undefined) {
47 | let content = text.split("|")
48 | if (content.length != 2) {
49 | let text = error ? error : "Invalid text format. Please make sure that you entered correct text."
50 | Toasts.open({
51 | content: text,
52 | source: Icons.Fail
53 | })
54 | return false
55 | } else {
56 | return content
57 | }
58 | }
59 |
60 | let importText
61 |
62 | return (
63 |
64 |
65 | }
70 | trailing={FormRow.Arrow}
71 | onPress={() => {
72 | getBackup().then((text) => {
73 | let res = checkFormat(text, "No backup was found.")
74 | if (res) {
75 | processExportedText(res)
76 | Toasts.open({
77 | content: "Successfully imported addons from backup!",
78 | source: Icons.Check
79 | })
80 | }
81 | })
82 | }}
83 | />
84 |
85 |
86 | {
89 | importText = input
90 | }}
91 | placeholder="Paste exported text"
92 | onSubmitEditing={(event) => {
93 | let res = checkFormat(event.nativeEvent.text)
94 | if (res) {
95 | processExportedText(res)
96 | }
97 | }}
98 | />
99 | {
103 | importText.clear()
104 | setPluginList({"": {}})
105 | setThemeList({"": {}})
106 | }}
107 | />
108 |
109 |
110 | {
111 | Object.keys(pluginList).map((name) =>
112 | !pluginList[name].url
113 | ?
114 | : : }
118 | trailing={pluginList[name].installed ? undefined : FormRow.Arrow}
119 | onPress={() => {
120 | installPlugin(name, plugins[name].url, () => {
121 | let newPlugins = Object.assign({}, pluginList) // そのままコピーすると再レンダリングされないので参照付きコピーではなく新規作成すること!
122 | newPlugins[name].installed = true
123 | setPluginList(newPlugins)
124 | })
125 | }}
126 | />
127 | )
128 | }
129 |
130 |
131 | {
132 | Object.keys(themeList).map((name) =>
133 | !themeList[name].url
134 | ?
135 | : : }
139 | trailing={themeList[name].installed ? undefined : FormRow.Arrow}
140 | onPress={() => {
141 | installTheme(name, themes[name].url, () => {
142 | let newThemes = Object.assign({}, themeList) // そのままコピーすると再レンダリングされないので参照付きコピーではなく新規作成すること!
143 | newThemes[name].installed = true
144 | setThemeList(newThemes)
145 | })
146 | }}
147 | />
148 | )
149 | }
150 |
151 |
152 | )
153 | }
154 |
155 | export {Import}
--------------------------------------------------------------------------------
/src/components/Page.tsx:
--------------------------------------------------------------------------------
1 | import {React, Navigation, NavigationNative, NavigationStack, Constants, StyleSheet} from 'enmity/metro/common'
2 | import {Button, View} from 'enmity/components'
3 | // @ts-ignore
4 | import {name as plugin_name} from '../../manifest.json'
5 |
6 | const Settings = NavigationStack.createStackNavigator()
7 |
8 | export default ({name = 'AddonManager', component = View} = {}) => {
9 | const styles = StyleSheet.createThemedStyleSheet({
10 | container: {
11 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_MOBILE_SECONDARY,
12 | flex: 1,
13 | },
14 | cardStyle: {
15 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_MOBILE_PRIMARY,
16 | color: Constants.ThemeColorMap.TEXT_NORMAL
17 | },
18 | header: {
19 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_MOBILE_SECONDARY,
20 | shadowColor: 'transparent',
21 | elevation: 0,
22 | },
23 | headerText: {
24 | color: Constants.ThemeColorMap.HEADER_PRIMARY,
25 | },
26 | headerButton: {
27 | color: Constants.ThemeColorMap.HEADER_PRIMARY
28 | }
29 | })
30 |
31 | return
32 |
46 | (
54 |
64 | ;
65 | }
--------------------------------------------------------------------------------
/src/components/Plugins.tsx:
--------------------------------------------------------------------------------
1 | import {FormRow, ScrollView} from 'enmity/components'
2 | import {Constants, React, StyleSheet} from 'enmity/metro/common'
3 | import {set} from "enmity/api/settings"
4 | import {getPlugins} from "enmity/managers/plugins"
5 | // @ts-ignore
6 | import {name as plugin_name} from '../../manifest.json'
7 | import {Search, Navigator, Icons} from "../utils/common"
8 | import {Detail} from "./Detail"
9 | import {getPluginDatabase} from "../utils/fetch"
10 | import {installPlugin, uninstallPlugin} from "../utils/addon"
11 |
12 | function Plugins({isSetting = false}) {
13 | const styles = StyleSheet.createThemedStyleSheet({
14 | container: {
15 | flex: 1,
16 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_PRIMARY,
17 | }
18 | })
19 | const Navigation = Navigator.useNavigation()
20 | const plugins = getPluginDatabase()
21 |
22 | const [query, setQuery] = React.useState("")
23 | // [name, name, name...]
24 | const [installedPlugins, setInstalledPlugins] = React.useState(getPlugins().map((plugin) => plugin.name))
25 |
26 | return (
27 | <>
28 | setQuery(text)}
31 | />
32 |
33 | {Object.keys(plugins).sort().filter(key => key.toLowerCase().includes(query.toLowerCase())).map(key =>
34 | : }
38 | trailing={FormRow.Arrow}
39 | onPress={() => {
40 | set(plugin_name, "_selected_plugin", key)
41 | if (isSetting) {
42 | Navigation.push("EnmityCustomPage", {
43 | Navigation,
44 | pageName: " ",
45 | pagePanel: () =>
46 | })
47 | } else {
48 | Navigation.navigate("PluginDetail")
49 | }
50 | }}
51 | onLongPress={() => {
52 | if (installedPlugins.includes(key)) {
53 | uninstallPlugin(key, () => {
54 | let newInstalledPlugins = Object.assign([], installedPlugins)
55 | newInstalledPlugins.splice(newInstalledPlugins.indexOf(key), 1)
56 | setInstalledPlugins(newInstalledPlugins)
57 | })
58 | } else {
59 | installPlugin(key, plugins[key].url, () => {
60 | let newInstalledPlugins = Object.assign([], installedPlugins)
61 | newInstalledPlugins.push(key)
62 | setInstalledPlugins(newInstalledPlugins)
63 | })
64 | }
65 | }}
66 | />
67 | )}
68 |
69 | >
70 | )
71 | }
72 |
73 | export {Plugins}
--------------------------------------------------------------------------------
/src/components/Settings.tsx:
--------------------------------------------------------------------------------
1 | import {Constants, React, StyleSheet} from "enmity/metro/common"
2 | import {get, set} from "enmity/api/settings"
3 | import {FormRow, FormSection, FormSwitch, ScrollView} from "enmity/components"
4 |
5 | // @ts-ignore
6 | import {name as plugin_name} from '../../manifest.json'
7 | import {Icons} from "../utils/common"
8 | import {checkUpdate} from "../utils/updater"
9 |
10 | function Settings() {
11 | const styles = StyleSheet.createThemedStyleSheet({
12 | container: {
13 | flex: 1,
14 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_PRIMARY,
15 | }
16 | })
17 | const [switchVal, setSwitchVal] = React.useState(Boolean(get(plugin_name, "check_updates_me",true))) // 格納されている値は0,1になっているので真偽値に変換
18 | const [switchVal2, setSwitchVal2] = React.useState(Boolean(get(plugin_name, "add_to_settings",true))) // 格納されている値は0,1になっているので真偽値に変換
19 | const [switchVal3, setSwitchVal3] = React.useState(Boolean(get(plugin_name, "long_press_downloader",true))) // 格納されている値は0,1になっているので真偽値に変換
20 |
21 |
22 | return (
23 |
24 |
25 | }
29 | trailing={
30 | {
33 | setSwitchVal(value)
34 | set(plugin_name, "check_updates_me", value)
35 | }}
36 | />
37 | }
38 | onPress={() => {
39 | checkUpdate(true)
40 | }}
41 | />
42 | }
45 | trailing={
46 | {
49 | setSwitchVal2(value)
50 | set(plugin_name, "add_to_settings", value)
51 | }}
52 | />
53 | }
54 | />
55 | }
58 | trailing={
59 | {
62 | setSwitchVal3(value)
63 | set(plugin_name, "long_press_downloader", value)
64 | }}
65 | />
66 | }
67 | />
68 |
69 |
70 | )
71 | }
72 |
73 | export {Settings}
--------------------------------------------------------------------------------
/src/components/Themes.tsx:
--------------------------------------------------------------------------------
1 | import {FormRow, ScrollView} from 'enmity/components'
2 | import {Constants, React, StyleSheet} from 'enmity/metro/common'
3 | import {getThemeDatabase} from "../utils/fetch"
4 | import {set} from "enmity/api/settings"
5 | // @ts-ignore
6 | import {name as plugin_name} from "../../manifest.json"
7 | import {getThemes} from "../utils/addon"
8 | import {Search, Navigator, Icons} from "../utils/common"
9 | import {Detail} from "./Detail"
10 |
11 |
12 | function Themes({isSetting=false}) {
13 | const styles = StyleSheet.createThemedStyleSheet({
14 | container: {
15 | flex: 1,
16 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_PRIMARY,
17 | }
18 | })
19 | const Navigation = Navigator.useNavigation()
20 | const themes = getThemeDatabase()
21 | const [query, setQuery] = React.useState("")
22 | // [name, name, name...]
23 | const [installedThemes, setInstalledThemes] = React.useState(getThemes().map((theme) => theme.name))
24 |
25 | return (
26 | <>
27 | setQuery(text)}
30 | />
31 |
32 | {Object.keys(themes).sort().filter(key => key.toLowerCase().includes(query.toLowerCase())).map(key =>
33 | : }
37 | trailing={FormRow.Arrow}
38 | onPress={() => {
39 | set(plugin_name, "_selected_theme", key)
40 | if (isSetting) {
41 | Navigation.push("EnmityCustomPage", {
42 | Navigation,
43 | pageName: " ",
44 | pagePanel: () =>
45 | })
46 | } else {
47 | Navigation.navigate("ThemeDetail")
48 | }
49 | }}
50 | />
51 | )}
52 |
53 | >
54 | )
55 | }
56 |
57 | export {Themes}
--------------------------------------------------------------------------------
/src/components/Update.tsx:
--------------------------------------------------------------------------------
1 | import {FormRow, ScrollView, FormSection, FormSwitch} from 'enmity/components'
2 | import {React, Constants, StyleSheet} from 'enmity/metro/common'
3 | import {getPlugin} from "enmity/managers/plugins"
4 | import {get, set} from "enmity/api/settings"
5 |
6 | // @ts-ignore
7 | import {name as plugin_name} from '../../manifest.json'
8 | import {getUpdatablePlugins, getUpdatableThemes} from "../utils/update"
9 | import {Navigator, Icons} from "../utils/common"
10 | import {Detail} from "./Detail"
11 | import {getPluginDatabase, getThemeDatabase} from "../utils/fetch"
12 | import {installPlugin, installTheme, getTheme, getCachedUpdated, addCachedUpdated} from "../utils/addon"
13 |
14 |
15 | function Update({isSetting = false}) {
16 | const styles = StyleSheet.createThemedStyleSheet({
17 | container: {
18 | flex: 1,
19 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_PRIMARY,
20 | }
21 | })
22 | const Navigation = Navigator.useNavigation()
23 | const isFocused = Navigator.useIsFocused()
24 |
25 | const plugins = getPluginDatabase()
26 | const themes = getThemeDatabase()
27 |
28 | const updatablePlugins = getUpdatablePlugins(plugins)
29 | const updatableThemes = getUpdatableThemes(themes)
30 |
31 | // // [name, name, name...]
32 | let [pluginList, setPluginList] = React.useState(updatablePlugins.length ? updatablePlugins : ["@"])
33 | let [themeList, setThemeList] = React.useState(updatableThemes.length ? updatableThemes : ["@"])
34 | const [switchVal, setSwitchVal] = React.useState(Boolean(get(plugin_name, "check_updates", true))) // 格納されている値は0,1になっているので真偽値に変換
35 | // const [switchVal2, setSwitchVal2] = React.useState(Boolean(get(plugin_name, "check_updates_me", true))) // 格納されている値は0,1になっているので真偽値に変換
36 |
37 | React.useEffect(() => {
38 | let updated_plugins = getCachedUpdated("plugin")
39 | let new_plugins = Object.assign([], pluginList.filter(name => !updated_plugins.includes(name)))
40 | setPluginList(new_plugins.length ? new_plugins : ["@"])
41 | let updated_themes = getCachedUpdated("theme")
42 | let new_themes = Object.assign([], themeList.filter(name => !updated_themes.includes(name)))
43 | setThemeList(new_themes.length ? new_themes : ["@"])
44 | }, [isFocused]) // backしてきたときも更新するために
45 |
46 |
47 | return (
48 |
49 |
50 | }
53 | trailing={
54 | {
57 | setSwitchVal(value)
58 | set(plugin_name, "check_updates", value)
59 | }}
60 | />
61 | }
62 | />
63 |
64 |
65 | {
66 | pluginList.map((name) =>
67 | name === "@"
68 | ?
69 | : v${plugins[name].version}` : name}
71 | subLabel={plugins[name].description}
72 | leading={}
73 | trailing={FormRow.Arrow}
74 | onPress={() => {
75 | set(plugin_name, "_selected_plugin", name)
76 | if (isSetting) {
77 | Navigation.push("EnmityCustomPage", {
78 | Navigation,
79 | pageName: " ",
80 | pagePanel: () =>
81 | })
82 | } else {
83 | Navigation.navigate("PluginDetail")
84 | }
85 | }}
86 | onLongPress={() => {
87 | installPlugin(name, plugins[name].url, () => {
88 | addCachedUpdated("plugin", name)
89 | let newPlugins = Object.assign([], pluginList) // そのままコピーすると再レンダリングされないので参照付きコピーではなく新規作成すること!
90 | newPlugins.splice(newPlugins.indexOf(name), 1)
91 | setPluginList(newPlugins.length ? newPlugins : ["@"])
92 | })
93 | }}
94 | />
95 | )
96 | }
97 |
98 |
99 | {
100 | themeList.map((name) =>
101 | name === "@"
102 | ?
103 | : v${themes[name].version}` : name}
105 | subLabel={themes[name].description}
106 | leading={}
107 | trailing={FormRow.Arrow}
108 | onPress={() => {
109 | set(plugin_name, "_selected_theme", name)
110 | if (isSetting) {
111 | Navigation.push("EnmityCustomPage", {
112 | Navigation,
113 | pageName: " ",
114 | pagePanel: () =>
115 | })
116 | } else {
117 | Navigation.navigate("ThemeDetail")
118 | }
119 | }}
120 | onLongPress={() => {
121 | installTheme(name, themes[name].url, () => {
122 | addCachedUpdated("theme", name)
123 | let newThemes = Object.assign([], themeList) // そのままコピーすると再レンダリングされないので参照付きコピーではなく新規作成すること!
124 | newThemes.splice(newThemes.indexOf(name), 1)
125 | setThemeList(newThemes.length ? newThemes : ["@"])
126 | })
127 | }}
128 | />
129 | )
130 | }
131 |
132 |
133 | )
134 | }
135 |
136 | export {Update}
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 | import {registerPlugin} from 'enmity/managers/plugins'
2 | import {Navigation, React, Toasts, Scenes} from 'enmity/metro/common'
3 | import {create} from 'enmity/patcher'
4 |
5 | // @ts-ignore
6 | import manifest, {name as plugin_name} from '../manifest.json'
7 | import {checkPluginDatabaseVer, checkThemeDatabaseVer} from "./utils/fetch"
8 | import {checkAddonUpdate} from "./utils/update"
9 | import "./utils/native"
10 | import {Home, HomeStack} from "./components/Home"
11 | import {installPlugin, installTheme, resetCachedUpdated} from "./utils/addon"
12 | import {ApplicationCommandType, Command} from "enmity/api/commands"
13 | import {bulk, filters, getByName} from "enmity/metro"
14 | import Page from "./components/Page"
15 | import {getByProps} from "enmity/modules"
16 | import {getIDByName} from "enmity/api/assets"
17 | import {get, set} from "enmity/api/settings"
18 | import {checkUpdate} from "./utils/updater"
19 | import {findInReactTree} from "enmity/utilities"
20 | import {FormArrow, FormDivider, FormRow} from "enmity/components"
21 | import {Icons} from "./utils/common";
22 | import {patchActionSheet} from "../../hook";
23 |
24 | const [
25 | Messages,
26 | MessagesWrapper,
27 | PrivateChannelActions,
28 | SettingsView,
29 | RouteUtils,
30 | LazyActionSheet
31 | ] = bulk(
32 | filters.byName('MessagesConnected', false),
33 | filters.byName('MessagesWrapperConnected', false),
34 | filters.byProps("openPrivateChannel"),
35 | filters.byName("UserSettingsOverviewWrapper", false),
36 | filters.byProps("transitionTo"),
37 | filters.byProps("openLazy", "hideActionSheet")
38 | )
39 |
40 | const {Platform: {isPad}} = getByProps("View", "Text")
41 | let doTransition = false
42 | const InfoIcon = getIDByName("ic_information_24px")
43 | const privateChannelId = "643945264868098049" // our beloved, Discord
44 |
45 | function burnIpad() {
46 | Toasts.open({
47 | content: `nvm. It is the normal behaviour on iPad as of now.`,
48 | source: InfoIcon
49 | })
50 | doTransition = true
51 | RouteUtils.transitionTo("/channels/@me", undefined) // in the case DM is already opened
52 | PrivateChannelActions.openPrivateChannel(privateChannelId)
53 | }
54 |
55 | const Patcher = create('AddonManager')
56 |
57 | const AddonManager = {
58 | ...manifest,
59 | onStart() {
60 | // define commands
61 | const addon: Command = {
62 | id: "addon",
63 | name: "addon",
64 | displayName: "addon",
65 | description: "Open AddonManager",
66 | displayDescription: "Open AddonManager",
67 | type: ApplicationCommandType.Chat,
68 | execute: async function (args, message) {
69 | if (isPad) burnIpad()
70 | else Navigation.push(Page, {component: HomeStack, name: "AddonManager"})
71 | }
72 | }
73 | this.commands = [addon]
74 |
75 | // patch the long press action sheet
76 | try {
77 | patchActionSheet(Patcher, "LongPressUrl", (args, res) => {
78 | if (get(plugin_name, "long_press_downloader", true)) {
79 | let url = args[0].header.title
80 | // avoid pushing it multiple times
81 | if (args[0].options.filter(item=>item.label.includes("Download")).length) return
82 | if (url.startsWith("http")) {
83 | if (url.endsWith(".js")) {
84 | let name = url.split("/").slice(-1)[0].replace(".js", "")
85 | args[0].options.unshift({
86 | label: "Download as a plugin",
87 | onPress: () => {
88 | installPlugin(name, url)
89 | LazyActionSheet.hideActionSheet()
90 | }
91 | })
92 | } else if (url.endsWith(".json")) {
93 | let name = url.split("/").slice(-1)[0].replace(".json", "")
94 | args[0].options.unshift({
95 | label: "Download as a theme",
96 | onPress: () => {
97 | installTheme(name, url)
98 | LazyActionSheet.hideActionSheet()
99 | }
100 | })
101 | }
102 | }
103 | }
104 | }, true)
105 | } catch(e) {
106 | // skipping this
107 | }
108 |
109 | // patch settings
110 | const unpatch = Patcher.after(SettingsView, 'default', (_, __, ret) => {
111 | const Overview = findInReactTree(ret, m => m.type?.name === 'UserSettingsOverview')
112 | Patcher.after(Overview.type.prototype, 'render', ({props: {navigation}}, __, res) => {
113 | const Enmity = findInReactTree(res, m => m.key === "Enmity")
114 | const AddonManagerRow = findInReactTree(res, m => m.label === "AddonManager") // avoid pushing it multiple times
115 | if (!AddonManagerRow && get(plugin_name, "add_to_settings", true)) {
116 | Enmity.props.children.push(
117 | ,
118 | }
121 | trailing={}
122 | onPress={() => {
123 | if (isPad) {
124 | Navigation.pop()
125 | burnIpad()
126 | } else {
127 | navigation.push('AddonManager', {navigation})
128 | }
129 | }}
130 | />
131 | )
132 | }
133 | unpatch()
134 | })
135 | })
136 | Patcher.after(Scenes, 'default', (_, __, res) => {
137 | return {
138 | ...res,
139 | AddonManager: {
140 | key: 'AddonManager',
141 | title: 'AddonManager',
142 | render: () =>
143 | }
144 | }
145 | })
146 |
147 | // hacky patch for ipads to take over DM
148 | const Messages_ = Messages ? Messages : MessagesWrapper // MessagesWrapper : 163+ / Messages : 162-
149 | Patcher.after(Messages_, 'default', (self, args, org) => {
150 | if (doTransition && args[0].channel?.recipients?.includes(privateChannelId)) {
151 | return
152 | } else { // unlock this state after the user goes to somewhere else (re-render may revert it if I put it into the above block)
153 | doTransition = false
154 | }
155 | })
156 | // check updates of the plugin itself
157 | if (get(plugin_name, "check_updates_me", true)) {
158 | if (get(plugin_name, "_updating", false)) {
159 | set(plugin_name, "_updating", false)
160 | } else {
161 | checkUpdate()
162 | }
163 | }
164 |
165 | // reset internal state
166 | let addons = ["plugin", "theme"]
167 | addons.forEach(addonType => resetCachedUpdated(addonType))
168 | // update internal assets
169 | checkPluginDatabaseVer()
170 | checkThemeDatabaseVer()
171 | // check updates of installed addons
172 | checkAddonUpdate()
173 | },
174 | onStop() {
175 | Patcher.unpatchAll()
176 | },
177 | getSettingsPanel({settings}) {
178 | if (isPad) {
179 | Navigation.pop()
180 | burnIpad()
181 | }
182 | return
183 | }
184 | }
185 |
186 | registerPlugin(AddonManager)
187 |
--------------------------------------------------------------------------------
/src/utils/addon.tsx:
--------------------------------------------------------------------------------
1 | import {Toasts} from "enmity/metro/common"
2 | import {get, set} from "enmity/api/settings"
3 | // @ts-ignore
4 | import {name as plugin_name} from '../../manifest.json'
5 | import {Icons} from "./common"
6 |
7 | function installPlugin(name, url, callback = () => {
8 | }) {
9 | // @ts-ignore
10 | window.enmity.plugins.installPlugin(url, (data) => {
11 | if (data.name === undefined) {
12 | Toasts.open({
13 | content: `Failed to install ${name}`,
14 | source: Icons.Fail
15 | })
16 | } else {
17 | Toasts.open({
18 | content: `Successfully installed ${name}!`,
19 | source: Icons.Check
20 | })
21 | callback()
22 | }
23 | })
24 | }
25 |
26 | function uninstallPlugin(name, callback = () => {
27 | }) {
28 | // @ts-ignore
29 | window.enmity.plugins.uninstallPlugin(name, (data) => {
30 | Toasts.open({
31 | content: `Successfully uninstalled ${name}!`,
32 | source: Icons.Check
33 | })
34 | callback()
35 | })
36 | }
37 |
38 | function installTheme(name, url, callback = () => {
39 | }) {
40 | // @ts-ignore
41 | window.enmity.themer.installTheme(url, (data) => {
42 | Toasts.open({
43 | content: `Successfully installed ${name}!`,
44 | source: Icons.Check
45 | })
46 | callback()
47 | })
48 | }
49 |
50 | function uninstallTheme(name, callback = () => {
51 | }) {
52 | // @ts-ignore
53 | window.enmity.themer.uninstallTheme(name, (data) => {
54 | Toasts.open({
55 | content: `Successfully uninstalled ${name}!`,
56 | source: Icons.Check
57 | })
58 | callback()
59 | })
60 | }
61 |
62 | function getTheme(name) {
63 | // @ts-ignore
64 | return window.enmity.themer.getThemeByName(name)
65 | }
66 |
67 | function getThemes() {
68 | // @ts-ignore
69 | return window.enmity.themer.listThemes()
70 | }
71 |
72 | function getThemeColors(tag) {
73 | try {
74 | // @ts-ignore
75 | let Theme = getTheme(window.enmity.themer.getTheme())
76 | return Theme ? Theme.colours[tag] : undefined
77 | } catch (e) {
78 | return undefined
79 | }
80 | }
81 |
82 | function addCachedUpdated(addonType, name) {
83 | let updated = getCachedUpdated("plugin")
84 | updated.push(name)
85 | set(plugin_name, `_updated_${addonType}s`, JSON.stringify(updated))
86 | }
87 |
88 | function resetCachedUpdated(addonType){
89 | set(plugin_name, `_updated_${addonType}s`, "[]")
90 | }
91 |
92 | function getCachedUpdated(addonType) {
93 | return JSON.parse(get(plugin_name, `_updated_${addonType}s`, "[]").toString())
94 | }
95 |
96 | export {installPlugin, installTheme, getTheme, getThemes, uninstallPlugin, uninstallTheme, getThemeColors, getCachedUpdated, addCachedUpdated, resetCachedUpdated}
--------------------------------------------------------------------------------
/src/utils/backup.tsx:
--------------------------------------------------------------------------------
1 | import {Token} from "enmity/metro/common"
2 | import {getByProps} from "enmity/metro"
3 | import {createExportText} from "../components/Export"
4 | import {getPlugins} from "enmity/managers/plugins"
5 | import {getThemes} from "./addon"
6 |
7 | const NoteStore = getByProps("updateNote")
8 |
9 | async function fetchNote(userId) {
10 | let res = await fetch(`https://discord.com/api/v9/users/@me/notes/${userId}`, {
11 | method: "GET",
12 | credentials: "include",
13 | headers: {
14 | "authorization": Token.getToken()
15 | }
16 | })
17 | let data = await res.json()
18 | return Object.keys(data).includes("note") ? data.note : ""
19 | }
20 |
21 | function setNote(userId, text){
22 | NoteStore.updateNote(userId, text)
23 | }
24 |
25 | function createBackup(){
26 | setNote("1048982327809818706", createExportText())
27 | }
28 |
29 | async function getBackup(){
30 | return fetchNote("1048982327809818706")
31 | }
32 |
33 | function createExportText() {
34 | let plugins = getPlugins().map((plugin) => plugin.name).join(";")
35 | // @ts-ignore
36 | let themes = getThemes().map((theme) => theme.name).join(";")
37 | return `${plugins}|${themes}`
38 | }
39 |
40 |
41 | export {createBackup, getBackup, createExportText}
--------------------------------------------------------------------------------
/src/utils/common.tsx:
--------------------------------------------------------------------------------
1 | import {Constants, React, StyleSheet} from "enmity/metro/common"
2 | import {FormRow} from "enmity/components"
3 | import {getIDByName} from "enmity/api/assets"
4 | import {getByName, getByProps} from "enmity/metro"
5 | import {getByKeyword} from "enmity/modules"
6 |
7 | // modules
8 | const Navigator = getByKeyword("getFocusedRoute")
9 | const Search = getByName('StaticSearchBarContainer')
10 | const Invites = getByProps('acceptInviteAndTransitionToInviteChannel')
11 | const ReactNative = getByProps("AppState")
12 | const Video = getByProps("DRMType", "FilterType").default
13 | const Clipboard = getByProps('setString')
14 |
15 | // icons
16 | const Icons = {
17 | Copy: getIDByName('ic_message_copy'),
18 | GitHub: getIDByName('img_account_sync_github_white'),
19 | Twitter: getIDByName('img_account_sync_twitter_white'),
20 | Discord: getIDByName('Discord'),
21 | Update: getIDByName('toast_image_saved'),
22 | Export: getIDByName('ic_reply_24px'),
23 | Import: getIDByName('ic_leave_stage'),
24 | Fail: getIDByName('Small'),
25 | Download: getIDByName('ic_download_24px'),
26 | Check: getIDByName('ic_check_24px'),
27 | Clear: getIDByName('ic_input_clear_24px'),
28 | Uninstall: getIDByName('ic_trash_24px'),
29 | Settings: getIDByName('ic_settings_white_24px'),
30 | Add: getIDByName('hub-add'),
31 | SettingIcon: getIDByName('ic_rulebook'), // ic_gridview
32 | Link: getIDByName('ic_link')
33 | }
34 |
35 | // styles
36 | const stackStyles = StyleSheet.createThemedStyleSheet({
37 | cardStyle: {
38 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_MOBILE_PRIMARY,
39 | color: Constants.ThemeColorMap.TEXT_NORMAL
40 | },
41 | header: {
42 | backgroundColor: Constants.ThemeColorMap.BACKGROUND_MOBILE_SECONDARY,
43 | shadowColor: 'transparent',
44 | elevation: 0,
45 | },
46 | headerText: {
47 | color: Constants.ThemeColorMap.HEADER_PRIMARY,
48 | }
49 | })
50 |
51 | const screenOptions = {
52 | cardStyle: stackStyles.cardStyle,
53 | headerStyle: stackStyles.header,
54 | headerTitleContainerStyle: stackStyles.headerText,
55 | headerTitleStyle: stackStyles.headerText,
56 | headerBackTitleStyle: stackStyles.headerText,
57 | headerBackImage: () => ,
58 | headerTitleAlign: 'center',
59 | safeAreaInsets: {
60 | top: 0,
61 | },
62 | }
63 |
64 |
65 | // func
66 | function filterColor(color, light, dark, boundary = 186){
67 | // Chooses whether the color should be Dark or Light depending on the background color of the element.
68 | // by Rosie (@acquitelol)
69 | let baseColor = color.replace("#", "")
70 | const parseColorAsInt = (color, digits, base) => parseInt(color.substring(digits[0], digits[1]), base)
71 | const red = parseColorAsInt(baseColor, [0, 2], 16),
72 | green = parseColorAsInt(baseColor, [2, 4], 16),
73 | blue = parseColorAsInt(baseColor, [4, 6], 16)
74 |
75 | return (((red + green + blue) / (255 * 3)) > boundary)
76 | ? dark
77 | : light
78 | }
79 |
80 |
81 | export {screenOptions, Icons, Navigator, Search, Invites, ReactNative, Video, Clipboard, filterColor}
--------------------------------------------------------------------------------
/src/utils/fetch.tsx:
--------------------------------------------------------------------------------
1 | import {REST} from 'enmity/metro/common'
2 | import {get, set} from 'enmity/api/settings'
3 | // @ts-ignore
4 | import {name as plugin_name} from '../../manifest.json'
5 |
6 | const rawURL = "https://raw.githubusercontent.com/m4fn3/AddonManagerDatabase/master/"
7 | // const rawURL = "https://raw.githubusercontent.com/m4fn3/Test/master/"
8 | const pluginDatabaseURL = rawURL + "plugins.json"
9 | const themeDatabaseURL = rawURL + "themes.json"
10 | const pluginDatabaseVerURL = rawURL + "plugins_update.txt"
11 | const themeDatabaseVerURL = rawURL + "themes_update.txt"
12 | const compatibilityURL = rawURL + "compatibility.json"
13 |
14 | function randomizeURL(url) {
15 | return `${url}?${Date.now()}`
16 | }
17 |
18 | function getDetailURL(addonType, name){
19 | return `${rawURL}${addonType}s/${name}.json`
20 | }
21 |
22 | function parseDatabase(name){
23 | try {
24 | return JSON.parse(get(plugin_name, name, "{}").toString())
25 | } catch {
26 | return {}
27 | }
28 | }
29 |
30 | function getPluginDatabase() {
31 | return parseDatabase("plugins")
32 | }
33 |
34 | function getThemeDatabase() {
35 | return parseDatabase("themes")
36 | }
37 |
38 | function getCompatibility(){
39 | return parseDatabase("compatibility")
40 | }
41 |
42 | function fetchPluginDatabase() {
43 | REST.get(randomizeURL(pluginDatabaseURL)).then(databaseRaw => {
44 | set(plugin_name, "plugins", databaseRaw.text)
45 | })
46 | }
47 |
48 | function fetchThemeDatabase() {
49 | REST.get(randomizeURL(themeDatabaseURL)).then(databaseRaw => {
50 | set(plugin_name, "themes", databaseRaw.text)
51 | })
52 | }
53 |
54 | function checkPluginDatabaseVer() {
55 | REST.get(randomizeURL(pluginDatabaseVerURL)).then(verRaw => {
56 | let ver = verRaw.text
57 | let plugins_ver = get(plugin_name, "plugins_ver")
58 | if (plugins_ver) {
59 | if (plugins_ver != ver) { // 更新がある場合
60 | set(plugin_name, "plugins_ver", ver)
61 | fetchPluginDatabase()
62 | }
63 | } else { // 初回
64 | set(plugin_name, "plugins_ver", ver)
65 | fetchPluginDatabase()
66 | }
67 | })
68 | }
69 |
70 | function checkThemeDatabaseVer() {
71 | REST.get(randomizeURL(themeDatabaseVerURL)).then(verRaw => {
72 | let ver = verRaw.text
73 | let themes_ver = get(plugin_name, "themes_ver")
74 | if (themes_ver) {
75 | if (themes_ver != ver) { // 更新がある場合
76 | set(plugin_name, "themes_ver", ver)
77 | fetchThemeDatabase()
78 | }
79 | } else {
80 | set(plugin_name, "themes_ver", ver)
81 | fetchThemeDatabase()
82 | }
83 | })
84 | }
85 |
86 | export {fetchPluginDatabase, fetchThemeDatabase, checkPluginDatabaseVer, checkThemeDatabaseVer, getPluginDatabase, getThemeDatabase, randomizeURL, getDetailURL, compatibilityURL, getCompatibility}
--------------------------------------------------------------------------------
/src/utils/icons.tsx:
--------------------------------------------------------------------------------
1 | // from https://github.com/enmity-mod/enmity/tree/main/src/core/screens/partials
2 |
3 | import { SVG, StyleSheet,Constants, React } from 'enmity/metro/common'
4 |
5 | export function PluginIcon({ height, width, ...rest }) {
6 | const styles = StyleSheet.createThemedStyleSheet({
7 | icon: {
8 | color: Constants.ThemeColorMap.INTERACTIVE_NORMAL,
9 | opacity: 0.75,
10 | marginLeft: 0.5
11 | }
12 | });
13 |
14 | return
15 |
16 |
17 | ;
18 | }
19 |
20 |
21 | export function ThemeIcon({ height, width, ...rest }) {
22 | const styles = StyleSheet.createThemedStyleSheet({
23 | icon: {
24 | color: Constants.ThemeColorMap.INTERACTIVE_NORMAL,
25 | opacity: 0.75,
26 | marginLeft: 0.5
27 | }
28 | });
29 |
30 | return
31 |
32 |
33 | ;
34 | }
--------------------------------------------------------------------------------
/src/utils/native.tsx:
--------------------------------------------------------------------------------
1 | // native.ts from enmity
2 | // https://github.com/enmity-mod/enmity/blob/main/src/modules/native.ts
3 |
4 | import {Linking} from 'enmity/metro/common'
5 | import {get} from "enmity/api/settings"
6 |
7 | // @ts-ignore
8 | import {name as plugin_name} from "../../manifest.json"
9 | import {createBackup} from "./backup"
10 |
11 | // @ts-ignore
12 | Linking.addEventListener('url', (url) => {
13 | let responseUrl = url.url
14 | responseUrl = decodeURIComponent(responseUrl.replace('com.hammerandchisel.discord://', ''))
15 | try {
16 | const response = JSON.parse(responseUrl)
17 | if (get(plugin_name, "auto_backup") && typeof response.data === "string" && ['installed_theme', 'overridden_theme', 'installed_plugin', 'overridden_plugin'].includes(response.data)) {
18 | createBackup()
19 | }
20 | } catch (e) {
21 | return
22 | }
23 | })
24 |
--------------------------------------------------------------------------------
/src/utils/update.tsx:
--------------------------------------------------------------------------------
1 | import {get, set} from "enmity/api/settings"
2 | import {getPlugin, getPlugins} from "enmity/managers/plugins"
3 | import {Toasts} from "enmity/metro/common"
4 |
5 | // @ts-ignore
6 | import {name as plugin_name} from '../../manifest.json'
7 | import {getPluginDatabase, getThemeDatabase} from "./fetch"
8 | import {getTheme, getThemes} from "./addon"
9 | import {Icons} from "./common"
10 |
11 | function checkAddonUpdate() {
12 | let val = get(plugin_name, "check_updates")
13 | if (val === undefined) {
14 | set(plugin_name, "check_updates", false)
15 | } else if (val) {
16 | const plugins = getPluginDatabase()
17 | const themes = getThemeDatabase()
18 | let updatablePlugins = getUpdatablePlugins(plugins)
19 | let updatableThemes = getUpdatableThemes(themes)
20 | if (updatablePlugins.length || updatableThemes.length) {
21 | let updatableAddons = updatablePlugins.concat(updatableThemes)
22 | let text = updatableAddons.join(", ")
23 | Toasts.open({
24 | content: `Updates are available for ${text}`,
25 | source: Icons.Download
26 | })
27 | }
28 | }
29 | }
30 |
31 | function compare(from, to) {
32 | return to.localeCompare(from, undefined, {numeric: true})
33 | }
34 |
35 | function isUpdate(from, to) { // from < to
36 | return compare(from, to) === 1
37 | }
38 |
39 |
40 | function getUpdatablePlugins(plugins) {
41 | const installedPlugins = getPlugins().map((plugin) => plugin.name)
42 | // バージョンを比較してアップデート可能なプラグインのリストを取得する - dbに存在することを確認,versionがない場合もあるのであることを先に確認
43 | return installedPlugins.filter((name) => Object.keys(plugins).includes(name) && Object.keys(plugins[name]).includes("version") && getPlugin(name).version && isUpdate(getPlugin(name).version, plugins[name].version))
44 | }
45 |
46 | function getUpdatableThemes(themes) {
47 | const installedThemes = getThemes().map((theme) => theme.name)
48 | return installedThemes.filter((name) => Object.keys(themes).includes(name) && Object.keys(themes[name]).includes("version") && getTheme(name).version && isUpdate(getTheme(name).version, themes[name].version))
49 | }
50 |
51 | export {checkAddonUpdate, getUpdatablePlugins, getUpdatableThemes, compare}
--------------------------------------------------------------------------------
/src/utils/updater.tsx:
--------------------------------------------------------------------------------
1 | import {REST, Dialog, Linking} from 'enmity/metro/common'
2 | import {getPlugin} from 'enmity/managers/plugins'
3 | import {get, set} from "enmity/api/settings"
4 | import {reload} from "enmity/api/native"
5 |
6 | // @ts-ignore
7 | import {name} from '../../manifest.json'
8 |
9 | const repoURL = "https://github.com/m4fn3/AddonManager"
10 | const manifestURL = "https://raw.githubusercontent.com/m4fn3/AddonManager/master/manifest.json"
11 | const installURL = "https://raw.githubusercontent.com/m4fn3/AddonManager/master/dist/AddonManager.js"
12 | const changelogURL = "https://raw.githubusercontent.com/m4fn3/AddonManager/master/changelogs.json"
13 |
14 |
15 | function updatePlugin(from, to) {
16 | // @ts-ignore
17 | window.enmity.plugins.installPlugin(installURL, () => {
18 | Dialog.show({
19 | title: "AddonManager",
20 | body: `Updated from ${from} to ${to}!\nDo you want to reload Discord now?`,
21 | confirmText: "Yes",
22 | cancelText: "Later",
23 | onConfirm: () => reload()
24 | })
25 | })
26 | }
27 |
28 |
29 | function checkUpdate(forceUpdate = false) {
30 | REST.get(manifestURL).then(manifestRaw => {
31 | const manifest = JSON.parse(manifestRaw.text)
32 | const plugin = getPlugin(manifest.name)
33 | if (manifest.version.localeCompare(plugin.version, undefined, {numeric: true}) === 1) { // latest > current
34 | if (forceUpdate || (!forceUpdate && get(name, "ignored", null) != manifest.version)) { // if update is not ignored
35 | REST.get(changelogURL).then(changelogRaw => {
36 | const changelogs = JSON.parse(changelogRaw.text)
37 | let changes = ""
38 | if (changelogs[manifest.version]) {
39 | changes = `\n\n- Changelogs\n${changelogs[manifest.version]}`
40 | }
41 | Dialog.show({
42 | title: "AddonManager",
43 | body: `New version v${manifest.version} is available!${changes}`,
44 | confirmText: "Update",
45 | cancelText: "Ignore",
46 | onConfirm: () => {
47 | set(name, "_updating", true)
48 | updatePlugin(plugin.version, manifest.version)
49 | },
50 | onCancel: () => set(name, "ignored", manifest.version)
51 | })
52 | })
53 | }
54 | } else if (forceUpdate) {
55 | Dialog.show({
56 | title: "AddonManager",
57 | body: `You are using latest version v${plugin.version}!`,
58 | confirmText: "OK"
59 | })
60 | } else { // up-to-date
61 | set(name, "ignored", null)
62 | }
63 | }).catch(response => {
64 | if (response.status === 404) {
65 | Dialog.show({
66 | title: "AddonManager",
67 | body: "Failed to check for updates. Please check GitHub manually.",
68 | confirmText: "GitHub",
69 | cancelText: "Close",
70 | onConfirm: () => Linking.openURL(repoURL),
71 | })
72 | }
73 | })
74 | }
75 |
76 | export {checkUpdate, updatePlugin}
--------------------------------------------------------------------------------