诸葛温侯 1 jaar geleden
commit
c9684e6a49

+ 5 - 0
.env

@@ -0,0 +1,5 @@
+# filename: .env
+# set this in .vscode/settings.json:
+# "python.envFile": "${workspaceFolder}/.env"
+SD_WEBUI_INTERPRETER_PATH="../../sd.webui/webui/venv/Scripts"
+PYTHONPATH="../../sd.webui/webui/"

+ 4 - 0
.vscode/settings.json

@@ -0,0 +1,4 @@
+{
+    "python.envFile": "${workspaceFolder}/.env",
+    "python.defaultInterpreterPath": "${workspaceFolder}/../../sd.webui/webui/venv/Scripts/"
+}

+ 663 - 0
LICENSE

@@ -0,0 +1,663 @@
+                    GNU AFFERO GENERAL PUBLIC LICENSE
+                       Version 3, 19 November 2007
+                       
+Copyright (c) 2023 a2569875/Chang Yu-Fan(張宇帆) – a2569875@gmail.com
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU Affero General Public License is a free, copyleft license for
+software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+our General Public Licenses are intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.
+
+  A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate.  Many developers of free software are heartened and
+encouraged by the resulting cooperation.  However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.
+
+  The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community.  It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server.  Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.
+
+  An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals.  This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU Affero General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Remote Network Interaction; Use with the GNU General Public License.
+
+  Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software.  This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the work with which it is combined will remain governed by version
+3 of the GNU General Public License.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time.  Such new versions
+will be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU Affero General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU Affero General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as published
+    by the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source.  For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code.  There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+<https://www.gnu.org/licenses/>.

+ 50 - 0
README.md

@@ -0,0 +1,50 @@
+[![Python](https://img.shields.io/badge/Python-%E2%89%A73.10-blue)](https://www.python.org/downloads/)
+[![License](https://img.shields.io/github/license/a2569875/lora-prompt-tool)](https://github.com/a2569875/lora-prompt-tool/blob/main/LICENSE)
+# LoRA Model Prompt Tool
+
+When you have trained many LoRA models, each model usually has its own model prompt, trigger words and usage method. In the past, external tools were needed to record them. This extension can help you save these model prompts and dedicated prompts, and quickly call them up when needed.
+
+[![buy me a coffee](readme/Artboard.svg)](https://www.buymeacoffee.com/a2569875 "buy me a coffee")
+
+[![LoRA-Prompt-Tool](https://res.cloudinary.com/marcomontalbano/image/upload/v1687840465/video_to_markdown/images/youtube--MVUNoxjrCzE-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://youtu.be/MVUNoxjrCzE "LoRA-Prompt-Tool")
+
+# Installation
+
+Go to \[Extensions\] -> \[Install from URL\] in webui and enter the following URL:
+```
+https://github.com/a2569875/lora-prompt-tool.git
+```
+Install and restart to complete installation.
+
+# Features
+
+* 1. Automatic add trigger words to prompts
+  - Insert prompts at the end of the prompt input box
+  - Insert prompts at the position where there are double commas ",,"
+  - Divided into prompts and reverse prompts
+  - Support txt2img and img2img
+
+* 2. Prompt search/filtering: When there are many prompts for a particular model, you can search/filter the prompts
+  - Supports regex search
+
+* 3. Editing and managing prompts
+  - Dedicated tab for editing prompts
+  - Can add, modify, delete prompts
+  - Supports CivitAI's JSON format
+  - Delete duplicate prompts
+  - Sort prompts
+  - Translate prompts
+
+* 4. Batch import of prompts
+  - Import from Civitai
+  - Import from Dreambooth models
+  - Import multiple lines of text
+
+  ## Videos
+[![LoRA-Prompt-Tool!](https://res.cloudinary.com/marcomontalbano/image/upload/v1683644210/video_to_markdown/images/youtube--QQ9YVjCO_9s-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=QQ9YVjCO_9s "LoRA-Prompt-Tool!")
+  
+  ## Acknowledgements
+*  [JackEllie's Stable-Siffusion community team](https://discord.gg/TM5d89YNwA) 、 [Youtube channel](https://www.youtube.com/@JackEllie)
+*  [Chinese Wikipedia community team](https://discord.gg/77n7vnu)
+
+<p align="center"><img src="https://count.getloli.com/get/@sd-webui-lora-prompt-tool.github" alt="sd-webui-lora-prompt-tool"></p>

+ 45 - 0
README.zh-tw.md

@@ -0,0 +1,45 @@
+[![Python](https://img.shields.io/badge/Python-%E2%89%A73.10-blue)](https://www.python.org/downloads/)
+[![License](https://img.shields.io/github/license/a2569875/lora-prompt-tool)](https://github.com/a2569875/lora-prompt-tool/blob/main/LICENSE)
+# LoRA模型觸發詞工具
+
+當你訓練了很多LoRA模型時,每個模型通常都有自己的模型觸發詞和使用方法,以往要使用外部工具來進行記錄
+這個擴展可以幫助你將這些模型的觸發詞和專用提示詞保存起來,並且在要使用時能快速地叫出來
+
+[![buy me a coffee](readme/Artboard.svg)](https://www.buymeacoffee.com/a2569875 "buy me a coffee")
+
+[![LoRA-Prompt-Tool!](https://res.cloudinary.com/marcomontalbano/image/upload/v1683644210/video_to_markdown/images/youtube--QQ9YVjCO_9s-c05b58ac6eb4c4700831b2b3070cd403.jpg)](https://www.youtube.com/watch?v=QQ9YVjCO_9s "LoRA-Prompt-Tool!")
+
+# 安裝
+
+將擴展解壓縮後,將lora-prompt-tool資料夾複製到\webui\extensions下,重新啟動webui即完成安裝
+
+# 功能
+* 1.自動加入提示詞
+  - 插入提示詞到提示詞輸入框的末尾
+  - 插入提示詞到中間有雙逗號 ",," 的位置
+  - 分為提示詞和反向提示詞
+  - txt2img和img2img支援
+
+* 2.提示詞搜索/篩選 : 當某個模型提示詞非常多時,可以搜索/篩選提示詞
+  - 支援regex(正規表達式)搜索
+
+* 3.編輯與管理提示詞
+  - 編輯提示詞的專屬頁籤
+  - 可以編輯、新增、修改、刪除
+  - 支援CivitAI的JSON
+  - 刪除重複的提示詞
+  - 排序提示詞
+  - 翻譯提示詞
+
+* 4.批次匯入提示詞
+  - 從Civitai匯入
+  - 從dreambooth模型匯入
+  - 文字多行匯入
+
+* ~~緒山真尋!~~
+
+## Acknowledgements
+*  [JackEllie的Stable-Siffusion的社群團隊](https://discord.gg/TM5d89YNwA) 、 [Youtube頻道](https://www.youtube.com/@JackEllie)
+*  [中文維基百科的社群團隊](https://discord.gg/77n7vnu)
+
+<p align="center"><img src="https://count.getloli.com/get/@sd-webui-lora-prompt-tool.github" alt="sd-webui-lora-prompt-tool"></p>

+ 231 - 0
javascript/AJAX.js

@@ -0,0 +1,231 @@
+(function(){
+
+function module_init() {
+    console.log("[lora-prompt-tool] load AJAX module");
+    lorahelper.lorahelp_js_ajax_txtbox_textarea = null;
+    lorahelper.lorahelp_js_ajax_txtbox_callback = function() {
+        lorahelper.debug('lorahelp_js_ajax_txtbox_callback callback');
+    }
+    lorahelper.call_lorahelp_js_ajax_txtbox_callback = function(){
+        lorahelper.lorahelp_js_ajax_txtbox_callback();
+    }
+    
+    function build_cors_request(url){
+        return new Promise((resolve, reject) => {
+            new myAJAX({
+                "action": "cors_request",
+                "url": url
+            }, lorahelper.js_cors_request_btn).then(response_message => {
+                const response_json = JSON.parse(response_message);
+                if(response_json.status === "error"){
+                    reject(response_json.message);
+                }
+                resolve(response_json.message);
+            }).error(error => {
+                throw new Error("Request failed");
+            }).sent();
+        });
+    }
+
+    function readFile(filePath) {
+        let request = new XMLHttpRequest();
+        request.open("GET", `file=${filePath}`, false);
+        request.send(null);
+        return request.responseText;
+      }
+    
+    // Options for the observer (which mutations to observe)
+    var lorahelp_js_ajax_txtbox_observer_config = { attributes: true, childList: true, subtree: true };
+    var lorahelp_js_ajax_txtbox_observer_value_check = "";
+    // Create an observer instance linked to the callback function
+    var lorahelp_js_ajax_txtbox_observer = new MutationObserver(lorahelper.call_lorahelp_js_ajax_txtbox_callback);
+    
+    //ajax queue
+    let ajax_list = []
+    let ajax_state = "ready";
+    function update_myAJAX(){
+        if(ajax_state == "running"){
+            return;
+        }
+        if (ajax_list.length > 0){
+            let req = ajax_list[0];
+            req.sentAJAX();
+        }
+    }
+    
+    function remove_ajax_queue_item(self){
+        for(let i=0; i<ajax_list.length; ++i){
+            if(ajax_list[i] === self){
+                ajax_list.splice(i, 1);
+                break;
+            }
+        }
+    }
+    
+    function myAJAX(msg, trigger){
+        this.message = msg;
+        this.trigger = trigger;
+        this.then_not_set = true;
+        this.then_func = lorahelper.noop_func;
+        this.error_func = lorahelper.noop_func;
+        this.timeout = 6000;
+    }
+    
+    myAJAX.prototype.then = function(then_func) {
+        this.then_func = then_func;
+        this.then_not_set = false;
+        return this;
+    }
+    
+    myAJAX.prototype.error = function(error_func) {
+        this.error_func = error_func;
+        return this;
+    }
+    
+    myAJAX.prototype.sentAJAX = function(){
+        if(ajax_state == "running"){
+            return;
+        }
+        ajax_state = "running";
+        // fill to msg box
+        send_lorahelp_py_ajax(this.message);
+        if(!this.then_not_set){
+            lorahelp_js_ajax_txtbox_observer_value_check = lorahelper.lorahelp_js_ajax_txtbox_textarea.value;
+            this.timeout_id = window.setTimeout((function(self) {return function() {
+                lorahelp_js_ajax_txtbox_observer.disconnect();
+                lorahelper.lorahelp_js_ajax_txtbox_callback = function() {
+                    lorahelper.debug('lorahelp_js_ajax_txtbox_callback callback');
+                }
+                self.error_func("timeout");
+                remove_ajax_queue_item(self);
+                ajax_state = "ready";
+                update_myAJAX();
+            }; })(this), this.timeout);
+            lorahelper.lorahelp_js_ajax_txtbox_callback = (function(self) {return function() {
+                if(lorahelper.lorahelp_js_ajax_txtbox_textarea.value == lorahelp_js_ajax_txtbox_observer_value_check){
+                    return;
+                }
+                window.clearTimeout(self.timeout_id);
+                lorahelp_js_ajax_txtbox_observer.disconnect();
+                lorahelper.lorahelp_js_ajax_txtbox_callback = function() {
+                    lorahelper.debug('lorahelp_js_ajax_txtbox_callback callback');
+                }
+                self.then_func(lorahelper.lorahelp_js_ajax_txtbox_textarea.value);
+                remove_ajax_queue_item(self);
+                ajax_state = "ready";
+                update_myAJAX();
+            }; })(this);
+            lorahelp_js_ajax_txtbox_observer.observe(lorahelper.lorahelp_js_ajax_txtbox_textarea, lorahelp_js_ajax_txtbox_observer_config);
+        }
+        this.trigger.click();
+        if(this.then_not_set){
+            remove_ajax_queue_item(this);
+            ajax_state = "ready";
+            update_myAJAX();
+        }
+    }
+    
+    myAJAX.prototype.sent = function(){
+        ajax_list.push(this);
+        update_myAJAX();
+    }
+    
+    function my_dispatchEvent(ele,eve){
+        try {
+            ele.dispatchEvent(eve);
+        } catch (error) {
+            
+        }
+    }
+    
+    function send_lorahelp_py_ajax(msg){
+        lorahelper.debug("run send_lorahelp_py_ajax");
+        let js_ajax_txtbox = lorahelper.gradioApp().querySelector("#lorahelp_js_ajax_txtbox textarea");
+        if (js_ajax_txtbox && msg) {
+            // fill to msg box
+            update_inputbox(js_ajax_txtbox, JSON.stringify(msg));
+            //js_ajax_txtbox.dispatchEvent(new Event("input"));
+        }
+    
+    }
+    
+    function update_inputbox(textbox, text){
+        textbox.value = text;
+        my_dispatchEvent(textbox, new Event("input", {
+            bubbles: true,
+            cancelable: true,
+        }));
+    }
+    
+    function get_lorahelp_py_ajax(){
+        lorahelper.debug("run get_lorahelp_py_ajax");
+        const py_ajax_txtbox = lorahelper.gradioApp().querySelector("#lorahelp_py_ajax_txtbox textarea");
+        if (py_ajax_txtbox && py_ajax_txtbox.value) {
+            lorahelper.debug("find py_ajax_txtbox");
+            lorahelper.debug("py_ajax_txtbox value: ");
+            lorahelper.debug(py_ajax_txtbox.value);
+            return py_ajax_txtbox.value
+        } else {
+            return ""
+        }
+    }
+    
+    const get_new_lorahelp_py_ajax = (max_count=3) => new Promise((resolve, reject) => {
+        lorahelper.debug("run get_new_lorahelp_py_ajax");
+    
+        let count = 0;
+        let new_ajax = "";
+        let find_ajax = false;
+        const interval = setInterval(() => {
+            const py_ajax_txtbox = lorahelper.gradioApp().querySelector("#lorahelp_py_ajax_txtbox textarea");
+            count++;
+    
+            if (py_ajax_txtbox && py_ajax_txtbox.value) {
+                lorahelper.debug("find py_ajax_txtbox");
+                lorahelper.debug("py_ajax_txtbox value: ");
+                lorahelper.debug(py_ajax_txtbox.value);
+    
+                new_ajax = py_ajax_txtbox.value
+                if (new_ajax != "") {
+                    find_ajax=true
+                }
+            }
+    
+            if (find_ajax) {
+                //clear msg in both sides
+                update_inputbox(py_ajax_txtbox, "");
+                //py_ajax_txtbox.dispatchEvent(new Event("input"));
+    
+                resolve(new_ajax);
+                clearInterval(interval);
+            } else if (count > max_count) {
+                //clear msg in both sides
+                update_inputbox(py_ajax_txtbox, "");
+                //py_ajax_txtbox.dispatchEvent(new Event("input"));
+    
+                reject('');
+                clearInterval(interval);
+            }
+    
+        }, 1000);
+    })
+
+    lorahelper.build_cors_request = build_cors_request;
+    lorahelper.readFile = readFile;
+    lorahelper.myAJAX = myAJAX;
+    lorahelper.my_dispatchEvent = my_dispatchEvent;
+    lorahelper.update_inputbox = update_inputbox;
+}
+let module_loadded = false;
+document.addEventListener("DOMContentLoaded", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+document.addEventListener("load", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+})();
+

+ 472 - 0
javascript/context_menu.js

@@ -0,0 +1,472 @@
+(function(){
+function module_init() {
+    console.log("[lora-prompt-tool] load context menu module");
+    lorahelper.lorahelper_context_menu = null;
+    lorahelper.lorahelper_context_menu_list = null;
+    lorahelper.lorahelper_context_menu_edit_btn = null;
+    lorahelper.lorahelper_context_menu_search_box = null;
+    lorahelper.lorahelper_sub_context_menu = null;
+    lorahelper.lorahelper_context_menu_opt = null;
+    
+    lorahelper.context_menu_list = [];
+    lorahelper.context_menu_search_box_item = null;
+    
+    lorahelper.lorahelper_context_menu_search_text = "";
+    lorahelper.lorahelper_context_menu_search_lock = false;
+    
+    lorahelper.lorahelper_mouse_position = {x: -1, y: -1};
+
+    function updateLoraHelperSearchingBox(event){
+        if(lorahelper.lorahelper_context_menu_search_lock){
+            return;
+        }
+        if(lorahelper.lorahelper_context_menu_search_text == lorahelper.lorahelper_context_menu_search_box.value){
+            return;
+        }
+        lorahelper.lorahelper_context_menu_search_lock = true;
+        lorahelper.lorahelper_context_menu_search_text = lorahelper.lorahelper_context_menu_search_box.value;
+        let filter = lorahelper.lorahelper_context_menu_search_text.trim();
+        const menu_list = lorahelper.lorahelper_context_menu_list.querySelectorAll('.item');
+        if(filter === ""){
+            for(const menu_item of menu_list){
+                menu_item.style.display = "block";
+            }
+            lorahelper.lorahelper_context_menu_search_lock = false;
+            return;
+        }
+        let is_regex = false;
+        if(filter.charAt(filter.length-1) == filter.charAt(0) && filter.charAt(0) == "/" && filter.length >= 2){
+            try {
+                const reg_filter = filter.substring(1, filter.length-1);
+                if(reg_filter !== ""){
+                    filter = new RegExp(reg_filter);
+                    is_regex = true;
+                }
+            } catch (error) {
+                is_regex = false;
+            }
+        }
+        if(!is_regex){
+            filter = filter.toLowerCase();
+            if(filter.indexOf("\\") > -1){
+                try {
+                    filter = lorahelper.unescape_string(filter);
+                } catch (error) {
+                    
+                }
+            }
+        }
+    
+        for(const menu_item of menu_list){
+            if(menu_item.classList.contains('edit-btn')) continue;
+            let flag = false;
+            const find_areas = [
+                menu_item.innerHTML || "", 
+                menu_item.getAttribute("prompt") || "", 
+                menu_item.getAttribute("categorys") || ""
+            ];
+            for(const find_area of find_areas){
+                if(is_regex){
+                    flag = find_area.toLowerCase().search(filter) > -1
+                } else {
+                    flag = find_area.toLowerCase().indexOf(filter) > -1
+                }
+                if (flag) break;
+            }
+            menu_item.style.display = flag ? "block" : "none";
+        }
+        lorahelper.lorahelper_context_menu_search_lock = false;
+    }
+    
+    function normalizePosition(the_context_menu, mouseX, mouseY){
+        const {
+            left: scopeOffsetX,
+            top: scopeOffsetY,
+        } = lorahelper.lorahelper_scope_div.getBoundingClientRect();
+    
+        const scopeX = mouseX - scopeOffsetX;
+        const scopeY = mouseY - scopeOffsetY;
+    
+        //check if the element will go out of bounds
+        const outOfBoundsOnX =
+            scopeX + the_context_menu.clientWidth > lorahelper.lorahelper_scope_div.clientWidth;
+        const outOfBoundsOnY =
+            scopeY + the_context_menu.clientHeight > lorahelper.lorahelper_scope_div.clientHeight; 
+        
+        let normalizeX = mouseX;
+        let normalizeY = mouseY;
+    
+        //normalize on X
+        if(outOfBoundsOnX){
+            normalizeX =
+                scopeOffsetX + lorahelper.lorahelper_scope_div.clientWidth - the_context_menu.clientWidth;
+        }
+    
+        //normalize on Y
+        if(outOfBoundsOnY){
+            normalizeY =
+                scopeOffsetY + lorahelper.lorahelper_scope_div.clientHeight - the_context_menu.clientHeight;
+        }
+    
+        return {normalizeX, normalizeY};
+    }
+    
+    function show_lora_context_menu(mouseX, mouseY){
+        lorahelper.lorahelper_context_menu_search_box.value = "";
+        lorahelper.lorahelper_context_menu_search_text = "";
+    
+        lorahelper.lorahelper_context_menu_list.style.height = "unset";
+        lorahelper.lorahelper_context_menu_search_box.style.width = "unset";
+        lorahelper.lorahelper_context_menu_list.style.overflow = "unset";
+        if(lorahelper.lorahelper_context_menu_list.clientHeight > lorahelper.lorahelper_scope_div.clientHeight - 150){
+            lorahelper.lorahelper_context_menu_list.style.height = `${lorahelper.lorahelper_scope_div.clientHeight - 150}px`;
+            lorahelper.lorahelper_context_menu_list.style.overflow = "scroll";
+        }
+    
+        lorahelper.lorahelper_context_menu_search_box.style.width = `${lorahelper.lorahelper_context_menu_list.clientWidth - 10}px`;
+    
+        lorahelper.lorahelper_context_menu_edit_btn.innerHTML = lorahelper.get_UI_display("edit prompt words...");
+        lorahelper.lorahelper_context_menu_search_box.placeholder = lorahelper.my_getTranslation("Search...");
+    
+        const {normalizeX, normalizeY} = normalizePosition(lorahelper.lorahelper_context_menu, mouseX, mouseY);
+    
+        lorahelper.lorahelper_context_menu.style.top = `${normalizeY}px`;
+        lorahelper.lorahelper_context_menu.style.left = `${normalizeX}px`;
+    
+        open_lora_context_menu(lorahelper.lorahelper_context_menu);
+    }
+    
+    function show_lora_sub_context_menu(sub_context_menu, parent_menu){
+        const parent_rect = parent_menu.getBoundingClientRect();
+    
+        sub_context_menu.style.height = "unset";
+        sub_context_menu.style.overflow = "unset";
+        if(sub_context_menu.clientHeight > lorahelper.lorahelper_scope_div.clientHeight - 100){
+            sub_context_menu.style.height = `${lorahelper.lorahelper_scope_div.clientHeight - 100}px`;
+            sub_context_menu.style.overflow = "scroll";
+        }
+        let pos_x = parent_rect.right
+        let pos_y = parent_rect.top
+    
+        if(parent_rect.right + sub_context_menu.clientWidth > lorahelper.lorahelper_scope_div.clientWidth){
+            pos_x = parent_rect.left - sub_context_menu.clientWidth;
+        }
+    
+        const {normalizeX, normalizeY} = normalizePosition(sub_context_menu, pos_x, pos_y);
+    
+        sub_context_menu.style.top = `${normalizeY}px`;
+        sub_context_menu.style.left = `${normalizeX}px`;
+    
+        open_lora_context_menu(sub_context_menu);
+    }
+    
+    function close_lora_context_menu(selected_context_menu){
+        if (!lorahelper.is_nullptr(selected_context_menu)){
+            selected_context_menu.classList.remove("visible");
+            if (typeof(selected_context_menu.on_close) === typeof(lorahelper.noop_func)){
+                selected_context_menu.on_close(selected_context_menu);
+            }
+        }else{
+            lorahelper.resetElementLayer();
+            let available_context_menu = get_lora_context_menu_list();
+            for (let the_context_menu of available_context_menu){
+                the_context_menu.classList.remove("visible");
+                if (typeof(the_context_menu.on_close) === typeof(lorahelper.noop_func)){
+                    the_context_menu.on_close(the_context_menu);
+                }
+            }
+        }
+    }
+    
+    function open_lora_context_menu(selected_context_menu){
+        selected_context_menu.classList.remove("visible");
+        setTimeout(()=>{
+            selected_context_menu.classList.add("visible");
+        });
+    }
+    
+    function add_lora_context_menu(the_context_menu){
+        lorahelper.lorahelper_scope.appendChild(the_context_menu);
+        lorahelper.context_menu_list.push(the_context_menu);
+    }
+    
+    function delete_lora_context_menu(the_context_menu){
+        try {
+            the_context_menu.remove();
+        } catch (error) { }
+        const index = lorahelper.context_menu_list.indexOf(the_context_menu);
+        if (index > -1) { // only splice array when item is found
+            lorahelper.context_menu_list.splice(index, 1); // 2nd parameter means remove one item only
+        }
+    }
+    
+    function get_lora_context_menu_list(){
+        let copy_list = [];
+        for (let item of lorahelper.context_menu_list) copy_list.push(item);
+        return copy_list;
+    }
+    
+    function create_context_menu(id){
+        let the_context_menu = document.createElement("div");
+        if(typeof(id) === typeof("string")){
+            if(id.trim() != "") the_context_menu.setAttribute("id", id);
+        }
+        the_context_menu.classList.add("lora-context-menu");
+        the_context_menu.innerHTML = "";
+        return the_context_menu;
+    }
+    
+    function create_context_menu_group(){
+        let context_menu_group = document.createElement("div");
+        context_menu_group.innerHTML = "";
+        return context_menu_group;
+    }
+    
+    function create_context_menu_hr_item(){
+        let context_menu_hr_item = document.createElement("div");
+        context_menu_hr_item.classList.add('hritem');
+        context_menu_hr_item.appendChild(document.createElement("hr"));
+        return context_menu_hr_item;
+    }
+    
+    function create_context_menu_button(text){
+        let context_menu_button_item = document.createElement("div");
+        context_menu_button_item.classList.add('item');
+        context_menu_button_item.innerHTML = text;
+        return context_menu_button_item;
+    }
+    
+    function create_context_subset(text, subset){
+        let context_menu_button_item = document.createElement("div");
+        let context_menu_subset_icon = document.createElement("span");
+        context_menu_subset_icon.innerHTML = "\u27a4";
+        context_menu_subset_icon.style.float = "right";
+        context_menu_button_item.classList.add('item');
+        context_menu_button_item.innerHTML = text;
+        context_menu_button_item.appendChild(context_menu_subset_icon);
+        context_menu_button_item.menu_subset = [];
+        for(const set_item of subset) {
+            context_menu_button_item.menu_subset.push(set_item);
+        }
+        const display_submenu = (event) => {
+            let old_sub_menu = context_menu_button_item.sub_menu_object;
+            if (!lorahelper.is_nullptr(old_sub_menu)){
+                
+            } else {
+                let the_sub_menu = create_context_menu();
+                for(const set_item of context_menu_button_item.menu_subset){
+                    the_sub_menu.appendChild(set_item);
+                }
+                the_sub_menu.on_close = (self)=>{
+                    context_menu_button_item.sub_menu_object = undefined;
+                    delete_lora_context_menu(self);
+                };
+                context_menu_button_item.sub_menu_object = the_sub_menu;
+                add_lora_context_menu(the_sub_menu);
+                show_lora_sub_context_menu(the_sub_menu, context_menu_button_item);
+            }
+        }
+        context_menu_button_item.addEventListener('mouseover', function(event) {
+            display_submenu(event);
+        }, false);
+        context_menu_button_item.addEventListener('touchstart', function(event) {
+            display_submenu(event);
+            let current_sub_menu = context_menu_button_item.sub_menu_object;
+            if (!lorahelper.is_nullptr(current_sub_menu)){
+                lorahelper.sendontop(current_sub_menu);
+            }
+        }, false);
+        context_menu_button_item.addEventListener('mouseleave', function(eve) {
+            window.setTimeout(((context_menu_button_item) => {
+                return () => {
+                    let the_sub_menu = context_menu_button_item.sub_menu_object;
+                    if (!lorahelper.is_nullptr(the_sub_menu)){
+                        const sub_menu_rect = the_sub_menu.getBoundingClientRect();
+                        if(!lorahelper.pointInRect(sub_menu_rect, lorahelper.lorahelper_mouse_position)){
+                            close_lora_context_menu(the_sub_menu);
+                        }
+                    }
+                }
+            })(context_menu_button_item), 50);
+        }, false);
+        return context_menu_button_item;
+    }
+    
+    function create_context_menu_textbox(text, onchange){
+        let context_menu_textbox_item = document.createElement("div");
+        let the_textbox = document.createElement("input");
+        the_textbox.placeholder = text;
+        if (typeof(onchange) === typeof(lorahelper.noop_func)){
+            the_textbox.addEventListener("change", onchange);
+            the_textbox.addEventListener("keypress", onchange);
+            the_textbox.addEventListener("paste", onchange);
+            the_textbox.addEventListener("input", onchange);
+        }
+        context_menu_textbox_item.classList.add('item');
+        context_menu_textbox_item.appendChild(the_textbox);
+        return context_menu_textbox_item;
+    }
+    
+    function create_context_menu_iframe(href){
+        let context_menu_iframe_item = document.createElement("div");
+        let the_iframe = document.createElement("iframe");
+        the_iframe.setAttribute("src", href);
+        the_iframe.style.width = "600px";
+        the_iframe.style.height = "60vh";
+        the_iframe.style.overflow = "scroll";
+        context_menu_iframe_item.classList.add('item');
+        context_menu_iframe_item.appendChild(the_iframe);
+        return context_menu_iframe_item;
+    }
+    
+    lorahelper.context_menu_edit_hr_item = null;
+    function hide_edit_btn(){
+        lorahelper.context_menu_edit_hr_item.style.display = "none";
+        lorahelper.lorahelper_context_menu_edit_btn.style.display = "none";
+    }
+    function show_edit_btn(){
+        lorahelper.context_menu_edit_hr_item.style.display = "block";
+        lorahelper.lorahelper_context_menu_edit_btn.style.display = "block";
+    }
+    
+    function build_mahiro_menu(event){
+        const {clientX: mouseX, clientY: mouseY} = event;
+        lorahelper.lorahelper_context_menu_list.innerHTML = "";
+        lorahelper.lorahelper_context_menu_opt.innerHTML = "";
+        const onimai_list = ["Mahiro", "Mihari", "Momiji", "Kaede", "Asahi", "Miyo"];
+        for(const onimai of onimai_list){
+            let mahiro_off_website = create_context_menu_button(`${onimai}!`);
+            mahiro_off_website.setAttribute("onclick",`lorahelper.build_mahiro_iframe(event, '${onimai.toLowerCase()}')`);
+            lorahelper.lorahelper_context_menu_list.appendChild(mahiro_off_website);
+        }
+        lorahelper.context_menu_search_box_item.style.display = "block";
+        hide_edit_btn();
+        show_lora_context_menu(mouseX, mouseY);
+        event.stopPropagation();
+        event.preventDefault();
+    }
+    
+    function build_mahiro_iframe(event, mahiro){
+        const {clientX: mouseX, clientY: mouseY} = event;
+        window.setTimeout(
+            ((mouseX, mouseY)=>{
+                return ()=>{
+                    lorahelper.lorahelper_context_menu_list.innerHTML = "";
+                    let mahiro_off_website = create_context_menu_iframe(`https://onimai.jp/character/${mahiro}.html`);
+                    if(lorahelper.lorahelper_scope_div.clientWidth <= 600){
+                        mahiro_off_website.style.width = "100vw";
+                    } else {
+                        mahiro_off_website.style.width = "600px";
+                    }
+                    mahiro_off_website.style.overflow = "scroll";
+                    lorahelper.lorahelper_context_menu_list.appendChild(mahiro_off_website);
+                    lorahelper.context_menu_search_box_item.style.display = "none";
+                    hide_edit_btn();
+                    show_lora_context_menu(mouseX, mouseY);
+                };
+            })(mouseX, mouseY)
+        , 50);
+        close_lora_context_menu();
+        event.stopPropagation();
+        event.preventDefault();
+    }
+    
+    function setup_context_menu(){
+        lorahelper.lorahelper_context_menu = create_context_menu("lora-context-menu");
+        lorahelper.lorahelper_sub_context_menu = create_context_menu("lora-sub-context-menu");
+    
+        //searching box
+        lorahelper.context_menu_search_box_item = create_context_menu_textbox(lorahelper.my_getTranslation("Search..."), updateLoraHelperSearchingBox);
+        lorahelper.lorahelper_context_menu_search_box = lorahelper.context_menu_search_box_item.querySelector("input");
+        lorahelper.lorahelper_context_menu_search_box.setAttribute("id", "lora-context-menu-search-box");
+        lorahelper.lorahelper_context_menu.appendChild(lorahelper.context_menu_search_box_item);
+    
+        //prompt list
+        lorahelper.lorahelper_context_menu_list = create_context_menu_group();
+        lorahelper.lorahelper_context_menu.appendChild(lorahelper.lorahelper_context_menu_list);
+    
+        //other option
+        lorahelper.lorahelper_context_menu_opt = create_context_menu_group();
+        lorahelper.lorahelper_context_menu.appendChild(lorahelper.lorahelper_context_menu_opt);
+    
+        //分隔線
+        lorahelper.context_menu_edit_hr_item = create_context_menu_hr_item();
+        lorahelper.lorahelper_context_menu.appendChild(lorahelper.context_menu_edit_hr_item);
+    
+        //編輯按鈕
+        lorahelper.lorahelper_context_menu_edit_btn = create_context_menu_button(lorahelper.get_UI_display("edit prompt words..."))
+        lorahelper.lorahelper_context_menu_edit_btn.classList.add('edit-btn');
+        lorahelper.lorahelper_context_menu.appendChild(lorahelper.lorahelper_context_menu_edit_btn);
+    
+        //test
+        /*let my_sub = create_context_subset("a", [
+            create_context_subset("b", [
+                create_context_menu_button("c"),
+                create_context_menu_button("d")
+            ]),
+            create_context_menu_button("e"),
+            create_context_menu_button("f")
+        ]);
+        lorahelper.lorahelper_context_menu.appendChild(my_sub);*/
+    
+        lorahelper.lorahelper_scope = document.querySelector("body");
+        lorahelper.lorahelper_scope.addEventListener("click", (e) => {
+            let flag = true;
+            let available_context_menu = get_lora_context_menu_list();
+            for (let the_context_menu of available_context_menu){
+                flag = flag && (e.target.offsetParent != the_context_menu);
+            }
+            if(flag){
+                close_lora_context_menu();
+            }
+        });
+        lorahelper.lorahelper_scope.addEventListener("mousemove", (e) => {
+            lorahelper.lorahelper_mouse_position.x = e.clientX;
+            lorahelper.lorahelper_mouse_position.y = e.clientY;
+        });
+        lorahelper.lorahelper_scope.addEventListener("touchstart", (e) => {
+            if(!lorahelper.is_nullptr(e.changedTouches)){
+                const touches = e.changedTouches;
+                lorahelper.lorahelper_mouse_position.x = touches[0].clientX;
+                lorahelper.lorahelper_mouse_position.y = touches[0].clientY;
+            }
+        });
+        add_lora_context_menu(lorahelper.lorahelper_context_menu);
+        add_lora_context_menu(lorahelper.lorahelper_sub_context_menu);
+    
+        //只覆蓋目前螢幕可見範圍的div,用於計算右鍵選單位置
+        lorahelper.lorahelper_scope_div = document.createElement("div");
+        lorahelper.lorahelper_scope_div.style.position = "fixed";
+        lorahelper.lorahelper_scope_div.style.top = "0px";
+        lorahelper.lorahelper_scope_div.style.left = "0px";
+        lorahelper.lorahelper_scope_div.style.width = "100vw";
+        lorahelper.lorahelper_scope_div.style.height = "100vh";
+        lorahelper.lorahelper_scope_div.style.zIndex = -1;
+        lorahelper.lorahelper_scope_div.style.backgroundColor = "transparent";
+        lorahelper.lorahelper_scope_div.style.opacity = 0;
+        lorahelper.lorahelper_scope_div.style.pointerEvents = "none";
+        lorahelper.lorahelper_scope.appendChild(lorahelper.lorahelper_scope_div);
+    }
+
+    lorahelper.show_lora_context_menu = show_lora_context_menu;
+    lorahelper.close_lora_context_menu = close_lora_context_menu;
+    lorahelper.create_context_menu_hr_item = create_context_menu_hr_item;
+    lorahelper.create_context_menu_button = create_context_menu_button;
+    lorahelper.create_context_subset = create_context_subset;
+    lorahelper.show_edit_btn = show_edit_btn;
+    lorahelper.build_mahiro_menu = build_mahiro_menu;
+    lorahelper.build_mahiro_iframe = build_mahiro_iframe;
+    lorahelper.setup_context_menu = setup_context_menu;
+}
+let module_loadded = false;
+document.addEventListener("DOMContentLoaded", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+document.addEventListener("load", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+})();

+ 450 - 0
javascript/dataframe_edit.js

@@ -0,0 +1,450 @@
+(function(){
+
+function module_init() {
+    console.log("[lora-prompt-tool] load dataframe edit module");
+    lorahelper.edit_action_list = {
+        add: "lorahelp_dataedit_add",
+        delete: "lorahelp_dataedit_delete",
+        up: "lorahelp_dataedit_up",
+        down: "lorahelp_dataedit_down",
+        copy: "lorahelp_dataedit_copy",
+        paste: "lorahelp_dataedit_paste",
+        paste_append: "lorahelp_dataedit_paste_append",
+        translate: "lorahelp_dataedit_translate"
+    }
+    
+    lorahelper.lorahlep_dataframe_unselected = [-1,-1];
+    
+    let lorahelp_js_dataframe_observer_lock = false;
+    let lorahelp_js_dataframe_add_event_lock = false;
+    function lorahelp_js_dataframe_add_event(){
+        window.setTimeout(()=>{
+            if(lorahelp_js_dataframe_observer_lock) return;
+            if(lorahelp_js_dataframe_add_event_lock) return;
+            lorahelp_js_dataframe_add_event_lock = true;
+            //const cell_list = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("table").querySelectorAll(".cell-wrap");
+            const cell_list = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("table").querySelectorAll("td");
+            for(const cell of cell_list){
+                if(cell.getAttribute("onfocusout") || "" != ""){
+                    lorahelp_js_dataframe_add_event_lock = false;
+                    return;
+                }
+            }
+            dataframe_focus_check_setup();
+            lorahelp_js_dataframe_add_event_lock = false;
+        }, 50);
+    }
+    var lorahelp_js_dataframe_observer_callback = function() {
+        if(lorahelp_js_dataframe_observer_lock) return;
+        lorahelp_js_dataframe_observer_lock = true;
+        lorahelp_js_dataframe_add_event();
+        lorahelp_js_dataframe_observer_lock = false;
+    }
+    function call_lorahelp_js_dataframe_observer_callback(){
+        lorahelp_js_dataframe_observer_callback();
+    }
+    
+    //select_index_text_box listener
+    lorahelper.select_index_text_box = null;
+    let select_index_text_box_callback = function() {
+        lorahelper.debug('select_index_text_box_callback callback');
+    }
+    function call_select_index_text_box_callback(){
+        select_index_text_box_callback();
+    }
+    // Options for the observer (which mutations to observe)
+    var select_index_text_box_observer_config = { attributes: true, childList: true, subtree: true };
+    var select_index_text_box_observer_value_check = "";
+    // Create an observer instance linked to the callback function
+    var select_index_text_box_observer = new MutationObserver(call_select_index_text_box_callback);
+    var select_index_text_box_value_check = "";
+    var select_index_text_box_value_lock = false;
+    function start_listen_select_index_text(call_back, timeout_input){
+        if (select_index_text_box_value_lock) return;
+        //console.log('觀測開始。');
+        select_index_text_box_value_lock = true;
+        select_index_text_box_value_check = lorahelper.select_index_text_box.value;
+        let timeout = 50;
+        if (!lorahelper.is_nullptr(timeout_input)) timeout = parseInt(timeout_input);
+        let timeout_id = window.setTimeout(function() {
+            select_index_text_box_observer.disconnect();
+            select_index_text_box_callback = function() {
+                lorahelper.debug('select_index_text_box_callback callback');
+            };
+            if(typeof(call_back) === typeof(lorahelper.noop_func))call_back("timeout");
+            //console.log('觀測結束。');
+            select_index_text_box_value_lock = false;
+        }, timeout);
+        select_index_text_box_callback = (function(self_timeout_id) {return function() {
+            if(lorahelper.select_index_text_box.value == select_index_text_box_value_check){
+                return;
+            }
+            window.clearTimeout(self_timeout_id);
+            select_index_text_box_observer.disconnect();
+            select_index_text_box_callback = function() {
+                lorahelper.debug('select_index_text_box_callback callback');
+            }
+            if(typeof(call_back) === typeof(lorahelper.noop_func))call_back();
+
+            //console.log('觀測結束。');
+            select_index_text_box_value_lock = false;
+        }; })(timeout_id);
+        select_index_text_box_observer.observe(lorahelper.select_index_text_box, select_index_text_box_observer_config);
+    }
+    
+    // dataframe listener
+    // Options for the observer (which mutations to observe)
+    lorahelper.lorahelp_js_dataframe_observer_config = { childList: true, subtree: true };
+    // Create an observer instance linked to the callback function
+    lorahelper.lorahelp_js_dataframe_observer = new MutationObserver(call_lorahelp_js_dataframe_observer_callback);
+    
+    function dataframe_edit_action(event, action){
+        const select_index = JSON.parse(lorahelper.gradioApp().querySelector("#lorahelp_dataedit_select_index_txtbox textarea").value);
+        if (select_index[0] > -1){
+            let table_obj = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("table");
+            let tbody_obj = table_obj.querySelector("tbody");
+            let selected_row = tbody_obj.childNodes[select_index[0]];
+            var the_btn = lorahelper.gradioApp().getElementById(lorahelper.edit_action_list[action]+"_event");
+            let node_ptr;
+            if (the_btn || action == "translate" || action == "copy") {
+                switch (action) {
+                    case "add":
+                    case "delete":
+                    case "up":
+                    case "down":
+                        the_btn.click();
+                        window.setTimeout(((action, select_index)=>{
+                            return ()=>{
+                                let new_select_index = [select_index[0], select_index[1]];
+                                if (action === "up"){
+                                    --new_select_index[0];
+                                }else if (action === "down"){
+                                    ++new_select_index[0];
+                                }
+                                let shape = dataframe_shape();
+                                if(new_select_index[0] < shape[0] && new_select_index[1] < shape[1] &&
+                                    new_select_index[0] >= 0 && new_select_index[1] >= 0){
+                                    lorahelper.update_inputbox(lorahelper.select_index_text_box, JSON.stringify(new_select_index));
+                                    if (!lorahelper.gradio_no_select_event) {
+                                        start_listen_select_index_text((state)=>{
+                                            if(state !== 'timeout')
+                                                lorahelper.update_inputbox(lorahelper.select_index_text_box, JSON.stringify(new_select_index));
+                                        }, 500);
+                                    }
+                                }
+                            };
+                        })(action, select_index),50);
+                        break;
+                    case "copy":
+                        let cell_node = selected_row.childNodes[select_index[1]];
+                        node_ptr = cell_node;
+                        //找葉子節點 (無分支節點)
+                        while(node_ptr.childNodes.length > 0){
+                            node_ptr = node_ptr.childNodes[0];
+                        }
+                        node_ptr = node_ptr.parentElement;
+                        let cell_text = "";
+                        for(const text_node of node_ptr.childNodes){
+                            cell_text += (text_node.innerHTML || "");
+                        }
+                        lorahelper.lorahelp_copy_paste_txtbox.value = cell_text;
+                        lorahelper.lorahelp_copy_paste_txtbox.select();
+                        lorahelper.lorahelp_copy_paste_txtbox.setSelectionRange(0, 99999);
+                        //document.execCommand("copy");
+                        navigator.clipboard.writeText(cell_text).then(() => {
+                            lorahelper.lorahelp_js_output_message.value = lorahelper.my_getTranslation("Content copied to clipboard");
+                            /* Resolved - text copied to clipboard successfully */
+                          },() => {
+                            lorahelper.lorahelp_js_output_message.value = lorahelper.my_getTranslation("Failed to copy");
+                            /* Rejected - text failed to copy to the clipboard */
+                          });
+                        break;
+                    case "paste":
+                    case "paste_append":
+                        lorahelper.update_inputbox(lorahelper.lorahelp_copy_paste_txtbox.value, "");
+                        //lorahelper.lorahelp_copy_paste_txtbox.dispatchEvent(new Event("input"));
+                        navigator.clipboard.readText()
+                        .then((the_trigger => { 
+                            return text=>{
+                                lorahelper.update_inputbox(lorahelper.lorahelp_copy_paste_txtbox, text);
+                                //lorahelper.lorahelp_copy_paste_txtbox.dispatchEvent(new Event("input"));
+                                the_trigger.click();
+                            };
+                        })(the_btn))
+                        .catch(err => {
+                            console.error('Failed to read clipboard contents: ', err);
+                        });
+                        break;
+                    case "translate":
+                        let prompt_node = selected_row.childNodes[1];
+                        node_ptr = prompt_node
+                        //找葉子節點 (無分支節點)
+                        while(node_ptr.childNodes.length > 0){
+                            node_ptr = node_ptr.childNodes[0];
+                        }
+                        node_ptr = node_ptr.parentElement;
+                        let prompt_text = "";
+                        for(const text_node of node_ptr.childNodes){
+                            prompt_text += (text_node.innerHTML || "");
+                        }
+                        prompt_text = lorahelper.unescape_string(prompt_text);
+                        prompt_text = prompt_text.replace(/[\s_]+/g, " ");
+                        if(prompt_text.trim() !== ""){
+                            let language_code = `${opts.localization}`.toLowerCase();
+                            let normalize_lcode = /[a-z]+([\s_\-\+]+[a-z]+)?/.exec(language_code);
+                            if (normalize_lcode) language_code = normalize_lcode[0] || language_code;
+                            language_code = language_code.replace(/[\s_\-\+]+/g, "_");
+                            lorahelper.lorahelp_translate_area.innerHTML = lorahelper.get_UI_display("translating...");
+                            lorahelper.google_translate(prompt_text, { from: "en", to: lorahelper.dataedit_translate_translate_language_selector.value })
+                            .then(res => {
+                                lorahelper.lorahelp_translate_area.innerHTML = "";
+                                let display_translate = document.createElement("p");
+                                display_translate.innerHTML = res.text;
+                                lorahelper.lorahelp_translate_area.appendChild(display_translate);
+                            })
+                            .catch(err => {
+                                lorahelper.lorahelp_translate_area.innerHTML = lorahelper.get_UI_display("translation error");
+                                console.error(err);
+                            });
+                        }
+                        break;
+                    default:
+                        lorahelper.debug("unknown action")
+                        break;
+                }
+            }
+        } else {
+            lorahelper.debug("no selected cell found!");
+        }
+        event.stopPropagation();
+        event.preventDefault();
+    }
+    
+    function updateDataeditSearchingBox(){
+        if(lorahelper.lorahelper_dataedit_search_lock){
+            return;
+        }
+        const table_body = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("tbody");
+        const txtbox = lorahelper.gradioApp().getElementById("lorahelp_js_dataframe_filter").querySelector("input, textarea");
+        lorahelper.lorahelper_dataedit_search_lock = true;
+        lorahelper.lorahelper_dataedit_search_text = txtbox.value;
+        let filter = lorahelper.lorahelper_dataedit_search_text.trim();
+        const menu_list = table_body.querySelectorAll('tr');
+        let is_regex = false;
+		if(filter !== ""){
+			if(filter.charAt(filter.length-1) == filter.charAt(0) && filter.charAt(0) == "/" && filter.length >= 2){
+				try {
+					const reg_filter = filter.substring(1, filter.length-1);
+					if(reg_filter !== ""){
+						filter = new RegExp(reg_filter);
+						is_regex = true;
+					}
+				} catch (error) {
+					is_regex = false;
+				}
+			}
+			if(!is_regex){
+				filter = filter.toLowerCase();
+				if(filter.indexOf("\\") > -1){
+					try {
+						filter = lorahelper.unescape_string(filter);
+					} catch (error) {
+						
+					}
+				}
+			}
+		}
+
+        for(const menu_item of menu_list){
+			let flag = false;
+			let rows = menu_item.querySelectorAll('td');
+			if (rows.length <= 0) continue;
+			
+            const find_areas = [
+                rows[0].innerText, 
+                rows[1].innerText, 
+                rows[2].innerText
+            ];
+            for(const find_area of find_areas){
+                if(is_regex){
+                    flag = find_area.toLowerCase().search(filter) > -1
+                } else {
+                    flag = find_area.toLowerCase().indexOf(filter) > -1
+                }
+                if (flag) break;
+            }
+			if(filter === ""){
+				if(/(^|,)\s*##default##\s*(,|$)/.exec(rows[2].innerText)){
+					flag = false;
+				} else {
+					flag = true;
+				}
+			}
+			if(find_areas.join("").trim() === ""){
+				flag = true;
+			}
+			if(rows[0]?.querySelector("span")?.style?.color == "gray"){
+				flag = true;
+			}
+			menu_item.style.display = flag ? "table-row" : "none";
+        }
+        lorahelper.lorahelper_dataedit_search_lock = false;
+    }
+
+    function fill_cell_placeholder(){
+        const table_body = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("tbody");
+        let it=0;
+        let jt=0;
+        for(var i = 0; i < table_body.childNodes.length; ++i){
+            //你不要亂入!
+            if(table_body.childNodes[i].nodeName.toLowerCase() !== 'tr') continue;
+            jt = 0;
+            for(var j = 0; j < table_body.childNodes[i].childNodes.length; ++j){
+                //你不要亂入 x 2!
+                if(table_body.childNodes[i].childNodes[j].nodeName.toLowerCase() !== 'td') continue;
+                const cell = table_body.childNodes[i].childNodes[j];
+				const cell_span = cell.querySelector("span");
+				const datafram_placeholder = [
+					lorahelper.my_getTranslation("Enter your custom name."),
+					lorahelper.my_getTranslation("Enter your trigger word. EX: character_name_\\(title of novel\\)"),
+					lorahelper.my_getTranslation("(optional) separated by commas. EX: Character Name/Style Attributes"),
+					lorahelper.my_getTranslation("It is automatically set to No when adding, and it needs to be changed again")
+				];
+				if(((cell_span?.innerText||"")+"").trim() === ""){
+					if(((datafram_placeholder[jt]||"")+"").trim()!==""){
+						cell_span.innerHTML =`<span style="color: gray;">${datafram_placeholder[jt]}</span>`;
+					}
+				}
+                ++jt
+            }
+            ++it;
+        }
+    }
+
+    function calculate_selected_cell(){
+        const table_body = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("tbody");
+        let it=0;
+        let jt=0;
+        for(var i = 0; i < table_body.childNodes.length; ++i){
+            //你不要亂入!
+            if(table_body.childNodes[i].nodeName.toLowerCase() !== 'tr') continue;
+            jt = 0;
+            for(var j = 0; j < table_body.childNodes[i].childNodes.length; ++j){
+                //你不要亂入 x 2!
+                if(table_body.childNodes[i].childNodes[j].nodeName.toLowerCase() !== 'td') continue;
+                const cell = table_body.childNodes[i].childNodes[j];
+                let select_flag = cell.contains(document.activeElement);
+                if (lorahelper.gradio_no_select_event){
+                    select_flag = !cell.childNodes[0].classList.contains("border-transparent");
+                }
+                if(select_flag){
+                    return [it, jt];
+                }
+                ++jt
+            }
+            ++it;
+        }
+        return lorahelper.lorahlep_dataframe_unselected;
+    }
+    
+    function dataframe_shape(){
+        const table_body = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("tbody");
+        let it=0;
+        let jt=0;
+        for(var i = 0; i < table_body.childNodes.length; ++i){
+            //你不要亂入!
+            if(table_body.childNodes[i].nodeName.toLowerCase() !== 'tr') continue;
+            jt = 0;
+            for(var j = 0; j < table_body.childNodes[i].childNodes.length; ++j){
+                //你不要亂入 x 2!
+                if(table_body.childNodes[i].childNodes[j].nodeName.toLowerCase() !== 'td') continue;
+                ++jt;
+            }
+            ++it;
+        }
+        return [it, jt];
+    }
+
+    function dataframe_focus_check_setup(){
+        //const cell_list = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("table").querySelectorAll(".cell-wrap");
+        for(const table_id of ["td","th"]){
+            const cell_list = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("table").querySelectorAll(table_id);
+            for(const cell of cell_list){
+                cell.setAttribute("onfocusout", "lorahelper.dataframe_focus_check(event)");
+                cell.setAttribute("onfocusin", "lorahelper.dataframe_infocus(event)");
+            }
+        }
+        if(lorahelper.translate_ready){
+            fill_cell_placeholder();
+            updateDataeditSearchingBox();
+        }
+    }
+    
+    function dataframe_infocus(event){
+        const selected_index = calculate_selected_cell();
+        if (lorahelper.gradio_no_select_event) {
+            lorahelper.update_inputbox(lorahelper.select_index_text_box, JSON.stringify(selected_index));
+        } else {
+            start_listen_select_index_text((the_selected_index =>{
+                return state => {
+                    const new_select_index = JSON.parse(lorahelper.select_index_text_box.value);
+                    if(new_select_index[0] != the_selected_index[0] || new_select_index[1] != the_selected_index[1]){
+                        lorahelper.update_inputbox(lorahelper.select_index_text_box, JSON.stringify(selected_index));
+                    }
+                };
+            })(selected_index));
+        }
+    }
+    
+    function dataframe_focus_check(event){
+        window.setTimeout(()=>{
+            let select_dom = document.activeElement;
+            let btn_list = [];
+            for (const [key, value] of Object.entries(lorahelper.edit_action_list)) btn_list.push(value+"_btn");
+            if(btn_list.includes(select_dom.getAttribute("id"))) return;
+            if(!lorahelper.is_dataframe_selected()){
+                lorahelper.update_inputbox(lorahelper.select_index_text_box, JSON.stringify(lorahelper.lorahlep_dataframe_unselected));
+                //lorahelper.select_index_text_box.dispatchEvent(new Event("input"));
+            }
+        }, 10);
+    }
+    
+    function setup_dataframe_edit(){
+        dataframe_focus_check_setup();
+        lorahelper.lorahelper_scope.addEventListener("click", (event) => {
+            const dataframe_area = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe");
+            if(lorahelper.is_nullptr(dataframe_area)) return;
+            const rect = dataframe_area.querySelector("tbody").getBoundingClientRect();
+            let select_dom = document.activeElement;
+            let btn_list = [];
+            for (const [key, value] of Object.entries(lorahelper.edit_action_list)) btn_list.push(value+"_btn");
+            if(btn_list.includes(select_dom.getAttribute("id"))) return;
+            const {clientX: mouseX, clientY: mouseY} = event;
+            if (!lorahelper.pointInRect(rect, {x:mouseX, y:mouseY})){
+                lorahelper.update_inputbox(lorahelper.select_index_text_box, JSON.stringify(lorahelper.lorahlep_dataframe_unselected));
+            }
+        });
+    }
+
+    lorahelper.dataframe_edit_action = dataframe_edit_action;
+    lorahelper.dataframe_infocus = dataframe_infocus;
+    lorahelper.dataframe_focus_check = dataframe_focus_check;
+    lorahelper.setup_dataframe_edit = setup_dataframe_edit;
+    lorahelper.fill_cell_placeholder = fill_cell_placeholder;
+    lorahelper.updateDataeditSearchingBox = updateDataeditSearchingBox;
+
+}
+let module_loadded = false;
+document.addEventListener("DOMContentLoaded", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+document.addEventListener("load", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+})();
+
+

+ 428 - 0
javascript/extension_functions.js

@@ -0,0 +1,428 @@
+(function(){
+
+function module_init() {
+    console.log("[lora-prompt-tool] load extension functions module");
+    function show_trigger_words(event, model_type, model_path, model_name, bgimg, active_tab_type){
+        lorahelper.debug("start show_trigger_words");
+    
+        //get hidden components of extension 
+        let js_show_trigger_words_btn = lorahelper.gradioApp().getElementById("lorahelp_js_show_trigger_words_btn");
+        if (!js_show_trigger_words_btn) {
+            return;
+        }
+        let {clientX: mouseX, clientY: mouseY} = event;
+        if(!lorahelper.is_nullptr(event.changedTouches)){
+            const touches = event.changedTouches;
+            mouseX = touches[0].clientX;
+            mouseY = touches[0].clientY;
+        }
+
+        //ajax to python side
+        new lorahelper.myAJAX({
+            "action": "show_trigger_words",
+            "model_type": model_type,
+            "model_path": model_path,
+        }, js_show_trigger_words_btn).then(
+            (function(mouseX, mouseY){return function(response){
+                lorahelper.lorahelper_context_menu_list.innerHTML = "";
+                lorahelper.lorahelper_context_menu_opt.innerHTML = "";
+                let prompt_count = 0;
+                try{
+                    let data = JSON.parse(response);
+                    if(!lorahelper.is_nullptr(data)){
+                        if(!lorahelper.is_nullptr(data.prompts)){
+                            let data_prompts = data.prompts;
+                            if (typeof data_prompts === 'string' || data_prompts instanceof String){
+                                data_prompts = [{"prompt": data_prompts}];
+                            }
+                            for(const prompt of data_prompts){
+                                if(!lorahelper.is_nullptr(prompt.prompt) && prompt.prompt !== ""){
+                                    const is_neg = (lorahelper.load_boolean_flag(prompt.neg || "")==1);
+                                    let context_menu_item = lorahelper.create_context_menu_button(prompt.prompt);
+                                    context_menu_item.setAttribute("prompt", prompt.prompt);
+                                    if(!lorahelper.is_nullptr(prompt.title) && prompt.title !== ""){
+                                        context_menu_item.innerHTML = prompt.title;
+                                        context_menu_item.setAttribute("title", prompt.prompt);
+                                    }
+                                    if(!lorahelper.is_nullptr(prompt.categorys) && prompt.categorys !== ""){
+                                        context_menu_item.setAttribute("categorys", prompt.categorys);
+                                    }
+                                    let function_name = "lorahelper.add_selected_trigger_word";
+                                    if(is_neg){
+                                        function_name = "lorahelper.add_selected_neg_trigger_word";
+                                        context_menu_item.innerHTML += ` (${lorahelper.my_getTranslation("Negative prompt")})`
+                                    }
+                                    context_menu_item.setAttribute("onclick",
+                                        `${function_name}(event, '${model_type}', '${model_path}', ${JSON.stringify(prompt.prompt)}, '${active_tab_type}')`
+                                    );
+                                    lorahelper.lorahelper_context_menu_list.appendChild(context_menu_item);
+    
+                                    ++prompt_count;
+                                }
+                            }
+                        }
+                        //support for Civitai's JSON
+                        if(!lorahelper.is_nullptr(data.trainedWords)){
+                            for(const prompt of data.trainedWords){
+                                if(!lorahelper.is_nullptr(prompt) && prompt !== ""){
+                                    let context_menu_item = lorahelper.create_context_menu_button(`${prompt} ${lorahelper.my_getTranslation("(from CivitAI)")}`);
+                                    context_menu_item.setAttribute("prompt", prompt);
+                                    context_menu_item.setAttribute("categorys", "civitai");
+                                    context_menu_item.setAttribute("onclick",
+                                        `lorahelper.add_selected_trigger_word(event, '${model_type}', '${model_path}', ${JSON.stringify(prompt)}, '${active_tab_type}')`
+                                    );
+                                    lorahelper.lorahelper_context_menu_list.appendChild(context_menu_item);
+    
+                                    ++prompt_count;
+                                }
+                            }
+                        }
+                        let options_count = 0;
+                        if(!lorahelper.is_nullptr(data.weight) || !lorahelper.is_nullptr(data.params)){
+                            let select_list = [];
+                            if(!lorahelper.is_empty(data.weight)){
+                                let syntax = lorahelper.build_hyper_cmd(model_type,model_name,data.weight,"");
+                                if(!lorahelper.is_empty(syntax)){
+                                    let select_btn = lorahelper.create_context_menu_button(lorahelper.get_UI_display("Use suggested weight"));
+                                
+                                    select_btn.setAttribute("onclick",
+                                            `lorahelper.add_selected_trigger_word(event, '${model_type}', '${model_path}', '${lorahelper.build_hyper_cmd(model_type,model_name,data.weight,"")}', '${active_tab_type}')`
+                                    );
+                                    select_list.push(select_btn);
+                                }
+                            }
+                            if(!lorahelper.is_empty(data.params)){
+                                let syntax = lorahelper.build_hyper_cmd(model_type,model_name,1.0,data.params);
+                                if(!lorahelper.is_empty(syntax)){
+                                    let select_btn = lorahelper.create_context_menu_button(lorahelper.get_UI_display("Use suggested params"));
+                                
+                                    select_btn.setAttribute("onclick",
+                                            `lorahelper.add_selected_trigger_word(event, '${model_type}', '${model_path}', '${lorahelper.build_hyper_cmd(model_type,model_name,1.0,data.params)}', '${active_tab_type}')`
+                                    );
+                                    select_list.push(select_btn);
+                                }
+                            }
+                            if(!lorahelper.is_empty(data.params) && !lorahelper.is_empty(data.weight)){
+                                let syntax = lorahelper.build_hyper_cmd(model_type,model_name,data.weight,data.params);
+                                if(!lorahelper.is_empty(syntax)){
+                                    let select_btn = lorahelper.create_context_menu_button(lorahelper.get_UI_display("Use suggested weight and params"));
+                                    select_btn.setAttribute("onclick",
+                                            `lorahelper.add_selected_trigger_word(event, '${model_type}', '${model_path}', '${lorahelper.build_hyper_cmd(model_type,model_name,data.weight,data.params)}', '${active_tab_type}')`
+                                    );
+                                    select_list.push(select_btn);
+                                }
+                            }
+                            if(select_list.length > 0){
+                                let sub_menu = lorahelper.create_context_subset(lorahelper.get_UI_display("add model using suggested setting"), select_list);
+                                lorahelper.lorahelper_context_menu_opt.appendChild(sub_menu);
+                                ++options_count;
+                            }
+                        }
+                        if(!lorahelper.is_nullptr(data.images)){
+                            if(data.images.length > 0){
+                                let image_list = [];
+                                let image_setting_list = [];
+                                for(const image_data of data.images){
+                                    if (!lorahelper.is_nullptr(image_data.meta)){
+                                        if (!lorahelper.is_nullptr(image_data.meta.prompt) && !lorahelper.is_nullptr(image_data.url)){
+                                            let image_btn = lorahelper.create_context_menu_button("");
+                                            let image_ele = document.createElement("img");
+                                            image_ele.setAttribute("src", image_data.url);
+                                            image_ele.style.width = "100px";
+                                            image_btn.appendChild(image_ele);
+                                            image_btn.addEventListener("click", ((model_type, model_path, image_data, active_tab_type) => {return (event) => {
+                                                lorahelper.add_selected_trigger_word(event, model_type, model_path, image_data.meta.prompt, active_tab_type);
+                                                window.setTimeout(((model_type, model_path, image_data, active_tab_type) => {return (event) => {
+                                                    if(!lorahelper.is_nullptr(image_data.meta.negativePrompt) && (""+image_data.meta.negativePrompt).trim() !== ""){
+                                                        lorahelper.add_selected_neg_trigger_word(event, model_type, model_path, image_data.meta.negativePrompt, active_tab_type);
+                                                    }
+                                                };})(model_type, model_path, image_data, active_tab_type),50);
+                                            };})(model_type, model_path, image_data, active_tab_type));
+                                            image_list.push(image_btn);
+                                            
+                                            let image_setting_btn = lorahelper.create_context_menu_button("");
+                                            let image_setting_ele = document.createElement("img");
+                                            image_setting_ele.setAttribute("src", image_data.url);
+                                            image_setting_ele.style.width = "100px";
+                                            image_setting_btn.appendChild(image_setting_ele);
+                                            image_setting_btn.addEventListener("click", ((model_type, model_path, image_data, active_tab_type) => {return (event) => {
+                                                lorahelper.add_selected_trigger_word(event, model_type, model_path, image_data.meta.prompt, active_tab_type, true);
+                                                window.setTimeout(((event, model_type, model_path, image_data, active_tab_type) => {return () => {
+                                                    if(!lorahelper.is_nullptr(image_data.meta.negativePrompt) && (""+image_data.meta.negativePrompt).trim() !== ""){
+                                                        lorahelper.add_selected_neg_trigger_word(event, model_type, model_path, image_data.meta.negativePrompt, active_tab_type, true);
+                                                    }
+                                                };})(event, model_type, model_path, image_data, active_tab_type),50);
+                                                const tab_ele = lorahelper.gradioApp().querySelector(`#tab_${active_tab_type}`);
+                                                if(!lorahelper.is_nullptr(tab_ele)){
+                                                    const load_size = /^\s*[\[\(\{<]?\s*(\d+)\s*[\*xX,]+\s*(\d+)\s*[\]\)\}>]?\s*$/.exec(image_data.meta.size || image_data.meta.Size);
+                                                    const image_size = {width:parseInt(load_size[1]), height:parseInt(load_size[2]||load_size[1])};
+                                                    const setting_panel = tab_ele.querySelector(`#${active_tab_type}_settings`);
+                                                    let sampling_element = setting_panel.querySelector(`#${active_tab_type}_sampling select`);
+                                                    let steps_element = setting_panel.querySelector(`#${active_tab_type}_steps`);
+                                                    let width_element = setting_panel.querySelector(`#${active_tab_type}_width`);
+                                                    let height_element = setting_panel.querySelector(`#${active_tab_type}_height`);
+                                                    let denoising_strength_element = setting_panel.querySelector(`#${active_tab_type}_denoising_strength`);
+                                                    let cfg_scale_element = setting_panel.querySelector(`#${active_tab_type}_cfg_scale`);
+                                                    let subseed_strength_element = setting_panel.querySelector(`#${active_tab_type}_subseed_strength`);
+                                                    let subseed_element = setting_panel.querySelector(`#${active_tab_type}_subseed`);
+                                                    let seed_element = setting_panel.querySelector(`#${active_tab_type}_seed input`);
+                                                    let mask_blur_element = setting_panel.querySelector(`#${active_tab_type}_mask_blur`);
+    
+                                                    let enable_hr_element = setting_panel.querySelector(`#${active_tab_type}_enable_hr input`);
+                                                    let subseed_show_element = setting_panel.querySelector(`#${active_tab_type}_subseed_show input`);
+    
+                                                    if (!Number.isNaN(image_size.width) && !Number.isNaN(image_size.height)){
+                                                        lorahelper.lora_help_change_number_input(width_element, image_size.width);
+                                                        lorahelper.lora_help_change_number_input(height_element, image_size.height);
+                                                    }
+    
+                                                    for (const [key, value] of Object.entries(image_data.meta)) {
+                                                        const key_name = key.toLowerCase();
+                                                        if(key_name === "seed" && !lorahelper.is_nullptr(seed_element)){
+                                                            lorahelper.update_inputbox(seed_element, value);
+                                                        }
+                                                        if(key_name === "eta" && !lorahelper.is_nullptr(subseed_strength_element)){
+                                                            if(!lorahelper.is_nullptr(subseed_show_element)){
+                                                                subseed_show_element.checked = true;
+                                                                lorahelper.update_inputbox(subseed_show_element, subseed_show_element.value);
+                                                            }
+                                                            lorahelper.lora_help_change_number_input(subseed_strength_element, value);
+                                                        }
+                                                        if(key_name === "ensd" && !lorahelper.is_nullptr(subseed_element)){
+                                                            subseed_show_element.checked = true;
+                                                            lorahelper.update_inputbox(subseed_show_element, subseed_show_element.value);
+                                                            lorahelper.lora_help_change_number_input(subseed_element, value);
+                                                        }
+                                                        if(key_name === "sampler" && !lorahelper.is_nullptr(sampling_element)){
+                                                            let index = -1;
+                                                            let val = value;
+                                                            let opt_index = -1;
+                                                            let selected_option = null;
+                                                            for (var i=0; i<sampling_element.options.length; ++i){
+                                                                const option = sampling_element.options[i];
+                                                                if(option.getAttribute("value").toLowerCase() == value.toLowerCase()){
+                                                                    index = i;
+                                                                    val = option.getAttribute("value");
+                                                                    opt_index = option.index;
+                                                                    selected_option = option;
+                                                                }
+                                                            }
+                                                            if (index > 0){
+                                                                sampling_element.selectedIndex = opt_index;
+                                                                sampling_element.value = val;
+                                                                //set again avoid it disappear
+                                                                sampling_element.selectedIndex = opt_index;
+                                                                lorahelper.my_dispatchEvent(sampling_element, new Event("change", {
+                                                                    bubbles: true,
+                                                                    cancelable: true,
+                                                                }));
+                                                                lorahelper.my_dispatchEvent(sampling_element, new Event("input", {
+                                                                    bubbles: true,
+                                                                    cancelable: true,
+                                                                }));
+                                                            }
+                                                        }
+                                                        if((key_name === "step" || key_name === "steps") && !lorahelper.is_nullptr(steps_element)){
+                                                            lorahelper.lora_help_change_number_input(steps_element, value);
+                                                        }
+                                                        if((key_name === "cfgscale" || key_name === "cfg scale" || 
+                                                            key_name === "cfg_scale") && !lorahelper.is_nullptr(cfg_scale_element)){
+                                                                lorahelper.lora_help_change_number_input(cfg_scale_element, value);
+                                                        }
+                                                        if((key_name === "denoising strength" || key_name === "denoisingstrength") &&
+                                                             !lorahelper.is_nullptr(denoising_strength_element)){
+                                                            if(!lorahelper.is_nullptr(enable_hr_element)){
+                                                                enable_hr_element.checked = true;
+                                                                lorahelper.update_inputbox(enable_hr_element, enable_hr_element.value);
+                                                            }
+                                                            lorahelper.lora_help_change_number_input(denoising_strength_element, value);
+                                                        }
+                                                        if((key_name === "mask blur" || key_name === "maskblur") &&
+                                                             !lorahelper.is_nullptr(mask_blur_element)){
+                                                                lorahelper.lora_help_change_number_input(mask_blur_element, value);
+                                                        }
+    
+                                                    }
+                                                }
+                                            };})(model_type, model_path, image_data, active_tab_type));
+                                            image_setting_list.push(image_setting_btn);
+                                        }
+                                    }
+                                }
+                                if (image_list.length > 0){
+                                    let sub_menu = lorahelper.create_context_subset(lorahelper.get_UI_display("add prompt by image"), image_list);
+                                    let sub_setting_menu = lorahelper.create_context_subset(lorahelper.get_UI_display("use prompt and setting by image"), image_setting_list);
+                                    lorahelper.lorahelper_context_menu_opt.appendChild(sub_menu);
+                                    lorahelper.lorahelper_context_menu_opt.appendChild(sub_setting_menu);
+                                    options_count += 2;
+                                }
+                            }
+                        }
+                        if (options_count > 0){
+                            lorahelper.lorahelper_context_menu_opt.prepend(lorahelper.create_context_menu_hr_item());
+                        }
+                    }
+                } catch(ex){
+        
+                }
+                if(prompt_count <= 0) {
+                    let context_menu_item = lorahelper.create_context_menu_button(lorahelper.get_UI_display("(No Trigger Word)"));
+                    context_menu_item.setAttribute("onclick","lorahelper.close_lora_context_menu()");
+                    lorahelper.lorahelper_context_menu_list.appendChild(context_menu_item);
+                }
+                lorahelper.context_menu_search_box_item.style.display = "block";
+                lorahelper.show_edit_btn();
+                lorahelper.lorahelper_context_menu_edit_btn.setAttribute("onclick", `lorahelper.update_trigger_words(event, '${model_type}', '${model_path}', '${bgimg}')`);
+                lorahelper.show_lora_context_menu(mouseX, mouseY);
+            }; })(mouseX, mouseY)
+        ).sent();
+    
+        lorahelper.debug("end show_trigger_words");
+    
+        if(event){
+            event.stopPropagation();
+            event.preventDefault();
+        }
+    }
+    
+    function add_selected_trigger_word(event, model_type, model_path, addprompt, active_tab_type, overwrite){
+        lorahelper.debug("start add_selected_trigger_word");
+    
+        //get hidden components of extension 
+        let js_add_selected_trigger_word_btn = lorahelper.gradioApp().getElementById("lorahelp_js_add_selected_trigger_word_btn");
+        if (!js_add_selected_trigger_word_btn) {
+            return;
+        }
+    
+        let txt2img_prompt = lorahelper.txt2img_prompt;
+        let img2img_prompt = lorahelper.img2img_prompt;
+    
+        let param = {
+            "action": "add_selected_trigger_word",
+            "addprompt":addprompt,
+            "model_type": model_type,
+            "model_path": model_path,
+            "txt2img_prompt": txt2img_prompt.value,
+            "img2img_prompt": img2img_prompt.value,
+            "neg_prompt": "",
+            "active_tab_type": active_tab_type
+        };
+        if(overwrite === true) param.overwrite = 1;
+        
+        //ajax to python side
+        new lorahelper.myAJAX(param, js_add_selected_trigger_word_btn).sent();
+    
+        lorahelper.close_lora_context_menu();
+        lorahelper.debug("end add_selected_trigger_word");
+    
+        if(event){
+            event.stopPropagation();
+            event.preventDefault();
+        }
+    }
+    
+    function add_selected_neg_trigger_word(event, model_type, model_path, addprompt, active_tab_type, overwrite){
+        lorahelper.debug("start add_selected_neg_trigger_word");
+    
+        //get hidden components of extension 
+        let js_add_selected_neg_trigger_word_btn = lorahelper.gradioApp().getElementById("lorahelp_js_add_selected_neg_trigger_word_btn");
+        if (!js_add_selected_neg_trigger_word_btn) {
+            return;
+        }
+    
+        let txt2img_prompt = lorahelper.neg_txt2img_prompt;
+        let img2img_prompt = lorahelper.neg_img2img_prompt;
+    
+        let param = {
+            "action": "add_selected_trigger_word",
+            "addprompt":addprompt,
+            "model_type": model_type,
+            "model_path": model_path,
+            "txt2img_prompt": txt2img_prompt.value,
+            "img2img_prompt": img2img_prompt.value,
+            "neg_prompt": "",
+            "active_tab_type": active_tab_type
+        }
+        if(overwrite === true) param.overwrite = 1;
+    
+        //ajax to python side
+        new lorahelper.myAJAX(param, js_add_selected_neg_trigger_word_btn).sent();
+    
+        lorahelper.close_lora_context_menu();
+        lorahelper.debug("end add_selected_neg_trigger_word");
+        if(event){
+            event.stopPropagation();
+            event.preventDefault();
+        }
+    }
+    
+    function update_trigger_words(event, model_type, model_path, bgimg){
+        lorahelper.debug("start update_trigger_words");
+    
+        //get hidden components of extension 
+        let js_update_trigger_words_btn = lorahelper.gradioApp().getElementById("lorahelp_js_update_trigger_words_btn");
+        if (!js_update_trigger_words_btn) {
+            return;
+        }
+    
+        //msg to python side
+        new lorahelper.myAJAX({
+            "action": "update_trigger_words",
+            "model_type": model_type,
+            "model_path": model_path,
+        }, js_update_trigger_words_btn).sent();
+    
+        lorahelper.switch_to_helper_tab();
+        lorahelper.close_lora_context_menu();
+        lorahelper.dataedit_search_box.value = "";
+        lorahelper.lorahelper_model_image.innerHTML = "";
+        let state = {EditTab:false};
+        let interval_id = window.setInterval((function(state_obj, bgimg_src){
+            return function(){
+                if(!state_obj.EditTab){
+                    state_obj.EditTab = true;
+                    let edit_model_tab = lorahelper.get_tab_by_name("Edit Model Trigger Words");
+                    if(edit_model_tab) edit_model_tab.click();
+                    else lorahelper.debug("fail to switch to edit tab.");
+                }
+                if(lorahelper.lorahelper_model_image_parent.clientWidth <= 0) return;
+                let theHeight = lorahelper.lorahelper_model_image_parent.clientHeight;
+                if (theHeight <= 0){
+                    theHeight = lorahelper.lorahelper_model_image_parent.clientWidth;
+                }
+                let preview_model_image = document.createElement("img");
+                preview_model_image.setAttribute("src", bgimg_src);
+                preview_model_image.style.margin = "0 auto";
+                preview_model_image.style.height = `${theHeight}px`
+                lorahelper.lorahelper_model_image.appendChild(preview_model_image);
+                lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("table").parentElement.style.overflow = "scroll";
+                lorahelper.gradioApp().getElementById("js_tab_adv_edit").parentElement.parentElement.querySelectorAll("button")[0].click();
+                window.clearInterval(interval_id);
+            };
+        })(state, bgimg), 50);
+    
+        lorahelper.debug("end update_trigger_words");
+    
+        if(event){
+            event.stopPropagation();
+            event.preventDefault();
+        }
+    }
+
+    lorahelper.show_trigger_words = show_trigger_words;
+    lorahelper.add_selected_trigger_word = add_selected_trigger_word;
+    lorahelper.add_selected_neg_trigger_word = add_selected_neg_trigger_word;
+    lorahelper.update_trigger_words = update_trigger_words;
+}
+let module_loadded = false;
+document.addEventListener("DOMContentLoaded", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+document.addEventListener("load", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+})();

+ 197 - 0
javascript/gradio_ui_control.js

@@ -0,0 +1,197 @@
+
+(function(){
+
+function module_init() {
+    
+    console.log("[lora-prompt-tool] load gradio UI Control module");
+    function switch_to_helper_tab(){
+        let tabs = lorahelper.gradioApp().querySelector('#tabs').querySelectorAll('button');
+        let target_tab_name = lorahelper.my_getTranslation("LoRA prompt helper");
+        if (!target_tab_name) {
+            target_tab_name = "LoRA prompt helper";
+        }
+        let complete_flag = false;
+        let tab_name = "";
+        for (const tab of tabs) {
+            tab_name = tab.innerHTML;
+            if(tab_name.trim().indexOf(target_tab_name.trim()) > -1){
+                tab.click();
+                complete_flag = true;
+                break;
+            }
+        }
+        if(!complete_flag){
+            target_tab_name = "LoRA prompt helper";
+            for (const tab of tabs) {
+                tab_name = tab.innerHTML;
+                if(tab_name.trim().indexOf(target_tab_name.trim()) > -1){
+                    tab.click();
+                    break;
+                }
+            }
+        }
+        lorahelper.dataframe_focus_check();
+    }
+
+    function find_tag_by_innerHTML(parent, tagname, innerHTML){
+        if(!lorahelper.is_nullptr(parent)){
+            if(typeof(parent.querySelectorAll) === typeof(lorahelper.noop_func)){
+                let tag_list = parent.querySelectorAll(tagname);
+                let target_element_name = lorahelper.my_getTranslation(innerHTML);
+                if (!target_element_name) {
+                    target_element_name = innerHTML;
+                }
+                let complete_flag = false;
+                let element_name = "";
+                for (const element of tag_list) {
+                    element_name = element.innerHTML;
+                    if(element_name.trim().indexOf(target_element_name.trim()) > -1 ){
+                        return element;
+                    }
+                }
+                if(!complete_flag){
+                    target_element_name = innerHTML;
+                    for (const element of tag_list) {
+                        element_name = element.innerHTML;
+                        if(element_name.trim().indexOf(target_element_name.trim()) > -1 ){
+                            return element;
+                        }
+                    }
+                }
+            }
+        }
+    }
+    
+    function get_tab_by_name(input_tab_name){
+        let tabs = lorahelper.gradioApp().querySelector('#tabs').querySelectorAll('button');
+        let target_tab_name = lorahelper.my_getTranslation(input_tab_name);
+        if (!target_tab_name) {
+            target_tab_name = input_tab_name;
+        }
+        let complete_flag = false;
+        let tab_name = "";
+        for (const tab of tabs) {
+            tab_name = tab.innerHTML;
+            if(tab_name.trim() == target_tab_name.trim()){
+                return tab;
+            }
+        }
+        if(!complete_flag){
+            target_tab_name = input_tab_name;
+            for (const tab of tabs) {
+                tab_name = tab.innerHTML;
+                if(tab_name.trim() == target_tab_name.trim()){
+                    return tab;
+                }
+            }
+        }
+        return null;
+    }
+
+    function lora_help_change_number_input(target, value){
+        let input_eles = target.querySelectorAll("input");
+        let value_changed = false;
+        for(let input_ele of input_eles){ 
+            if((''+input_ele.value) !== (''+value)){
+                input_ele.value = value;
+                value_changed = true;
+            }
+        }
+        if(value_changed){
+            for(let input_ele of input_eles) lorahelper.my_dispatchEvent(
+                input_ele, new Event("input", {
+                    bubbles: true,
+                    cancelable: true,
+                })
+            );
+        }
+    }
+    
+    function is_dataframe_selected(){
+        const cell_list = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("table").querySelectorAll("td");
+        for(const cell of cell_list){
+            let select_flag = cell.contains(document.activeElement);
+            if (lorahelper.gradio_no_select_event){
+                select_flag = !cell.childNodes[0].classList.contains("border-transparent");
+            }
+            if (select_flag) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    function lorahelp_gradio_version(){
+        let foot = lorahelper.gradioApp().getElementById("footer");
+        if (!foot){return null;}
+    
+        let versions = foot.querySelector(".versions");
+        if (!versions){return null;}
+    
+        if (versions.innerHTML.indexOf("gradio: 3.16.2")>0) {
+            return "3.16.2";
+        } else {
+            return "3.23.0";
+        }
+        
+    }
+    
+    function getActiveTabType() {
+        if(typeof(get_uiCurrentTabContent) !== typeof(lorahelper.noop_func)) return null;
+        const currentTab = get_uiCurrentTabContent();
+        switch (currentTab?.id) {
+            case "tab_txt2img":
+                return "txt2img";
+            case "tab_img2img":
+                return "img2img";
+        }
+        return null;
+    }
+    
+    function getActivePrompt() {
+        if(typeof(get_uiCurrentTabContent) !== typeof(lorahelper.noop_func)) return null;
+        const currentTab = get_uiCurrentTabContent();
+        switch (currentTab?.id) {
+            case "tab_txt2img":
+                return lorahelper.txt2img_prompt;
+            case "tab_img2img":
+                return lorahelper.img2img_prompt;
+        }
+        return null;
+    }
+    
+    function getActiveNegativePrompt() {
+        if(typeof(get_uiCurrentTabContent) !== typeof(lorahelper.noop_func)) return null;
+        const currentTab = get_uiCurrentTabContent();
+        switch (currentTab?.id) {
+            case "tab_txt2img":
+                return lorahelper.neg_txt2img_prompt;
+            case "tab_img2img":
+                return lorahelper.neg_img2img_prompt;
+        }
+        return null;
+    }
+
+    lorahelper.switch_to_helper_tab = switch_to_helper_tab;
+    lorahelper.lora_help_change_number_input = lora_help_change_number_input;
+    lorahelper.is_dataframe_selected = is_dataframe_selected;
+    lorahelper.lorahelp_gradio_version = lorahelp_gradio_version;
+    lorahelper.getActiveTabType = getActiveTabType;
+    lorahelper.getActivePrompt = getActivePrompt;
+    lorahelper.getActiveNegativePrompt = getActiveNegativePrompt;
+    lorahelper.get_tab_by_name = get_tab_by_name;
+    lorahelper.find_tag_by_innerHTML = find_tag_by_innerHTML;
+}
+let module_loadded = false;
+document.addEventListener("DOMContentLoaded", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+document.addEventListener("load", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+})();
+

+ 919 - 0
javascript/localization.js

@@ -0,0 +1,919 @@
+(function(){
+
+function module_init() {
+    console.log("[lora-prompt-tool] load localization module");
+
+    const my_localization_data = {
+      "LoRA prompt helper": {
+        "zh_TW": "LoRA提示詞工具",
+        "ja": "LoRAプロンプトヘルパー",
+        "ko": "LoRA 프롬프트 도우미",
+        "zh_CN": "LoRA提示词工具"
+      },
+      "Edit Model Trigger Words": {
+        "zh_TW": "編輯模型觸發詞",
+        "ja": "モデルトリガーワードの編集",
+        "ko": "모델 트리거 단어 수정",
+        "zh_CN": "编辑模型触发词"
+      },
+      "Enter your custom name.": {
+        "zh_TW": "輸入您的自訂名稱",
+        "ja": "カスタム名を入力します。",
+        "ko": "사용자 지정 이름을 입력합니다.",
+        "zh_CN": "将模型触发词保存到模型资料文件中"
+      },
+      "Enter your trigger word. EX: character_name_\\(title of novel\\)": {
+        "zh_TW": "輸入您的觸發提示詞。 EX: 角色名稱_\\(作品名稱\\)",
+        "ja": "トリガーワードを入力してください。 例: キャラクター名_\\(小説のタイトル\\)",
+        "ko": "트리거 단어를 입력하십시오. 예: character_name_\\(소설 제목\\)",
+        "zh_CN": "输入您的触发提示词。 EX: 角色名称_\\(作品名称\\) "
+      },
+      "(optional) separated by commas. EX: Character Name/Style Attributes": {
+        "zh_TW": "(選用) 以逗點分隔。 EX: 角色名稱/風格屬性",
+        "ja": "(オプション) カンマで区切ります。 例: キャラクター名/スタイル属性",
+        "ko": "(선택 사항) 쉼표로 구분합니다. 예: 캐릭터 이름/스타일 속성",
+        "zh_CN": "(可选) 以逗点分隔。 EX: 角色名称/风格属性 "
+      },
+      "It is automatically set to No when adding, and it needs to be changed again": {
+        "zh_TW": "添加時自動設定為否,有需要再改",
+        "ja": "追加時に自動的に「いいえ」に設定されるため、再度変更する必要があります。",
+        "ko": "추가 시 자동으로 No로 설정되며 다시 변경해야 합니다.",
+        "zh_CN": "添加时自动设定为否,有需要再改"
+      },
+      "Update the JSON data from user input.": {
+        "zh_TW": "從在編輯頁面上做的編輯更新本JSON表格",
+        "ja": "ユーザー入力からJSONデータを更新する",
+        "ko": "사용자 입력에서 JSON 데이터 업데이트",
+        "zh_CN": "从在编辑页面上做的编辑更新本JSON表格"
+      },
+      "Reload trigger words from model information file.": {
+        "zh_TW": "從模型資料檔案中重新載入模型觸發詞",
+        "ja": "モデル情報ファイルからトリガーワードを再読み込みする",
+        "ko": "모델 정보 파일에서 트리거 단어 다시 로드",
+        "zh_CN": "从模型资料文件中重新加载模型触发词"
+      },
+      "Save the trigger words to model information file.": {
+        "zh_TW": "將模型觸發詞存檔到模型資料檔案中",
+        "ja": "トリガーワードをモデル情報ファイルに保存する",
+        "ko": "트리거 단어를 모델 정보 파일에 저장",
+        "zh_CN": "将模型触发词保存到模型资料文件中"
+      },
+      "prompts": {
+        "zh_TW": "提示詞",
+        "ja": "プロンプト",
+        "ko": "프롬프트",
+        "zh_CN": "提示词"
+      },
+      "prompt": {
+        "zh_TW": "提示詞",
+        "ja": "プロンプト",
+        "ko": "프롬프트",
+        "zh_CN": "提示词"
+      },
+      "title": {
+        "zh_TW": "標題",
+        "ja": "タイトル",
+        "ko": "제목",
+        "zh_CN": "标题"
+      },
+      "trainedWords": {
+        "zh_TW": "已訓練的提示詞",
+        "ja": "訓練済みのプロンプト",
+        "ko": "훈련된 프롬프트",
+        "zh_CN": "已训练的提示词"
+      },
+      "baseModel": {
+        "zh_TW": "基底模型",
+        "ja": "ベースモデル",
+        "ko": "베이스 모델",
+        "zh_CN": "基底模型"
+      },
+      "description": {
+        "zh_TW": "描述",
+        "ja": "説明",
+        "ko": "설명",
+        "zh_CN": "描述"
+      },
+      "modelId": {
+        "zh_TW": "模型編號",
+        "ja": "モデルID",
+        "ko": "모델 ID",
+        "zh_CN": "模型编号"
+      },
+      "negativePrompt": {
+        "zh_TW": "反向提示詞",
+        "ja": "ネガティブプロンプト",
+        "ko": "부정적인 프롬프트",
+        "zh_CN": "反向提示词"
+      },
+      "hashes": {
+        "zh_TW": "雜湊值",
+        "ja": "ハッシュ値",
+        "ko": "해시 값",
+        "zh_CN": "散列值"
+      },
+      "Size": {
+        "zh_TW": "尺寸",
+        "ja": "サイズ",
+        "ko": "크기",
+        "zh_CN": "尺寸"
+      },
+      "name": {
+        "zh_TW": "名稱",
+        "ja": "名前",
+        "ko": "이름",
+        "zh_CN": "名称"
+      },
+      "Success": {
+        "zh_TW": "成功",
+        "ja": "成功",
+        "ko": "성공",
+        "zh_CN": "成功"
+      },
+      "virusScanResult": {
+        "zh_TW": "掃毒結果",
+        "ja": "ウイルススキャン結果",
+        "ko": "바이러스 스캔 결과",
+        "zh_CN": "扫毒结果"
+      },
+      "downloadUrl": {
+        "zh_TW": "下載網址",
+        "ja": "ダウンロードURL",
+        "ko": "다운로드 URL",
+        "zh_CN": "下载网址"
+      },
+      "sizeKB": {
+        "zh_TW": "檔案大小 (KB)",
+        "ja": "ファイルサイズ(KB)",
+        "ko": "파일 크기 (KB)",
+        "zh_CN": "文件大小 (KB)"
+      },
+      "(from CivitAI)": {
+        "zh_TW": "(來自CivitAI)",
+        "ja": "(CivitAIから)",
+        "ko": "(CivitAI에서)",
+        "zh_CN": "(来自CivitAI)"
+      },
+      "(No Trigger Word)": {
+        "zh_TW": "(無觸發詞)",
+        "ja": "(トリガーワードなし)",
+        "ko": "(트리거 단어 없음)",
+        "zh_CN": "(无触发词)"
+      },
+      "edit prompt words...": {
+        "zh_TW": "編輯...",
+        "ja": "プロンプトを編集する...",
+        "ko": "프롬프트 단어 편집...",
+        "zh_CN": "编辑..."
+      },
+      "Not": {
+        "zh_TW": "否",
+        "ja": "いいえ",
+        "ko": "아니요",
+        "zh_CN": "否"
+      },
+      "##Civitai##": {
+        "zh_TW": "(CivitAI提供的提詞)",
+        "ja": "(CivitAIからのプロンプト)",
+        "ko": "(CivitAI에서 제공하는 프롬프트)",
+        "zh_CN": "(CivitAI提供的提词)"
+      },
+      "Sort Order": {
+        "zh_TW": "排序方式",
+        "ja": "ソート順",
+        "ko": "정렬 순서",
+        "zh_CN": "排序方式"
+      },
+      "Ascending": {
+        "zh_TW": "升序排序",
+        "ja": "昇順",
+        "ko": "오름차순",
+        "zh_CN": "升序排序"
+      },
+      "Descending": {
+        "zh_TW": "降序排序",
+        "ja": "降順",
+        "ko": "내림차순",
+        "zh_CN": "降序排序"
+      },
+      "Content copied to clipboard": {
+        "zh_TW": "成功將所選擇的儲存格複製到剪貼簿",
+        "ja": "選択されたセルがクリップボードにコピーされました",
+        "ko": "선택한 셀이 클립 보드로 복사되었습니다",
+        "zh_CN": "成功将所选择的单元格复制到剪贴板"
+      },
+      "Failed to copy": {
+        "zh_TW": "複製失敗",
+        "ja": "コピーに失敗しました",
+        "ko": "복사 실패",
+        "zh_CN": "复制失败"
+      },
+      "translating...": {
+        "zh_TW": "翻譯中...",
+        "ja": "翻訳中...",
+        "ko": "번역 중...",
+        "zh_CN": "翻译中..."
+      },
+      "translation error": {
+        "zh_TW": "翻譯發生錯誤",
+        "ja": "翻訳エラー",
+        "ko": "번역 오류",
+        "zh_CN": "翻译发生错误"
+      },
+      "add prompt by image": {
+        "zh_TW": "加入範例圖片的提示詞",
+        "ja": "画像からプロンプトを追加",
+        "ko": "이미지로 프롬프트 추가",
+        "zh_CN": "加入示例图片的提示词"
+      },
+      "use prompt and setting by image": {
+        "zh_TW": "使用範例圖片的提示詞和生圖設定",
+        "ja": "画像からプロンプトと設定を使用",
+        "ko": "이미지로 프롬프트와 설정 사용",
+        "zh_CN": "使用示例图片的提示词和生图设置"
+      },
+      "Chinese Traditional": {
+        "zh_TW": "繁體中文",
+        "ja": "繁体中国語",
+        "ko": "중국어 번체",
+        "zh_CN": "繁体中文"
+      },
+      "add model using suggested setting": {
+        "zh_TW": "使用建議的模型設定",
+        "ja": "提案された設定を使用してモデルを追加",
+        "ko": "제안된 설정을 사용하여 모델 추가",
+        "zh_CN": "使用建议的模型设置"
+      },
+      "Use suggested weight": {
+        "zh_TW": "使用建議的權重",
+        "ja": "提案された重みを使用",
+        "ko": "제안된 가중치 사용",
+        "zh_CN": "使用建议的权重"
+      },
+      "Use suggested params": {
+        "zh_TW": "使用建議的模型參數",
+        "ja": "提案されたパラメータを使用",
+        "ko": "제안된 모델 매개변수 사용",
+        "zh_CN": "使用建议的模型参数"
+      },
+      "Use suggested weight and params": {
+        "zh_TW": "使用建議的權重和模型參數",
+        "ja": "提案された重みとパラメータを使用",
+        "ko": "제안된 가중치와 모델 매개변수 사용",
+        "zh_CN": "使用建议的权重和模型参数"
+      }
+    };
+    
+    lorahelper.localizationPromise = new Promise((resolve, reject) => {
+        lorahelper.localizationPromiseResolve = resolve;
+        lorahelper.localizationPromiseReject = reject;
+    });
+
+    let other_translate = {};
+    let try_localization_looping = false;
+    let try_localization = window.setInterval(function(){
+        if (try_localization_looping) return;
+        try {
+            if(!lorahelper.is_nullptr(window.localization) && !lorahelper.is_nullptr(opts.localization)){
+                try_localization_looping = true;
+                if (Object.keys(window.localization).length) {
+                    for (const [key, value] of Object.entries(my_localization_data)) {
+                        if(value[opts.localization]){
+                            window.localization[key] = value[opts.localization];
+                        } else {
+                            const prefix = ((""+(opts.localization||"")).toLowerCase().replace(/[_\-\s]+/,"_").split("_")||[])[0];
+                            if(value[prefix]){
+                              window.localization[key] = value[prefix];
+                          }
+                        }
+                        
+                    }
+                } else {
+                    if(has_bilingual()){
+                        const dirs = opts["bilingual_localization_dirs"];
+                        const file = opts["bilingual_localization_file"];
+                        if (file !== "None" && dirs !== "None"){
+                            const dirs_list = JSON.parse(dirs);
+                            const regex_scope = /^##(?<scope>\S+)##(?<skey>\S+)$/ // ##scope##.skey
+                            const i18n = JSON.parse(lorahelper.readFile(dirs_list[file]), (key, value) => {
+                                if (key.startsWith('@@')) {} //skip
+                                else if (regex_scope.test(key)) {} //skip
+                                else return value;
+                            });
+                            other_translate = i18n;
+                        }
+                    }
+                    //opts["bilingual_localization_dirs"]
+                }
+                lorahelper.translate_ready = true;
+                if(typeof(lorahelper.localizationPromiseResolve) === typeof(lorahelper.noop_func)){
+                    lorahelper.localizationPromiseResolve();
+                }
+                try_localization_looping = false;
+                window.clearInterval(try_localization);
+            }
+        } catch (error) {
+            console.log(error.stack);
+        }
+    },10);
+
+    function get_if_not_empty(toget){
+        if(lorahelper.is_empty(toget)) return undefined;
+        if((''+toget).toLowerCase() === "none") return undefined;
+        return toget;
+    }
+    function get_system_language(){
+        let DateTimeFormat_obj = Intl?.DateTimeFormat;
+        if(typeof(DateTimeFormat_obj) !== typeof(lorahelper.noop_func)) return undefined;
+        return DateTimeFormat_obj()?.resolvedOptions()?.locale
+    }
+
+    function has_bilingual(){
+        return !!opts.bilingual_localization_enabled && !!get_if_not_empty(opts.bilingual_localization_file) && !(Object.keys(window.localization||{}).length);
+    }
+
+    function get_language_code(for_translate){
+        const selected_language_code = get_if_not_empty(opts.localization);
+        if(selected_language_code){
+            return selected_language_code
+        } else {
+            if(opts.bilingual_localization_enabled){
+                const bilingual_language_code = get_if_not_empty(opts.bilingual_localization_file);
+                if (bilingual_language_code){
+                    return (x=>((x||[]).length>1)?x.slice(0,-1):x)(bilingual_language_code.split(".")).join(".");
+                }
+            } else if (for_translate) {
+                const browser_language_code = get_if_not_empty(navigator.language || navigator.userLanguage);
+                if (browser_language_code){
+                    return browser_language_code;
+                }
+                const system_language_code = get_if_not_empty(get_system_language());
+                if (system_language_code){
+                    return system_language_code;
+                }
+                return "en"; //default english
+            }
+        }
+        return undefined;
+    }
+
+    function is_same_language(lang1, lang2){
+        lang1_split = (''+lang1).trim().toLowerCase().replace(/[_\s\-\+]+/g,"_").split("_");
+        lang2_split = (''+lang2).trim().toLowerCase().replace(/[_\s\-\+]+/g,"_").split("_");
+        if (lang1_split[0] !== lang2_split[0]) return false;
+        if (lang1_split.length <= 1) return true;
+        if (lang2_split.length <= 1) return false;
+        let flag = true;
+        for (const variants of lang1_split){
+            flag = flag && !!lang2_split.includes(variants);
+        }
+        return flag;
+    }
+
+    function get_myTranslation_in_mydist(msg, lang_code){
+        const msg_obj = my_localization_data[msg];
+        if (msg_obj){
+            for (const [lang_name, translated_msg] of Object.entries(msg_obj)) {
+                if(is_same_language(lang_name, lang_code)) return translated_msg;
+            }
+        }
+        return undefined;
+    }
+
+    function my_getTranslation(msg){
+        const selected_language_code = get_language_code();
+        let trans = getTranslation(msg);
+        if (selected_language_code){
+            const my_translate = get_myTranslation_in_mydist(msg,selected_language_code);
+            if(my_translate) return my_translate;
+        }
+        if (!trans) {
+            trans = other_translate[msg];
+            if (!trans) trans = msg;
+        }
+        return trans;
+    }
+
+    function set_bilingual(element){
+        if (!has_bilingual()) return;
+        if (!lorahelper.is_nullptr(element.querySelector(".bilingual__trans_wrapper"))) return;
+        const msg = element.innerHTML;
+        element.innerHTML = get_UI_display(msg);
+    }
+
+    function get_UI_display(msg){
+        const tmsg = my_getTranslation(msg);
+        if (has_bilingual()){
+            if (tmsg != msg){
+                if(opts.bilingual_localization_order.toLowerCase() === "translation first")
+                    return `<div class="bilingual__trans_wrapper">${tmsg}<em>${msg}</em></div>`;
+                else return `<div class="bilingual__trans_wrapper">${msg}<em>${tmsg}</em></div>`
+            }
+        }
+        return tmsg;
+    }
+
+    function translate_language_selector(){
+        lorahelper.dataedit_translate_btn = lorahelper.gradioApp().getElementById("lorahelp_dataedit_translate_btn")
+        //Create and append select list
+        var selectList = document.createElement("select");
+        selectList.id = "translate_language_selector";
+        let select_box = document.createElement("div");
+
+        selectList.style.position = "absolute";
+        selectList.style.top = "0px";
+        selectList.style.border = "none";
+        selectList.style.backgroundColor = "transparent";
+        selectList.style.opacity = 0;
+
+        select_box.appendChild(selectList);
+        lorahelper.dataedit_translate_btn.appendChild(select_box);
+        lorahelper.dataedit_translate_translate_language_selector = selectList;
+
+        let lang_display = document.createElement("span");
+        lang_display.style.margin = "0.5em";
+        select_box.appendChild(lang_display);
+
+        //Create and append the options
+        let i = 0;
+        const selected_lang_code = get_language_code(true);
+        let select_id = 0;
+        for (const [lang_code, lang_name] of Object.entries(lorahelper.languages)) {
+            var option = document.createElement("option");
+            const lang_data = !!(lang_name.name) ? lang_name : {name: lang_name};
+            option.value = lang_code;
+            option.text = lang_data.display ? `${lang_code} - ${lang_data.display} (${lang_data.name})` : lang_data.name;
+            option.setAttribute("title", lang_data.display ? lang_data.display : lang_data.name);
+            option.setAttribute("lang-name", lang_data.name);
+            if(is_same_language(lang_code, selected_lang_code)){
+                lang_display.innerHTML = lang_data.display;
+                select_id = i;
+            }
+            //option.text = my_getTranslation(lang_name);
+            selectList.appendChild(option);
+            ++i;
+        }
+        selectList.addEventListener("change", function(event){
+            const lang_name = lorahelper.languages[selectList.value];
+            const lang_data = !!(lang_name.name) ? lang_name : {name: lang_name};
+            lang_display.innerHTML = lang_data.display;
+        });
+        lorahelper.dataedit_translate_translate_language_selector.selectedIndex = select_id;
+    }
+    lorahelper.translate_language_selector = translate_language_selector;
+    lorahelper.get_language_code = get_language_code;
+    lorahelper.my_getTranslation = my_getTranslation;
+    lorahelper.get_UI_display = get_UI_display;
+
+    lorahelper.languages = {
+        "auto": "Auto",
+        "af": {
+          "name": "Afrikaans",
+          "display": "Afrikaans"
+        },
+        "sq": {
+          "name": "Albanian",
+          "display": "shqip"
+        },
+        "am": {
+          "name": "Amharic",
+          "display": "አማርኛ"
+        },
+        "ar": {
+          "name": "Arabic",
+          "display": "العربية"
+        },
+        "hy": {
+          "name": "Armenian",
+          "display": "հայերեն"
+        },
+        "az": {
+          "name": "Azerbaijani",
+          "display": "azərbaycanca"
+        },
+        "eu": {
+          "name": "Basque",
+          "display": "euskara"
+        },
+        "be": {
+          "name": "Belarusian",
+          "display": "беларуская"
+        },
+        "bn": {
+          "name": "Bengali",
+          "display": "বাংলা"
+        },
+        "bs": {
+          "name": "Bosnian",
+          "display": "bosanski"
+        },
+        "bg": {
+          "name": "Bulgarian",
+          "display": "български"
+        },
+        "ca": {
+          "name": "Catalan",
+          "display": "català"
+        },
+        "ceb": {
+          "name": "Cebuano",
+          "display": "Cebuano"
+        },
+        "ny": {
+          "name": "Chichewa",
+          "display": "Chi-Chewa"
+        },
+        "zh": {
+          "name": "Chinese",
+          "display": "中文"
+        },
+        "zh_cn": {
+          "name": "Chinese Simplified",
+          "display": "简体中文 (中国大陆)"
+        },
+        "zh_tw": {
+          "name": "Chinese Traditional",
+          "display": "繁體中文 (臺灣)"
+        },
+        "zh_hk": {
+          "name": "Chinese Traditional",
+          "display": "繁體中文 (香港)"
+        },
+        "co": {
+          "name": "Corsican",
+          "display": "corsu"
+        },
+        "hr": {
+          "name": "Croatian",
+          "display": "hrvatski"
+        },
+        "cs": {
+          "name": "Czech",
+          "display": "čeština"
+        },
+        "da": {
+          "name": "Danish",
+          "display": "dansk"
+        },
+        "nl": {
+          "name": "Dutch",
+          "display": "Nederlands"
+        },
+        "en": {
+          "name": "English",
+          "display": "English"
+        },
+        "eo": {
+          "name": "Esperanto",
+          "display": "Esperanto"
+        },
+        "et": {
+          "name": "Estonian",
+          "display": "eesti"
+        },
+        "tl": {
+          "name": "Filipino",
+          "display": "Tagalog"
+        },
+        "fi": {
+          "name": "Finnish",
+          "display": "suomi"
+        },
+        "fr": {
+          "name": "French",
+          "display": "français"
+        },
+        "fy": {
+          "name": "Frisian",
+          "display": "Frysk"
+        },
+        "gl": {
+          "name": "Galician",
+          "display": "galego"
+        },
+        "ka": {
+          "name": "Georgian",
+          "display": "ქართული"
+        },
+        "de": {
+          "name": "German",
+          "display": "Deutsch"
+        },
+        "el": {
+          "name": "Greek",
+          "display": "Ελληνικά"
+        },
+        "gu": {
+          "name": "Gujarati",
+          "display": "ગુજરાતી"
+        },
+        "ht": {
+          "name": "Haitian Creole",
+          "display": "Kreyòl ayisyen"
+        },
+        "ha": {
+          "name": "Hausa",
+          "display": "Hausa"
+        },
+        "haw": {
+          "name": "Hawaiian",
+          "display": "Hawaiʻi"
+        },
+        "he": {
+          "name": "Hebrew",
+          "display": "עברית"
+        },
+        "iw": "Hebrew",
+        "hi": {
+          "name": "Hindi",
+          "display": "हिन्दी"
+        },
+        "hmn": "Hmong",
+        "hu": {
+          "name": "Hungarian",
+          "display": "magyar"
+        },
+        "is": {
+          "name": "Icelandic",
+          "display": "íslenska"
+        },
+        "ig": {
+          "name": "Igbo",
+          "display": "Igbo"
+        },
+        "id": {
+          "name": "Indonesian",
+          "display": "Bahasa Indonesia"
+        },
+        "ga": {
+          "name": "Irish",
+          "display": "Gaeilge"
+        },
+        "it": {
+          "name": "Italian",
+          "display": "italiano"
+        },
+        "ja": {
+          "name": "Japanese",
+          "display": "日本語"
+        },
+        "jw": "Javanese",
+        "kn": {
+          "name": "Kannada",
+          "display": "ಕನ್ನಡ"
+        },
+        "kk": {
+          "name": "Kazakh",
+          "display": "қазақша"
+        },
+        "km": {
+          "name": "Khmer",
+          "display": "ភាសាខ្មែរ"
+        },
+        "rw": {
+          "name": "Kinyarwanda",
+          "display": "Ikinyarwanda"
+        },
+        "ko": {
+          "name": "Korean",
+          "display": "한국어"
+        },
+        "ku": {
+          "name": "Kurdish (Kurmanji)",
+          "display": "kurdî"
+        },
+        "ky": {
+          "name": "Kyrgyz",
+          "display": "кыргызча"
+        },
+        "lo": {
+          "name": "Lao",
+          "display": "ລາວ"
+        },
+        "la": {
+          "name": "Latin",
+          "display": "Latina"
+        },
+        "lv": {
+          "name": "Latvian",
+          "display": "latviešu"
+        },
+        "lt": {
+          "name": "Lithuanian",
+          "display": "lietuvių"
+        },
+        "lb": {
+          "name": "Luxembourgish",
+          "display": "Lëtzebuergesch"
+        },
+        "mk": {
+          "name": "Macedonian",
+          "display": "македонски"
+        },
+        "mg": {
+          "name": "Malagasy",
+          "display": "Malagasy"
+        },
+        "ms": {
+          "name": "Malay",
+          "display": "Bahasa Melayu"
+        },
+        "ml": {
+          "name": "Malayalam",
+          "display": "മലയാളം"
+        },
+        "mt": {
+          "name": "Maltese",
+          "display": "Malti"
+        },
+        "mi": {
+          "name": "Maori",
+          "display": "Māori"
+        },
+        "mr": {
+          "name": "Marathi",
+          "display": "मराठी"
+        },
+        "mn": {
+          "name": "Mongolian",
+          "display": "монгол"
+        },
+        "my": {
+          "name": "Myanmar (Burmese)",
+          "display": "မြန်မာဘာသာ"
+        },
+        "ne": {
+          "name": "Nepali",
+          "display": "नेपाली"
+        },
+        "no": "Norwegian",
+        "or": {
+          "name": "Odia (Oriya)",
+          "display": "ଓଡ଼ିଆ"
+        },
+        "ps": {
+          "name": "Pashto",
+          "display": "پښتو"
+        },
+        "fa": {
+          "name": "Persian",
+          "display": "فارسی"
+        },
+        "pl": {
+          "name": "Polish",
+          "display": "polski"
+        },
+        "pt": {
+          "name": "Portuguese",
+          "display": "português"
+        },
+        "pa": {
+          "name": "Punjabi",
+          "display": "ਪੰਜਾਬੀ"
+        },
+        "ro": {
+          "name": "Romanian",
+          "display": "română"
+        },
+        "ru": {
+          "name": "Russian",
+          "display": "русский"
+        },
+        "sm": {
+          "name": "Samoan",
+          "display": "Gagana Samoa"
+        },
+        "gd": {
+          "name": "Scots Gaelic",
+          "display": "Gàidhlig"
+        },
+        "sr": {
+          "name": "Serbian",
+          "display": "српски / srpski"
+        },
+        "st": {
+          "name": "Sesotho",
+          "display": "Sesotho"
+        },
+        "sn": {
+          "name": "Shona",
+          "display": "chiShona"
+        },
+        "sd": {
+          "name": "Sindhi",
+          "display": "سنڌي"
+        },
+        "si": {
+          "name": "Sinhala",
+          "display": "සිංහල"
+        },
+        "sk": {
+          "name": "Slovak",
+          "display": "slovenčina"
+        },
+        "sl": {
+          "name": "Slovenian",
+          "display": "slovenščina"
+        },
+        "so": {
+          "name": "Somali",
+          "display": "Soomaaliga"
+        },
+        "es": {
+          "name": "Spanish",
+          "display": "español"
+        },
+        "su": {
+          "name": "Sundanese",
+          "display": "Sunda"
+        },
+        "sw": {
+          "name": "Swahili",
+          "display": "Kiswahili"
+        },
+        "sv": {
+          "name": "Swedish",
+          "display": "svenska"
+        },
+        "tg": {
+          "name": "Tajik",
+          "display": "тоҷикӣ"
+        },
+        "ta": {
+          "name": "Tamil",
+          "display": "தமிழ்"
+        },
+        "tt": {
+          "name": "Tatar",
+          "display": "татарча / tatarça"
+        },
+        "te": {
+          "name": "Telugu",
+          "display": "తెలుగు"
+        },
+        "th": {
+          "name": "Thai",
+          "display": "ไทย"
+        },
+        "tr": {
+          "name": "Turkish",
+          "display": "Türkçe"
+        },
+        "tk": {
+          "name": "Turkmen",
+          "display": "Türkmençe"
+        },
+        "uk": {
+          "name": "Ukrainian",
+          "display": "українська"
+        },
+        "ur": {
+          "name": "Urdu",
+          "display": "اردو"
+        },
+        "ug": {
+          "name": "Uyghur",
+          "display": "ئۇيغۇرچە / Uyghurche"
+        },
+        "uz": {
+          "name": "Uzbek",
+          "display": "oʻzbekcha / ўзбекча"
+        },
+        "vi": {
+          "name": "Vietnamese",
+          "display": "Tiếng Việt"
+        },
+        "cy": {
+          "name": "Welsh",
+          "display": "Cymraeg"
+        },
+        "xh": {
+          "name": "Xhosa",
+          "display": "isiXhosa"
+        },
+        "yi": {
+          "name": "Yiddish",
+          "display": "ייִדיש"
+        },
+        "yo": {
+          "name": "Yoruba",
+          "display": "Yorùbá"
+        },
+        "zu": {
+          "name": "Zulu",
+          "display": "isiZulu"
+        }
+      };
+}
+let module_loadded = false;
+document.addEventListener("DOMContentLoaded", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+document.addEventListener("load", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+})();

+ 508 - 0
javascript/lora_prompt_tool.js

@@ -0,0 +1,508 @@
+let lorahelper = {};
+console.log("[lora-prompt-tool] load the main module");
+
+lorahelper.lorahelper_model_image = null;
+lorahelper.lorahelper_model_image_parent = null;
+lorahelper.lorahelper_scope = null;
+lorahelper.lorahelper_scope_div = null;
+lorahelper.lorahelper_trigger_words_dataframe_scope = null;
+
+lorahelper.lorahelp_copy_paste_txtbox = null;
+lorahelper.lorahelp_js_output_message = null;
+lorahelper.lorahelp_translate_area = null;
+lorahelper.js_cors_request_btn = null;
+lorahelper.lorahelp_extension_name = null;
+lorahelper.gradio_no_select_event = false;
+
+onUiLoaded(() => {
+    //load extension name
+    lorahelper.lorahelp_extension_name = lorahelper.gradioApp().querySelector("#lorahelp_extension_name textarea").value;
+
+    //check select event support or not 
+    lorahelper.gradio_no_select_event = !!(lorahelper.gradioApp().querySelector("#lorahelp_select_not_support"));
+    if(lorahelper.gradio_no_select_event){
+        var styleSheet = document.createElement("style");
+        styleSheet.innerHTML = lorahelp_old_ver_css;
+        document.head.appendChild(styleSheet);
+    }
+    
+    //init
+    lorahelper.setup_context_menu();
+    lorahelper.setup_dataframe_edit();
+
+    lorahelper.txt2img_prompt = lorahelper.gradioApp().querySelector("#txt2img_prompt textarea");
+    lorahelper.img2img_prompt = lorahelper.gradioApp().querySelector("#img2img_prompt textarea");
+    lorahelper.neg_txt2img_prompt = lorahelper.gradioApp().querySelector("#txt2img_neg_prompt textarea");
+    lorahelper.neg_img2img_prompt = lorahelper.gradioApp().querySelector("#img2img_neg_prompt textarea");
+
+    ace_txt2img_prompt = lorahelper.gradioApp().querySelector("#ace-txt2img_prompt");
+    ace_img2img_prompt = lorahelper.gradioApp().querySelector("#ace-img2img_prompt");
+    ace_txt2img_neg_prompt = lorahelper.gradioApp().querySelector("#ace-txt2img_neg_prompt");
+    ace_img2img_neg_prompt = lorahelper.gradioApp().querySelector("#ace-img2img_neg_prompt");
+
+    if(!lorahelper.is_nullptr(ace_txt2img_prompt)) lorahelper.txt2img_prompt = ace_txt2img_prompt;
+    if(!lorahelper.is_nullptr(ace_img2img_prompt)) lorahelper.img2img_prompt = ace_img2img_prompt;
+    if(!lorahelper.is_nullptr(ace_txt2img_neg_prompt)) lorahelper.neg_txt2img_prompt = ace_txt2img_neg_prompt;
+    if(!lorahelper.is_nullptr(ace_img2img_neg_prompt)) lorahelper.neg_img2img_prompt = ace_img2img_neg_prompt;
+
+    //preview image size handler
+    lorahelper.lorahelper_model_image = lorahelper.gradioApp().getElementById("lorahelp_js_image_area");
+    let parent_iter = lorahelper.lorahelper_model_image.parentElement
+    while(!lorahelper.is_nullptr(parent_iter)){
+        if(parent_iter.classList.contains('gradio-html') && parent_iter.classList.contains('block')){
+            lorahelper.lorahelper_model_image_parent = parent_iter;
+            break;
+        }
+        parent_iter = parent_iter.parentElement;
+    }
+    if(lorahelper.is_nullptr(lorahelper.lorahelper_model_image_parent)){
+        parent_iter = lorahelper.lorahelper_model_image.parentElement
+        while(!lorahelper.is_nullptr(parent_iter)){
+            if(parent_iter.classList.contains('gr-block') && parent_iter.classList.contains('gr-box')){
+                lorahelper.lorahelper_model_image_parent = parent_iter;
+                break;
+            }
+            parent_iter = parent_iter.parentElement;
+        }
+    }
+    
+    //AJAX setup
+    lorahelper.js_cors_request_btn = lorahelper.gradioApp().getElementById("lorahelp_js_cors_request_btn");
+    lorahelper.lorahelp_js_ajax_txtbox_textarea = lorahelper.gradioApp().querySelector("#lorahelp_js_ajax_txtbox textarea");
+    lorahelper.lorahelp_js_ajax_txtbox_textarea.addEventListener('input', lorahelper.call_lorahelp_js_ajax_txtbox_callback);
+
+    lorahelper.lorahelp_js_output_message = lorahelper.gradioApp().querySelector("#lorahelp_js_output_message textarea");
+
+    lorahelper.lorahelper_trigger_words_dataframe_scope = lorahelper.gradioApp().getElementById("lorahelp_js_trigger_words_dataframe").querySelector("table").parentElement;
+    lorahelper.lorahelp_js_dataframe_observer.observe(lorahelper.lorahelper_trigger_words_dataframe_scope, lorahelper.lorahelp_js_dataframe_observer_config);
+
+    lorahelper.select_index_text_box = lorahelper.gradioApp().querySelector("#lorahelp_dataedit_select_index_txtbox textarea");
+    lorahelper.update_inputbox(lorahelper.select_index_text_box, JSON.stringify(lorahelper.lorahlep_dataframe_unselected));
+
+    lorahelper.lorahelp_translate_area = lorahelper.gradioApp().getElementById("lorahelp_translate_area");
+
+    lorahelper.localizationPromise.then(()=>{
+        let helper_tag = lorahelper.get_tab_by_name("LoRA prompt helper");
+        helper_tag.innerHTML = lorahelper.get_UI_display("LoRA prompt helper");
+
+        lorahelper.gradioApp().getElementById("lorahelp_dataedit_refresh_event_btn").setAttribute("title", lorahelper.my_getTranslation("Reload trigger words from model information file."));
+        lorahelper.gradioApp().getElementById("lorahelp_json_refresh_event_btn").setAttribute("title", lorahelper.my_getTranslation("Update the JSON data from user input."));
+        lorahelper.gradioApp().getElementById("lorahelp_js_save_model_setting_btn").setAttribute("title", lorahelper.my_getTranslation("Save the trigger words to model information file."));
+        let lorahelp_js_sort_order_radio = lorahelper.gradioApp().getElementById("lorahelp_js_sort_order_radio");
+        let lorahelp_js_sort_order_radio_text = lorahelper.find_tag_by_innerHTML(lorahelp_js_sort_order_radio, "span", "Sort Order");
+        if (!lorahelper.is_nullptr(lorahelp_js_sort_order_radio_text)) lorahelp_js_sort_order_radio_text.innerHTML = lorahelper.get_UI_display("Sort Order");
+        lorahelper.find_tag_by_innerHTML(lorahelp_js_sort_order_radio, "span", "Ascending").innerHTML = lorahelper.get_UI_display("Ascending");
+        lorahelper.find_tag_by_innerHTML(lorahelp_js_sort_order_radio, "span", "Descending").innerHTML = lorahelper.get_UI_display("Descending");
+        lorahelper.translate_language_selector();
+        lorahelper.fill_cell_placeholder();
+
+        lorahelper.gradioApp().getElementById("lorahelp_js_load_textbox_prompt_btn").addEventListener('click', e=>{
+            lorahelper.gradioApp().getElementById("js_tab_adv_edit").parentElement.parentElement.querySelectorAll("button")[1].click();
+            lorahelper.dataedit_search_box.value = "";
+        }, false);
+        lorahelper.gradioApp().getElementById("lorahelp_js_load_civitai_setting_btn").addEventListener('click', e=>{
+            lorahelper.gradioApp().getElementById("js_tab_adv_edit").parentElement.parentElement.querySelectorAll("button")[1].click();
+            lorahelper.dataedit_search_box.value = "";
+        }, false);
+        lorahelper.gradioApp().getElementById("lorahelp_js_load_dreambooth_setting_btn").addEventListener('click', e=>{
+            lorahelper.gradioApp().getElementById("js_tab_adv_edit").parentElement.parentElement.querySelectorAll("button")[1].click();
+            lorahelper.dataedit_search_box.value = "";
+        }, false);
+
+        let dataedit_search = lorahelper.gradioApp().getElementById("lorahelp_js_dataframe_filter").querySelector("input, textarea");
+        for(const eve_name of ["change", "keypress", "paste", "input"]){
+            dataedit_search.addEventListener(eve_name, e=>{
+                lorahelper.updateDataeditSearchingBox();
+            }, false);
+        }
+        lorahelper.dataedit_search_box = dataedit_search;
+
+        (()=>{
+            // Select the node that will be observed for mutations
+            const targetNode = document.getElementById("lorahelp_simpleedit_supergroup_other");
+    
+            // Options for the observer (which mutations to observe)
+            const config = { attributes: true, childList: true, subtree: true };
+    
+            // Callback function to execute when mutations are observed
+            const callback = (mutationList, observer) => {
+                lorahelper.update_simpleedit_group();
+            };
+    
+            // Create an observer instance linked to the callback function
+            const observer = new MutationObserver(callback);
+    
+            // Start observing the target node for configured mutations
+            observer.observe(targetNode, config);
+        })();
+
+    });
+
+    //緒山真尋!! 緒山真尋!! 緒山真尋!! 緒山真尋!! 緒山真尋!!
+    let mahiro_btn = lorahelper.gradioApp().getElementById("lorahelp_oyama_mahiro");
+    if(!lorahelper.is_nullptr(mahiro_icon) && !lorahelper.is_nullptr(mahiro_icon2)){
+        let mahiro_img = document.createElement("img");
+        mahiro_img.setAttribute("src", mahiro_icon);
+        mahiro_img.style.height = "32px";
+        mahiro_img.style.position = "absolute";
+        
+        mahiro_btn.appendChild(mahiro_img);
+        mahiro_btn.addEventListener('click', function(ev) {
+            mahiro_img.setAttribute("src", mahiro_icon2);
+            window.setTimeout(()=>{
+                alert("你好,我是緒山真尋!!\nこんにちは、おやま まひろです!!");
+                new Audio(watashiwoyamamahoro).play();
+                lorahelper.lorahelp_js_output_message.value = "你去問緒山真尋這程式寫好沒!";
+                window.setTimeout(()=>mahiro_img.setAttribute("src", mahiro_icon),1000);
+            },100);
+        }, false);
+        mahiro_btn.addEventListener('mouseover', event => mahiro_img.setAttribute("src", mahiro_icon2), false);
+        mahiro_btn.addEventListener('mouseleave', event => mahiro_img.setAttribute("src", mahiro_icon), false);
+        mahiro_btn.setAttribute("title", "緒山真尋!");
+        mahiro_btn.setAttribute("oncontextmenu","lorahelper.build_mahiro_menu(event)");
+        mahiro_btn.setAttribute("ondblclick","lorahelper.build_mahiro_menu(event)");
+    } else {
+        //お兄ちゃんはおしまい!
+        mahiro_btn.style.display = "none";
+    }
+
+    lorahelper.lorahelp_copy_paste_txtbox = lorahelper.gradioApp().querySelector("#lorahelp_copy_paste_txtbox textarea");
+
+    //get gradio version
+    let gradio_ver = lorahelper.lorahelp_gradio_version();
+    lorahelper.debug("gradio_ver:" + gradio_ver);
+
+    // get all extra network tabs
+    let tab_prefix_list = ["txt2img", "img2img"];
+    let model_type_list = ["textual_inversion", "hypernetworks", "checkpoints", "lora", "lycoris"];
+    let cardid_suffix = "cards";
+
+    function update_card_for_lorahelper(){
+        let replace_preview_text = lorahelper.my_getTranslation("replace preview");
+        if (!replace_preview_text) {
+            replace_preview_text = "replace preview";
+        }
+
+        //initial values
+        let extra_network_id = "";
+        let extra_network_node = null;
+        let model_path_node = null;
+        let model_name_node = null;
+        let model_path = "";
+        let model_name = "";
+        let model_type = "";
+        let cards = null;
+
+        //get current tab
+        let active_tab_type = lorahelper.getActiveTabType();
+        if (!active_tab_type){active_tab_type = "txt2img";}
+
+        for (const tab_prefix of tab_prefix_list) {
+            if (tab_prefix != active_tab_type) continue;
+
+            let log_messages = [];
+
+            //find out current selected model type tab
+            let active_extra_tab_type = "";
+            let extra_tabs = lorahelper.gradioApp().getElementById(tab_prefix+"_extra_tabs");
+            if (!extra_tabs) {
+                log_messages.push("can not find extra_tabs: " + tab_prefix+"_extra_tabs");
+            }
+
+            //get active extratab
+            let try_to_get_extra_tab = Array.from(get_uiCurrentTabContent().querySelectorAll('.extra-network-cards,.extra-network-thumbs'))
+            if(try_to_get_extra_tab.length <= 0){ //support for kitchen-theme and lobe-theme
+                let txt2img_array_tmp = Array.from(lorahelper.gradioApp().querySelector("#txt2img-extra-network-sidebar, #txt2img-extra-netwrok-sidebar")?.querySelectorAll('.extra-network-cards,.extra-network-thumbs')||[]);
+                let img2img_array_tmp = Array.from(lorahelper.gradioApp().querySelector("#img2img-extra-network-sidebar, #img2img-extra-netwrok-sidebar")?.querySelectorAll('.extra-network-cards,.extra-network-thumbs')||[]);
+                try_to_get_extra_tab = txt2img_array_tmp.concat(img2img_array_tmp);
+            }
+            const active_extra_tab = try_to_get_extra_tab
+                .find(el => el.closest('.tabitem').style.display === 'block')
+                ?.id.match(/^(txt2img|img2img)_(.+)_cards$/)[2];
+
+            switch (active_extra_tab) {
+                case "textual_inversion":
+                    active_extra_tab_type = "ti";
+                    break;
+                case "hypernetworks":
+                    active_extra_tab_type = "hyper";
+                    break;
+                case "checkpoints":
+                    active_extra_tab_type = "ckp";
+                    break;
+                case "lora":
+                    active_extra_tab_type = "lora";
+                    break;
+                case "lycoris":
+                    active_extra_tab_type = "lyco";
+                    break;
+            }
+            let tab_counter = 0;
+            for (const js_model_type of model_type_list) {
+                //get model_type for python side
+                switch (js_model_type) {
+                    case "textual_inversion":
+                        model_type = "ti";
+                        break;
+                    case "hypernetworks":
+                        model_type = "hyper";
+                        break;
+                    case "checkpoints":
+                        model_type = "ckp";
+                        break;
+                    case "lora":
+                        model_type = "lora";
+                        break;
+                    case "lycoris":
+                        model_type = "lyco";
+                        break;
+                }
+
+                if (!model_type) {
+                    log_messages.push("can not get model_type from: " + js_model_type);
+                    continue;
+                }
+
+                let extra_network_parent = null;
+                //only handle current sub-tab
+                extra_network_id = tab_prefix+"_"+js_model_type+"_"+cardid_suffix;
+                if (model_type != active_extra_tab_type) continue;
+                extra_network_node = lorahelper.gradioApp().getElementById(extra_network_id);
+                // check if extr network is under thumbnail mode
+                is_thumb_mode = false
+                if (extra_network_node) {
+                    if (extra_network_node.className == "extra-network-thumbs") {
+                        log_messages.push(extra_network_id + " is in thumbnail mode");
+                        is_thumb_mode = true;
+                    }
+                } else {
+                    log_messages.push("can not find extra_network_node: " + extra_network_id);
+                    continue;
+                }
+
+                let i = 0;
+                // get all card nodes
+                cards = extra_network_node.querySelectorAll(".card");
+                for (let card of cards) {
+                    if(card.classList.contains("lorahelp-context_menu")) continue;
+                    card.classList.add("lorahelp-context_menu");
+                    if(i==0){
+                        log_messages.push("setup context menu for " + extra_network_id);
+                        for(const msg of log_messages) lorahelper.debug(msg);
+                    }
+                    //metadata_buttoncard
+                    metadata_button = card.querySelector(".metadata-button");
+                    //additional node
+                    additional_node = card.querySelector(".actions .additional");
+                    //get ul node, which is the parent of all buttons
+                    ul_node = card.querySelector(".actions .additional ul");
+                    // replace preview text button
+                    replace_preview_btn = card.querySelector(".actions .additional a");
+
+                    // model_path node
+                    // model_path = subfolder path + model name + ext
+                    model_path_node = card.querySelector(".actions .additional .search_term");
+                    if (!model_path_node){
+                        lorahelper.debug("can not find search_term node for cards in " + extra_network_id);
+                        continue;
+                    }
+
+                    model_name_node = card.querySelector(".actions .name");
+                    if (!model_name_node){
+                        lorahelper.debug("can not find name node for cards in " + extra_network_id);
+                    }
+
+                    // get model_path
+                    model_path = model_path_node.innerHTML;
+                    if (!model_path) {
+                        lorahelper.debug("model_path is empty for cards in " + extra_network_id);
+                        continue;
+                    }
+                    model_name = model_name_node.innerHTML;
+                    if (!model_name) {
+                        lorahelper.debug("model_name is empty for cards in " + extra_network_id);
+                        model_name = "";
+                    }
+                    model_path = model_path.replace(/(\.(bin|pt|safetensors|ckpt))(\s+)?([a-z0-9]+)?$/i, "$1");
+                    let bgimg = card.style.backgroundImage || "url(\"./file=html/card-no-preview.png\")";
+                    if(lorahelper.is_empty(card.style.backgroundImage)){
+                        let img_preview = card.querySelector("img.preview");
+                        let tmp_bgimg = "./file=html/card-no-preview.png";
+                        if(img_preview){
+                            tmp_bgimg = card.querySelector("img.preview").getAttribute('src');
+                        }
+                        if(lorahelper.is_empty(tmp_bgimg)){
+                            tmp_bgimg = "./file=html/card-no-preview.png";
+                        }
+                        bgimg = `url(\"${tmp_bgimg}\")`;
+                    }
+                    bgimg = bgimg.replace(/^\s*url\s*\(\s*\"/i, "lorahelper.pass_url(\"");
+
+                    card.setAttribute("oncontextmenu",
+                        `lorahelper.show_trigger_words(event, '${model_type}', '${model_path}', '${model_name}', ${bgimg}, '${active_tab_type}')`
+                    );
+                    let touch_icon = card.querySelector(".lorahelp-touch-icon");
+                    if(lorahelper.is_nullptr(touch_icon)){
+                        touch_icon = document.createElement("div");
+                        touch_icon.classList.add("lorahelp-touch-icon");
+                        let inside_span = document.createElement("span");
+                        touch_icon.appendChild(inside_span);
+                        card.appendChild(touch_icon);
+                    }
+                    let icon_label = touch_icon.querySelector("span");
+                    icon_label.innerHTML = "...";
+                    touch_icon.setAttribute("onclick",
+                        `lorahelper.show_trigger_words(event, '${model_type}', '${model_path}', '${model_name}', ${bgimg}, '${active_tab_type}')`
+                    );
+                    touch_icon.setAttribute("ontouchstart",
+                        `lorahelper.show_trigger_words(event, '${model_type}', '${model_path}', '${model_name}', ${bgimg}, '${active_tab_type}')`
+                    );
+                    if(lorahelper.isTouchDevice() || lorahelper.settings.touch_mode()){
+                        touch_icon.style.display = "block";
+                    }else{
+                        touch_icon.style.display = "none";
+                    }
+                    ++i;
+                }
+                if(tab_counter == 0){
+                    for(let node_ptr = lorahelper.gradioApp().getElementById(extra_network_id);
+                        !lorahelper.is_empty(node_ptr?.parentElement?.parentNode);
+                        node_ptr = node_ptr?.parentElement
+                    ){
+                        node_id = (node_ptr||{getAttribute:()=>null}).getAttribute("id");
+                        if(lorahelper.is_empty(node_id)) continue;
+                        if ((node_id||"").indexOf("extra_network") >= 0){
+                            extra_network_parent = node_ptr;
+                            break;
+                        }
+                    }
+                    if(!lorahelper.is_empty(extra_network_parent)){
+                        if (lorahelper.is_empty(lorahelper.extra_network_panel_list)){
+                            lorahelper.extra_network_panel_list = [];
+                            lorahelper.extra_network_observer_list = [];
+                        }
+                        if ((lorahelper.extra_network_panel_list?.length||-1) <= 0){
+                            lorahelper.extra_network_panel_list = [];
+                            lorahelper.extra_network_observer_list = [];
+                        }
+                        let observer_id = lorahelper.extra_network_panel_list.indexOf(extra_network_parent);
+                        if(observer_id < 0){
+                            lorahelper.extra_network_panel_list.push(extra_network_parent);
+                            observer_id = lorahelper.extra_network_panel_list.indexOf(extra_network_parent);
+                            let lorahelper_observer = new MutationObserver((function(self){
+                                return mutations => {
+                                    if(lorahelper.extra_network_observer_list[self.id].working) return;
+                                    lorahelper.extra_network_observer_list[self.id].working = true;
+                                    lorahelper.update_card_for_lorahelper();
+                                    lorahelper.extra_network_observer_list[self.id].working = false;
+                                }
+                            })({
+                                id: observer_id,
+                                tab_prefix: tab_prefix
+                            }) );
+                            lorahelper.extra_network_observer_list.push(lorahelper_observer);
+                            lorahelper_observer.observe(extra_network_parent, {
+                                characterData: true,
+                                childList: true,
+                                subtree: true,
+                                attributes: true
+                            });
+                        }
+                    }
+                }
+                ++tab_counter;
+            }
+        }
+    }
+    
+    //update when tab is changed
+    let all_tabs = lorahelper.gradioApp().querySelectorAll(".tab-nav, .ant-tabs");
+    let tab_search = window.setInterval(function(){
+        if(lorahelper.gradioApp().querySelectorAll(".tab-nav, .ant-tabs").length <= 0 && lorahelper.gradioApp().querySelectorAll(".tabs").length <= 0){
+            return;
+        }
+        all_tabs = lorahelper.gradioApp().querySelectorAll(".tab-nav, .ant-tabs");
+        window.clearInterval(tab_search);
+        if(all_tabs.length <= 0){
+            //support for old version
+            all_tabs = lorahelper.gradioApp().querySelectorAll(".tabs");
+            for (let tab_parent of all_tabs) {
+                all_tab_items = tab_parent.childNodes[0].querySelectorAll("button, .ant-tabs-tab-btn");
+                for (let the_tab of all_tab_items) {
+                    the_tab.addEventListener('click', function(ev) {
+                        (the_tab.querySelector("button, .ant-tabs-tab-btn")||{addEventListener:()=>false}).addEventListener('click', function(ev) {
+                            update_card_for_lorahelper();
+                            return true;
+                        }, false);
+                        update_card_for_lorahelper();
+                        return true;
+                    }, false);
+                }
+            }
+        }else{
+            for (let the_tab of all_tabs) {
+                (the_tab.querySelector("button, .ant-tabs-tab-btn")||{addEventListener:()=>false}).addEventListener('click', function(ev) {
+                    update_card_for_lorahelper();
+                    return true;
+                }, false);
+                the_tab.addEventListener('click', function(ev) {
+                    update_card_for_lorahelper();
+                    return true;
+                }, false);
+            }
+        }
+    },20);
+
+    lorahelper.simpleedit_group_extra_enabled = lorahelper.gradioApp().querySelector("#lorahelp_simpleedit_group_extra_enabled input");
+    lorahelper.simpleedit_group_extra_body = lorahelper.gradioApp().querySelector("#lorahelp_simpleedit_group_extra_body");
+    lorahelper.simpleedit_group_neg_enabled = lorahelper.gradioApp().querySelector("#lorahelp_simpleedit_group_neg_enabled input");
+    lorahelper.simpleedit_group_neg_body= lorahelper.gradioApp().querySelector("#lorahelp_simpleedit_group_neg_body");
+    lorahelper.sorting_group_enabled = lorahelper.gradioApp().querySelector("#lorahelp_sorting_group_enabled input");
+    lorahelper.sorting_group_body = lorahelper.gradioApp().querySelector("#lorahelp_sorting_group");
+    lorahelper.update_simpleedit_group = function(){
+        if(lorahelper.simpleedit_group_extra_enabled.checked)
+            lorahelper.simpleedit_group_extra_body.style.display="block";
+        else
+            lorahelper.simpleedit_group_extra_body.style.display="none";
+        if(lorahelper.simpleedit_group_neg_enabled.checked)
+            lorahelper.simpleedit_group_neg_body.style.display="block";
+        else
+            lorahelper.simpleedit_group_neg_body.style.display="none";
+        if(lorahelper.sorting_group_enabled.checked)
+            lorahelper.sorting_group_body.style.display="block";
+        else
+            lorahelper.sorting_group_body.style.display="none";
+        return true;
+    }
+
+    lorahelper.simpleedit_group_extra_enabled.addEventListener('click', lorahelper.update_simpleedit_group, false);
+    lorahelper.simpleedit_group_neg_enabled.addEventListener('click', lorahelper.update_simpleedit_group, false);
+    lorahelper.sorting_group_enabled.addEventListener('click', lorahelper.update_simpleedit_group, false);
+    lorahelper.update_simpleedit_group();
+    //update when tab refreshed
+    lorahelper.gradioApp().getElementById("txt2img_extra_refresh").addEventListener('click', function(ev) {
+        update_card_for_lorahelper();
+        return true;
+    }, false);
+    lorahelper.gradioApp().getElementById("img2img_extra_refresh").addEventListener('click', function(ev) {
+        update_card_for_lorahelper();
+        return true;
+    }, false);
+
+    //link dataframe edit actions
+    for (const [key, value] of Object.entries(lorahelper.edit_action_list)) {
+        var the_btn = lorahelper.gradioApp().getElementById(value+"_btn");
+        the_btn.setAttribute("onclick", `lorahelper.dataframe_edit_action(event, '${key}')`);
+        the_btn.setAttribute("title", key);
+    }
+    //check if Browser support paste from clipboard
+    if (typeof(lorahelper.noop_func) !== typeof(navigator.clipboard.readText)){
+        lorahelper.gradioApp().getElementById("lorahelp_dataedit_paste_btn").style.display = "none";
+        lorahelper.gradioApp().getElementById("lorahelp_dataedit_paste_append_btn").style.display = "none";
+    }
+
+    //update when start webui
+    update_card_for_lorahelper();
+    lorahelper.dataframe_focus_check();
+    lorahelper.update_card_for_lorahelper = update_card_for_lorahelper;
+});

File diff suppressed because it is too large
+ 44 - 0
javascript/lorahelp_otherdata.js


+ 19 - 0
javascript/module_template.js

@@ -0,0 +1,19 @@
+(function(){
+
+function module_init() {
+    console.log("[lora-prompt-tool] load module template module");
+	console.log("Hello, World!\n");
+	//insert code here
+}
+let module_loadded = false;
+document.addEventListener("DOMContentLoaded", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+document.addEventListener("load", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+})();

+ 29 - 0
javascript/settings.js

@@ -0,0 +1,29 @@
+(function(){
+
+function module_init() {
+    console.log("[lora-prompt-tool] load settings module");
+
+    lorahelper.settings = {};
+
+    function get_boolean(ele_id){
+        const element = lorahelper.gradioApp().querySelector(`#${ele_id} input`);
+        if(lorahelper.is_nullptr(element)) return false;
+        if(lorahelper.is_nullptr(element.checked)) return false;
+        return !!element.checked;
+    }
+    
+    lorahelper.settings.is_debug = ()=>get_boolean("lorahelp_js_debug_logging");
+    lorahelper.settings.touch_mode = ()=>get_boolean("lorahelp_js_touch_mode");
+}
+let module_loadded = false;
+document.addEventListener("DOMContentLoaded", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+document.addEventListener("load", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+})();

+ 302 - 0
javascript/utilitys.js

@@ -0,0 +1,302 @@
+(function(){
+function module_init() {
+    console.log("[lora-prompt-tool] load utilitys module");
+    lorahelper.noop_func = ()=>{};
+    lorahelper.pointInRect = (rect, {x, y}) => (
+        (x > rect.left && x < rect.right) && (y > rect.top && y < rect.bottom)
+      );
+    
+    function load_json_number(input){
+        let cvt = parseFloat(input)
+        if(Number.isNaN(cvt)) return 0;
+        return cvt;
+    }
+    
+    function load_boolean_flag(flag){
+        let flag_str = `${flag}`;
+        flag_str = flag_str.toLowerCase().trim();
+        if(['yes','true','是','y','t'].includes(flag_str)){
+            return 1;
+        }
+        const flag_num = parseInt(load_json_number(flag_str))
+        if (flag_num != 0){
+            return 1;
+        }
+        return "";
+    }
+    
+    function debug(...msg) {
+        if (lorahelper.settings.is_debug()) console.log(`[${lorahelper.lorahelp_extension_name}]`,...msg);
+    }
+    
+    function is_nullptr(obj) {
+        try {
+            if (typeof(obj) === "undefined") return true;
+            if (obj == undefined) return true;
+            if (obj == null) return true;
+        } catch (error) {
+            return true;
+        }
+        return false;
+    }
+    
+    function is_empty(str) {
+        if (is_nullptr(str)) return true;
+        if ((''+str).trim() === '') return true;
+        return false;
+    }
+
+    function convert_file_path_to_url(path){
+        let prefix = "file=";
+        let path_to_url = path.replaceAll('\\', '/');
+        return prefix+path_to_url;
+    }
+    function img_node_str(path){
+        return `<img src='${convert_file_path_to_url(path)}' style="width:24px"/>`;
+    }
+    
+    function pass_url(url_name){
+        return url_name;
+    }
+    
+    function build_hyper_cmd(mode, model, weight, param){
+        let par_str = param.trim();
+        if(par_str.charAt(0) !== ':' && par_str !== ""){
+            par_str = ":" + par_str;
+        }
+        switch (mode) {
+            case "ti":
+                if(Math.abs(parseFloat(weight) - 1) > 1e-8)
+                    return `(${model}:${weight})`;
+                return model;
+            case "hyper":
+                return `<hypernet:${model}:${weight}${par_str}>`;
+            case "ckp":
+                return;
+            case "lora":
+            case "lyco":
+            default:
+                return `<${mode}:${model}:${weight}${par_str}>`;
+        }
+    }
+
+    function unescape_string(input_string){
+        let result = '';
+        const unicode_list = ['u','x'];
+        for(var i=0; i<input_string.length; ++i){
+            const current_char = input_string.charAt(i);
+            if(current_char == '\\'){
+                ++i;
+                if (i >= input_string.length) break;
+                const string_body = input_string.charAt(i);
+                if(unicode_list.includes(string_body.toLowerCase())){
+                    result += `${current_char}${string_body}`;
+                } else {
+                    let char_added = false;
+                    try {
+                        const unescaped = JSON.parse(`"${current_char}${string_body}"`);
+                        if (unescaped){
+                            result += unescaped;
+                            char_added = true;
+                        }
+                    } catch (error) {
+                        
+                    }
+                    if(!char_added){
+                        result += string_body;
+                    }
+                }
+            } else {
+                result += current_char;
+            }
+        }
+        return JSON.parse(JSON.stringify(result).replace(/\\\\/g,"\\"));
+    }
+    
+    const default_top_index = 10001;
+    var my_index = default_top_index;
+    function sendontop(ele_id) {
+        let element = ele_id;
+        if (typeof(ele_id)===typeof("string")) {
+            element = document.getElementById(ele_id);
+        }
+        element.classList.add("sendontop");
+        element.style.zIndex = ++my_index;
+    }
+    function resetElementLayer() {
+        const all_top_element = document.querySelectorAll(".sendontop");
+        my_index = default_top_index;
+        for(let ele of all_top_element){
+            ele.style.zIndex = "unset";
+        }
+    }
+
+    async function google_translate(text, options = {}) {
+        const defaultTranslateOptions = {
+            client: 'gtx',
+            from: 'auto',
+            to: 'en',
+            hl: 'en',
+            tld: 'com',
+        };
+        function sM(a) {
+            let e = [];
+            let f = 0;
+            for (let g = 0; g < a.length; g++) {
+                let l = a.charCodeAt(g)
+                128 > l
+                ? (e[f++] = l)
+                : (2048 > l
+                    ? (e[f++] = (l >> 6) | 192)
+                    : (55296 == (l & 64512) &&
+                        g + 1 < a.length &&
+                        56320 == (a.charCodeAt(g + 1) & 64512)
+                        ? ((l = 65536 + ((l & 1023) << 10) + (a.charCodeAt(++g) & 1023)),
+                            (e[f++] = (l >> 18) | 240),
+                            (e[f++] = ((l >> 12) & 63) | 128))
+                        : (e[f++] = (l >> 12) | 224),
+                        (e[f++] = ((l >> 6) & 63) | 128)),
+                    (e[f++] = (l & 63) | 128));
+            }
+            let a_ = 0
+            for (f = 0; f < e.length; f++) {
+                a_ += e[f];
+                a_ = xr(a_, "+-a^+6");
+            }
+            a_ = xr(a_, "+-3^+b+-f");
+            a_ ^= 0;
+            0 > a_ && (a_ = (a_ & 2147483647) + 2147483648);
+            a_ %= 1e6;
+            return a_.toString() + "." + a_.toString();
+        }
+        function xr(a, b) {
+            for (let c = 0; c < b.length - 2; c += 3) {
+                let d = b.charAt(c + 2);
+                d = "a" <= d ? d.charCodeAt(0) - 87 : Number(d);
+                d = "+" == b.charAt(c + 1) ? a >>> d : a << d;
+                a = "+" == b.charAt(c) ? a + d : a ^ d;
+            }
+            return a;
+        }
+        function normaliseResponse(body, raw = false) {
+            const result = {
+                text: "",
+                pronunciation: "",
+                from: {
+                    language: {
+                        didYouMean: false,
+                        iso: ""
+                    },
+                    text: {
+                        autoCorrected: false,
+                        value: "",
+                        didYouMean: false
+                    }
+                }
+            };
+            body[0].forEach(obj => {
+                if (obj[0]) {
+                    result.text += obj[0];
+                } else if (obj[2]) {
+                    result.pronunciation += obj[2];
+                }
+            })
+            if (body[2] === body[8][0][0]) {
+                result.from.language.iso = body[2];
+            } else {
+                result.from.language.didYouMean = true;
+                result.from.language.iso = body[8][0][0];
+            }
+            if (body[7] && body[7][0]) {
+                let str = body[7][0];
+    
+                str = str.replace(/<b><i>/g, "[");
+                str = str.replace(/<\/i><\/b>/g, "]");
+    
+                result.from.text.value = str;
+    
+                if (body[7][5] === true) {
+                    result.from.text.autoCorrected = true;
+                } else {
+                    result.from.text.didYouMean = true;
+                }
+            }
+    
+            if (raw) {
+                result.raw = body;
+            }
+    
+            return result;
+        }
+    
+        function generateRequestUrl(text, options) {
+          const translateOptions = { ...defaultTranslateOptions, ...options }
+    
+          const queryParams = {
+            client: translateOptions.client,
+            sl: translateOptions.from,
+            tl: translateOptions.to,
+            hl: translateOptions.hl,
+            ie: "UTF-8",
+            oe: "UTF-8",
+            otf: "1",
+            ssel: "0",
+            tsel: "0",
+            kc: "7",
+            q: text,
+            tk: sM(text)
+          }
+          const searchParams = new URLSearchParams(queryParams);
+          ["at", "bd", "ex", "ld", "md", "qca", "rw", "rm", "ss", "t"].forEach(l =>
+            searchParams.append("dt", l)
+          )
+    
+          return `https://translate.google.${translateOptions.tld}/translate_a/single?${searchParams}`;
+        }
+        const translateUrl = generateRequestUrl(text, options);
+        const response = await lorahelper.build_cors_request(translateUrl);
+    
+        const body = await JSON.parse(response);
+        return normaliseResponse(body, options.raw);
+    }
+
+    function isTouchDevice() {
+        return (('ontouchstart' in window) ||
+            (navigator.maxTouchPoints > 0) ||
+            (navigator.msMaxTouchPoints > 0));
+    }
+
+    lorahelper.gradioApp = function() {
+        const elems = document.getElementsByTagName('gradio-app');
+        const elem = elems.length == 0 ? document : elems[0];
+    
+        if (elem !== document) elem.getElementById = function (id) { return document.getElementById(id); }
+        return elem.shadowRoot ? elem.shadowRoot : elem;
+    };
+    lorahelper.debug = debug;
+    lorahelper.load_json_number = load_json_number;
+    lorahelper.load_boolean_flag = load_boolean_flag;
+    lorahelper.is_nullptr = is_nullptr;
+    lorahelper.is_empty = is_empty;
+    lorahelper.convert_file_path_to_url = convert_file_path_to_url;
+    lorahelper.img_node_str = img_node_str;
+    lorahelper.pass_url = pass_url;
+    lorahelper.unescape_string = unescape_string;
+    lorahelper.google_translate = google_translate;
+    lorahelper.isTouchDevice = isTouchDevice;
+    lorahelper.sendontop = sendontop;
+    lorahelper.resetElementLayer = resetElementLayer;
+    lorahelper.build_hyper_cmd = build_hyper_cmd;
+}
+let module_loadded = false;
+document.addEventListener("DOMContentLoaded", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+document.addEventListener("load", () => {
+    if (module_loadded) return;
+    module_loadded = true;
+    module_init();
+});
+})();

+ 164 - 0
readme/Artboard.svg

@@ -0,0 +1,164 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
+	 width="270.25px" height="30px" viewBox="0 0 270.25 30" enable-background="new 0 0 270.25 30" xml:space="preserve">
+<path id="Rectangle" fill="#FF5E5B" d="M9.695,0h250.859c5.354,0,9.695,3.582,9.695,8v14c0,4.418-4.342,8-9.695,8H9.695
+	C4.34,30,0,26.418,0,22V8C0,3.582,4.34,0,9.695,0z"/>
+<path id="SupportmeonKo-f" fill="#FFFFFF" d="M66.2,19.141c-0.672,0-1.27-0.084-1.792-0.252c-0.523-0.169-1.013-0.453-1.47-0.854
+	c-0.252-0.224-0.378-0.472-0.378-0.742c0-0.215,0.079-0.403,0.238-0.567c0.159-0.163,0.35-0.244,0.574-0.244
+	c0.177,0,0.336,0.056,0.476,0.168c0.373,0.308,0.737,0.531,1.092,0.672c0.354,0.14,0.775,0.21,1.26,0.21
+	c0.522,0,0.973-0.117,1.351-0.351c0.378-0.232,0.567-0.522,0.567-0.867c0-0.42-0.187-0.75-0.56-0.987
+	c-0.374-0.238-0.966-0.418-1.778-0.539c-2.044-0.299-3.066-1.251-3.066-2.856c0-0.588,0.154-1.099,0.462-1.533
+	c0.308-0.434,0.728-0.765,1.26-0.994c0.532-0.229,1.125-0.343,1.778-0.343c0.588,0,1.141,0.088,1.659,0.266
+	c0.518,0.177,0.95,0.411,1.295,0.7c0.271,0.215,0.406,0.462,0.406,0.742c0,0.214-0.08,0.404-0.238,0.567
+	c-0.159,0.164-0.345,0.245-0.56,0.245c-0.14,0-0.266-0.042-0.378-0.126c-0.243-0.196-0.581-0.376-1.015-0.539
+	c-0.434-0.164-0.823-0.245-1.169-0.245c-0.588,0-1.043,0.11-1.365,0.329c-0.322,0.219-0.483,0.506-0.483,0.861
+	c0,0.401,0.166,0.705,0.497,0.91c0.332,0.206,0.852,0.374,1.561,0.504c0.803,0.14,1.444,0.32,1.925,0.539
+	c0.48,0.219,0.842,0.518,1.085,0.896s0.364,0.88,0.364,1.505c0,0.588-0.166,1.104-0.497,1.547c-0.331,0.443-0.772,0.784-1.323,1.022
+	S66.834,19.141,66.2,19.141z M76.826,11.51c0.243,0,0.443,0.082,0.602,0.245c0.158,0.164,0.238,0.366,0.238,0.609v3.556
+	c0,1.008-0.278,1.797-0.833,2.366s-1.346,0.854-2.373,0.854s-1.815-0.285-2.366-0.854c-0.551-0.569-0.826-1.358-0.826-2.366v-3.556
+	c0-0.243,0.079-0.446,0.238-0.609c0.159-0.163,0.359-0.245,0.602-0.245s0.443,0.082,0.602,0.245
+	c0.159,0.164,0.238,0.366,0.238,0.609v3.556c0,0.569,0.126,0.992,0.378,1.268s0.63,0.412,1.134,0.412
+	c0.513,0,0.896-0.137,1.148-0.412s0.378-0.698,0.378-1.268v-3.556c0-0.243,0.08-0.446,0.238-0.609
+	C76.383,11.592,76.583,11.51,76.826,11.51z M83.364,11.37c0.644,0,1.228,0.166,1.75,0.497c0.523,0.331,0.936,0.791,1.239,1.379
+	s0.455,1.255,0.455,2.002c0,0.746-0.149,1.416-0.448,2.009c-0.298,0.593-0.707,1.055-1.225,1.386
+	c-0.518,0.332-1.089,0.498-1.715,0.498c-0.448,0-0.87-0.092-1.267-0.273c-0.396-0.182-0.726-0.404-0.987-0.665v2.743
+	c0,0.243-0.08,0.446-0.238,0.609c-0.159,0.164-0.359,0.245-0.602,0.245s-0.443-0.079-0.602-0.237
+	c-0.159-0.159-0.238-0.364-0.238-0.617v-8.581c0-0.243,0.08-0.446,0.238-0.609c0.159-0.163,0.359-0.245,0.602-0.245
+	s0.443,0.082,0.602,0.245c0.158,0.164,0.238,0.366,0.238,0.609v0.056c0.224-0.28,0.537-0.525,0.938-0.735S82.925,11.37,83.364,11.37
+	z M83.154,17.6c0.598,0,1.087-0.224,1.47-0.672c0.383-0.447,0.574-1.008,0.574-1.68s-0.189-1.229-0.567-1.673
+	s-0.87-0.665-1.477-0.665c-0.606,0-1.101,0.222-1.484,0.665s-0.574,1.001-0.574,1.673s0.191,1.232,0.574,1.68
+	C82.053,17.376,82.547,17.6,83.154,17.6z M92.086,11.37c0.644,0,1.228,0.166,1.75,0.497c0.523,0.331,0.936,0.791,1.239,1.379
+	c0.303,0.588,0.455,1.255,0.455,2.002c0,0.746-0.149,1.416-0.448,2.009s-0.707,1.055-1.225,1.386
+	c-0.518,0.332-1.09,0.498-1.715,0.498c-0.448,0-0.871-0.092-1.267-0.273s-0.726-0.404-0.987-0.665v2.743
+	c0,0.243-0.08,0.446-0.238,0.609c-0.159,0.164-0.359,0.245-0.602,0.245s-0.443-0.079-0.602-0.237
+	c-0.159-0.159-0.238-0.364-0.238-0.617v-8.581c0-0.243,0.079-0.446,0.238-0.609c0.159-0.163,0.359-0.245,0.602-0.245
+	s0.443,0.082,0.602,0.245c0.159,0.164,0.238,0.366,0.238,0.609v0.056c0.224-0.28,0.537-0.525,0.938-0.735S91.647,11.37,92.086,11.37
+	z M91.876,17.6c0.597,0,1.087-0.224,1.47-0.672c0.382-0.447,0.574-1.008,0.574-1.68s-0.189-1.229-0.567-1.673
+	s-0.87-0.665-1.477-0.665c-0.606,0-1.101,0.222-1.484,0.665s-0.574,1.001-0.574,1.673s0.191,1.232,0.574,1.68
+	C90.775,17.376,91.27,17.6,91.876,17.6z M104.126,15.262c0,0.747-0.168,1.416-0.504,2.009c-0.336,0.592-0.796,1.052-1.379,1.379
+	c-0.583,0.326-1.225,0.49-1.925,0.49c-0.709,0-1.353-0.164-1.932-0.49c-0.579-0.327-1.036-0.787-1.372-1.379
+	c-0.336-0.594-0.504-1.263-0.504-2.009c0-0.747,0.168-1.417,0.504-2.009s0.793-1.055,1.372-1.386
+	c0.579-0.332,1.223-0.497,1.932-0.497c0.7,0,1.342,0.166,1.925,0.497c0.583,0.331,1.043,0.793,1.379,1.386
+	S104.126,14.515,104.126,15.262z M102.446,15.262c0-0.458-0.096-0.866-0.287-1.225c-0.191-0.359-0.448-0.637-0.77-0.833
+	c-0.322-0.196-0.679-0.294-1.071-0.294s-0.749,0.098-1.071,0.294c-0.322,0.196-0.579,0.474-0.77,0.833s-0.287,0.768-0.287,1.225
+	c0,0.457,0.096,0.863,0.287,1.218c0.191,0.354,0.448,0.629,0.77,0.826c0.322,0.195,0.679,0.293,1.071,0.293s0.749-0.098,1.071-0.293
+	c0.322-0.197,0.579-0.473,0.77-0.826C102.35,16.125,102.446,15.719,102.446,15.262z M109.418,11.37c0.28,0,0.516,0.079,0.707,0.238
+	s0.287,0.345,0.287,0.56c0,0.29-0.075,0.506-0.224,0.651c-0.149,0.145-0.327,0.217-0.532,0.217c-0.14,0-0.298-0.033-0.476-0.098
+	c-0.028-0.009-0.091-0.028-0.189-0.056c-0.098-0.028-0.203-0.042-0.315-0.042c-0.243,0-0.476,0.075-0.7,0.224
+	s-0.408,0.375-0.553,0.679c-0.145,0.303-0.217,0.665-0.217,1.085v3.318c0,0.242-0.08,0.445-0.238,0.608
+	C106.81,18.918,106.609,19,106.366,19s-0.443-0.082-0.602-0.245s-0.238-0.366-0.238-0.608v-5.782c0-0.243,0.08-0.446,0.238-0.609
+	c0.159-0.163,0.359-0.245,0.602-0.245s0.443,0.082,0.602,0.245c0.159,0.164,0.238,0.366,0.238,0.609v0.182
+	c0.215-0.383,0.522-0.674,0.924-0.875S108.96,11.37,109.418,11.37z M115.214,17.418c0.131,0,0.25,0.063,0.356,0.189
+	c0.107,0.125,0.162,0.291,0.162,0.496c0,0.252-0.139,0.465-0.414,0.638S114.733,19,114.389,19c-0.579,0-1.066-0.123-1.464-0.371
+	c-0.396-0.247-0.595-0.772-0.595-1.574V13.19h-0.644c-0.224,0-0.411-0.075-0.56-0.224s-0.224-0.336-0.224-0.56
+	c0-0.215,0.075-0.395,0.224-0.539c0.149-0.145,0.336-0.217,0.56-0.217h0.644v-0.896c0-0.243,0.082-0.445,0.245-0.609
+	s0.366-0.245,0.608-0.245c0.234,0,0.43,0.082,0.588,0.245c0.159,0.164,0.238,0.366,0.238,0.609v0.896h0.994
+	c0.225,0,0.41,0.075,0.561,0.224c0.148,0.149,0.224,0.336,0.224,0.56c0,0.214-0.075,0.394-0.224,0.539
+	c-0.15,0.145-0.336,0.217-0.561,0.217h-0.994v3.794c0,0.195,0.052,0.338,0.154,0.427s0.242,0.133,0.42,0.133
+	c0.074,0,0.178-0.019,0.309-0.056C115.004,17.441,115.111,17.418,115.214,17.418z M129.887,11.37c0.924,0,1.563,0.282,1.918,0.847
+	c0.354,0.565,0.531,1.347,0.531,2.345v3.584c0,0.242-0.079,0.445-0.238,0.608c-0.158,0.163-0.359,0.245-0.602,0.245
+	s-0.443-0.082-0.602-0.245c-0.159-0.163-0.238-0.366-0.238-0.608v-3.584c0-0.513-0.101-0.917-0.301-1.211
+	c-0.201-0.294-0.553-0.441-1.058-0.441c-0.522,0-0.931,0.156-1.226,0.469c-0.293,0.313-0.44,0.707-0.44,1.183v3.584
+	c0,0.242-0.079,0.445-0.237,0.608c-0.159,0.163-0.359,0.245-0.603,0.245s-0.443-0.082-0.603-0.245
+	c-0.158-0.163-0.237-0.366-0.237-0.608v-3.584c0-0.513-0.101-0.917-0.302-1.211c-0.2-0.294-0.553-0.441-1.057-0.441
+	c-0.522,0-0.931,0.156-1.225,0.469s-0.441,0.707-0.441,1.183v3.584c0,0.242-0.079,0.445-0.238,0.608
+	C122.531,18.918,122.33,19,122.088,19s-0.443-0.082-0.602-0.245c-0.159-0.163-0.238-0.366-0.238-0.608v-5.782
+	c0-0.243,0.079-0.446,0.238-0.609c0.158-0.163,0.359-0.245,0.602-0.245s0.443,0.082,0.602,0.245
+	c0.159,0.164,0.238,0.366,0.238,0.609v0.224c0.252-0.336,0.572-0.623,0.959-0.861c0.388-0.238,0.819-0.357,1.295-0.357
+	c1.176,0,1.928,0.513,2.254,1.54c0.215-0.392,0.539-0.747,0.974-1.064C128.843,11.529,129.336,11.37,129.887,11.37z M140.876,15.08
+	c-0.009,0.224-0.099,0.406-0.267,0.546c-0.168,0.14-0.363,0.21-0.588,0.21h-4.619c0.111,0.551,0.368,0.982,0.77,1.295
+	s0.854,0.469,1.357,0.469c0.383,0,0.682-0.035,0.896-0.104c0.215-0.07,0.385-0.145,0.512-0.224c0.125-0.08,0.212-0.133,0.258-0.162
+	c0.168-0.084,0.327-0.125,0.477-0.125c0.196,0,0.364,0.07,0.504,0.209c0.141,0.141,0.211,0.304,0.211,0.49
+	c0,0.252-0.131,0.48-0.393,0.687c-0.262,0.214-0.611,0.396-1.051,0.546c-0.438,0.149-0.881,0.225-1.33,0.225
+	c-0.783,0-1.467-0.164-2.051-0.49c-0.583-0.327-1.033-0.777-1.351-1.352s-0.476-1.221-0.476-1.939c0-0.803,0.168-1.507,0.504-2.114
+	c0.336-0.607,0.779-1.071,1.33-1.393s1.139-0.483,1.764-0.483c0.616,0,1.197,0.168,1.743,0.504s0.981,0.789,1.31,1.358
+	C140.713,13.801,140.876,14.417,140.876,15.08z M137.334,12.91c-1.082,0-1.723,0.508-1.918,1.526h3.668v-0.098
+	c-0.037-0.392-0.229-0.728-0.574-1.008C138.164,13.05,137.772,12.91,137.334,12.91z M153.393,15.262
+	c0,0.747-0.168,1.416-0.504,2.009c-0.336,0.592-0.797,1.052-1.38,1.379c-0.583,0.326-1.225,0.49-1.925,0.49
+	c-0.709,0-1.354-0.164-1.932-0.49c-0.579-0.327-1.036-0.787-1.373-1.379c-0.336-0.594-0.504-1.263-0.504-2.009
+	c0-0.747,0.168-1.417,0.504-2.009c0.337-0.593,0.794-1.055,1.373-1.386c0.578-0.332,1.223-0.497,1.932-0.497
+	c0.7,0,1.342,0.166,1.925,0.497c0.583,0.331,1.044,0.793,1.38,1.386S153.393,14.515,153.393,15.262z M151.712,15.262
+	c0-0.458-0.096-0.866-0.287-1.225c-0.19-0.359-0.448-0.637-0.771-0.833c-0.321-0.196-0.678-0.294-1.07-0.294
+	s-0.749,0.098-1.07,0.294c-0.322,0.196-0.579,0.474-0.771,0.833s-0.287,0.768-0.287,1.225c0,0.457,0.096,0.863,0.287,1.218
+	c0.191,0.354,0.448,0.629,0.771,0.826c0.321,0.195,0.678,0.293,1.07,0.293s0.749-0.098,1.07-0.293
+	c0.322-0.197,0.58-0.473,0.771-0.826C151.616,16.125,151.712,15.719,151.712,15.262z M158.796,11.37c0.952,0,1.61,0.282,1.974,0.847
+	c0.364,0.565,0.547,1.347,0.547,2.345v3.584c0,0.242-0.08,0.445-0.238,0.608S160.719,19,160.477,19
+	c-0.243,0-0.443-0.082-0.603-0.245s-0.237-0.366-0.237-0.608v-3.584c0-0.513-0.107-0.917-0.322-1.211s-0.584-0.441-1.106-0.441
+	c-0.542,0-0.966,0.156-1.274,0.469c-0.308,0.313-0.461,0.707-0.461,1.183v3.584c0,0.242-0.08,0.445-0.238,0.608
+	c-0.159,0.163-0.359,0.245-0.603,0.245s-0.443-0.082-0.603-0.245c-0.158-0.163-0.237-0.366-0.237-0.608v-5.782
+	c0-0.243,0.079-0.446,0.237-0.609c0.159-0.163,0.359-0.245,0.603-0.245s0.443,0.082,0.603,0.245
+	c0.158,0.164,0.238,0.366,0.238,0.609v0.238c0.252-0.336,0.58-0.625,0.986-0.868S158.311,11.37,158.796,11.37z M174.7,17.544
+	c0.056,0.075,0.103,0.165,0.14,0.272s0.057,0.208,0.057,0.302c0,0.252-0.096,0.462-0.287,0.63S174.195,19,173.943,19
+	c-0.121,0-0.237-0.027-0.35-0.084c-0.111-0.057-0.205-0.135-0.279-0.238l-3.039-4.004l-1.33,1.274v2.198
+	c0,0.252-0.081,0.457-0.244,0.615c-0.164,0.159-0.376,0.238-0.637,0.238c-0.252,0-0.46-0.082-0.623-0.245
+	c-0.164-0.163-0.246-0.366-0.246-0.608v-8.092c0-0.243,0.084-0.446,0.252-0.609c0.169-0.163,0.383-0.245,0.645-0.245
+	c0.252,0,0.457,0.079,0.616,0.238s0.237,0.364,0.237,0.616v3.808l4.48-4.41c0.215-0.215,0.443-0.322,0.686-0.322
+	c0.215,0,0.397,0.089,0.547,0.266c0.148,0.177,0.224,0.364,0.224,0.56c0,0.196-0.084,0.378-0.252,0.546l-3.052,2.912L174.7,17.544z
+	 M183.422,15.262c0,0.747-0.168,1.416-0.504,2.009c-0.336,0.592-0.795,1.052-1.379,1.379c-0.584,0.326-1.225,0.49-1.926,0.49
+	c-0.709,0-1.353-0.164-1.932-0.49c-0.578-0.327-1.035-0.787-1.371-1.379c-0.336-0.594-0.504-1.263-0.504-2.009
+	c0-0.747,0.168-1.417,0.504-2.009s0.793-1.055,1.371-1.386c0.579-0.332,1.223-0.497,1.932-0.497c0.701,0,1.342,0.166,1.926,0.497
+	c0.584,0.331,1.043,0.793,1.379,1.386S183.422,14.515,183.422,15.262z M181.742,15.262c0-0.458-0.096-0.866-0.287-1.225
+	s-0.448-0.637-0.77-0.833c-0.322-0.196-0.68-0.294-1.072-0.294c-0.391,0-0.748,0.098-1.07,0.294
+	c-0.322,0.196-0.578,0.474-0.77,0.833s-0.287,0.768-0.287,1.225c0,0.457,0.096,0.863,0.287,1.218
+	c0.191,0.354,0.447,0.629,0.77,0.826c0.322,0.195,0.68,0.293,1.07,0.293c0.393,0,0.75-0.098,1.072-0.293
+	c0.321-0.197,0.578-0.473,0.77-0.826C181.646,16.125,181.742,15.719,181.742,15.262z M185.466,15.542
+	c-0.243,0-0.445-0.079-0.608-0.238c-0.164-0.159-0.246-0.359-0.246-0.602c0-0.233,0.082-0.43,0.246-0.588
+	c0.163-0.159,0.365-0.238,0.608-0.238h2.437c0.242,0,0.445,0.082,0.609,0.245c0.162,0.163,0.244,0.366,0.244,0.609
+	c0,0.233-0.082,0.427-0.244,0.581c-0.164,0.154-0.367,0.231-0.609,0.231H185.466z M193.964,10.124c-0.317,0-0.541,0.091-0.672,0.273
+	s-0.196,0.38-0.196,0.595v0.658h1.274c0.224,0,0.411,0.072,0.56,0.217c0.149,0.145,0.225,0.329,0.225,0.553
+	s-0.075,0.408-0.225,0.553c-0.148,0.145-0.336,0.217-0.56,0.217h-1.274v4.957c0,0.242-0.079,0.445-0.238,0.608
+	c-0.158,0.163-0.359,0.245-0.602,0.245s-0.443-0.082-0.602-0.245c-0.159-0.163-0.238-0.366-0.238-0.608V13.19h-0.756
+	c-0.225,0-0.41-0.072-0.561-0.217c-0.148-0.145-0.224-0.329-0.224-0.553s0.075-0.408,0.224-0.553
+	c0.15-0.145,0.336-0.217,0.561-0.217h0.756v-0.644c0-0.7,0.24-1.269,0.721-1.708c0.48-0.438,1.174-0.658,2.079-0.658
+	c0.346,0,0.646,0.07,0.903,0.21c0.256,0.14,0.385,0.354,0.385,0.644c0,0.224-0.065,0.406-0.195,0.546
+	c-0.131,0.14-0.29,0.21-0.477,0.21c-0.047,0-0.096-0.005-0.146-0.014c-0.052-0.009-0.105-0.019-0.162-0.028
+	C194.3,10.152,194.113,10.124,193.964,10.124z M197.786,18.146c0,0.242-0.079,0.445-0.238,0.608S197.188,19,196.945,19
+	c-0.242,0-0.443-0.082-0.602-0.245s-0.238-0.366-0.238-0.608v-5.782c0-0.243,0.08-0.446,0.238-0.609
+	c0.158-0.163,0.359-0.245,0.602-0.245c0.243,0,0.443,0.082,0.603,0.245c0.159,0.164,0.238,0.366,0.238,0.609V18.146z M196.932,10.6
+	c-0.316,0-0.541-0.051-0.672-0.154c-0.131-0.103-0.195-0.285-0.195-0.546V9.634c0-0.261,0.069-0.443,0.209-0.546
+	c0.141-0.103,0.365-0.154,0.672-0.154c0.327,0,0.557,0.051,0.687,0.154c0.131,0.103,0.196,0.285,0.196,0.546V9.9
+	c0,0.271-0.068,0.455-0.203,0.553C197.49,10.551,197.259,10.6,196.932,10.6z"/>
+<rect x="165.311" y="6.771" fill="#FF5E5B" width="35.439" height="15.84"/>
+<text transform="matrix(1 0 0 1 167.2363 19.2617)" fill="#FFFFFF" font-family="'AdobeFanHeitiStd-Bold-B5pc-H'" font-size="12">buy me a coffee</text>
+<g>
+	<path fill="#FFFFFF" d="M44.444,17.218c0.41-1.435-0.268-2.3-0.972-2.605c-0.3-0.13-0.628-0.18-0.961-0.151
+		c0.062-0.802,0.036-1.324,0.035-1.334c0-2.369-3.712-4.226-8.451-4.226c-4.739,0-8.45,1.857-8.45,4.206
+		c-0.008,0.151-0.174,3.735,1.606,6.622l-0.013,0.009c0.016,0.024,0.033,0.048,0.05,0.073c-1.887,0.669-2.92,1.592-2.92,2.619
+		c0,1.763,3.463,3.636,9.88,3.636s9.88-1.873,9.88-3.636c0-1.411-2.146-2.34-3.188-2.707c0.079-0.129,0.156-0.261,0.231-0.4
+		C43.487,19.351,44.217,18.014,44.444,17.218z M43.362,22.43c0,1.356-3.742,2.866-9.112,2.866s-9.112-1.51-9.112-2.866
+		c0-0.69,0.979-1.422,2.625-1.968c1.302,1.547,3.295,2.274,6.19,2.274h0.25c2.929,0,4.998-0.776,6.299-2.364
+		c0.025,0.015,0.051,0.028,0.08,0.039C42.245,20.979,43.362,21.79,43.362,22.43z M40.604,18.756
+		c-0.106,0.207-0.212,0.396-0.323,0.576c-0.019,0.031-0.031,0.063-0.041,0.097c-1.122,1.729-3.042,2.54-6.037,2.54h-0.25
+		c-2.976,0-4.886-0.814-6.005-2.554c-0.009-0.028-0.021-0.057-0.037-0.083c-1.657-2.679-1.5-6.15-1.497-6.205
+		c0-1.873,3.518-3.457,7.682-3.458c4.164,0.001,7.682,1.585,7.683,3.478c0,0.007,0.035,0.731-0.081,1.759
+		c-0.015,0.132,0.039,0.263,0.144,0.345c0.104,0.082,0.245,0.104,0.369,0.059c0.328-0.12,0.667-0.117,0.956,0.008
+		c0.213,0.092,0.882,0.487,0.539,1.688c-0.293,1.027-1.119,1.549-2.453,1.549c-0.088,0-0.18-0.002-0.288-0.008
+		C40.818,18.54,40.673,18.621,40.604,18.756z"/>
+	<path fill="#FFFFFF" d="M41.77,17.75c-0.127,0-0.246-0.063-0.318-0.168c-0.072-0.105-0.086-0.24-0.039-0.359
+		c0.095-0.235,0.169-0.497,0.221-0.777c0.015-0.077,0.053-0.148,0.11-0.204c0.224-0.218,0.567-0.29,0.831-0.177
+		c0.249,0.108,0.486,0.416,0.339,0.928c-0.08,0.28-0.334,0.752-1.142,0.758C41.771,17.75,41.771,17.75,41.77,17.75z"/>
+	<path fill="#FFFFFF" d="M33.982,10.566c-3.797,0-6.875,1.148-6.875,2.565s3.079,2.566,6.875,2.566c3.797,0,6.875-1.149,6.875-2.566
+		S37.779,10.566,33.982,10.566z M34.09,14.912l-2.975-1.89c-0.269-0.171-0.417-0.381-0.417-0.591c0-0.209,0.148-0.419,0.417-0.591
+		c0.199-0.126,0.458-0.19,0.77-0.19c0.512,0,1.123,0.176,1.633,0.471l0.557,0.322l0.557-0.322c0.511-0.294,1.122-0.471,1.634-0.471
+		c0.312,0,0.571,0.064,0.77,0.191c0.269,0.17,0.417,0.381,0.417,0.59c0,0.21-0.148,0.42-0.417,0.591l-2.954,1.881
+		c-0.001,0-0.003,0-0.007,0L34.09,14.912z"/>
+	<path fill="#FFFFFF" d="M35.38,7.834c-0.087,0-0.175-0.03-0.247-0.091c-0.4-0.335-0.962-1.225-0.228-2.188
+		c0.159-0.208,0.353-0.423,0.541-0.63c0.402-0.444,0.901-0.998,0.864-1.342c-0.004-0.042-0.018-0.167-0.244-0.33
+		c-0.281-0.202-0.527-0.212-0.695-0.03c-0.118,0.13-0.138,0.299-0.094,0.351c0.139,0.161,0.121,0.403-0.04,0.542
+		c-0.16,0.139-0.403,0.121-0.542-0.039c-0.317-0.368-0.27-0.957,0.109-1.371c0.332-0.363,0.979-0.601,1.71-0.077
+		c0.336,0.241,0.524,0.535,0.561,0.873c0.073,0.687-0.502,1.323-1.059,1.939c-0.185,0.205-0.36,0.398-0.499,0.581
+		c-0.47,0.618,0.05,1.083,0.111,1.134c0.163,0.136,0.184,0.379,0.047,0.542C35.598,7.787,35.489,7.834,35.38,7.834z"/>
+	<path fill="#FFFFFF" d="M33.203,8.553c-0.098,0-0.197-0.038-0.272-0.113c-0.149-0.15-0.149-0.394,0-0.543
+		c0.193-0.193,0.373-0.577,0.339-1c-0.038-0.47-0.323-0.9-0.847-1.277c-0.94-0.676-0.855-1.477-0.618-2.029
+		c0.173-0.403,0.692-0.655,1.234-0.596c0.631,0.068,1.088,0.522,1.223,1.215c0.041,0.208-0.095,0.411-0.304,0.451
+		c-0.208,0.042-0.41-0.096-0.451-0.304c-0.088-0.452-0.345-0.575-0.544-0.598c-0.243-0.028-0.429,0.083-0.452,0.134
+		c-0.194,0.452-0.086,0.781,0.36,1.103c0.892,0.641,1.125,1.354,1.164,1.839c0.058,0.713-0.267,1.311-0.562,1.606
+		C33.399,8.516,33.301,8.553,33.203,8.553z"/>
+	<path fill="#FFFFFF" d="M31.196,7.834c-0.076,0-0.152-0.023-0.219-0.069c-0.174-0.121-0.217-0.36-0.097-0.534
+		c0.282-0.406,0.123-0.669-0.534-1.308c-0.09-0.087-0.178-0.173-0.261-0.26c-0.602-0.626-0.325-1.344,0.007-1.672
+		c0.151-0.149,0.394-0.148,0.543,0.002c0.148,0.15,0.148,0.391,0,0.54C30.53,4.645,30.39,4.87,30.641,5.132
+		c0.076,0.079,0.159,0.159,0.242,0.24c0.529,0.514,1.328,1.291,0.629,2.297C31.437,7.776,31.317,7.834,31.196,7.834z"/>
+</g>
+</svg>

+ 255 - 0
scripts/lora_prompt_tool.py

@@ -0,0 +1,255 @@
+import modules.scripts as scripts
+import gradio as gr
+import modules
+from modules import script_callbacks
+from modules import shared
+from modules.ui_components import ToolButton
+from modules.ui import create_refresh_button
+from scripts.loraprompt_lib import libdata
+from scripts.loraprompt_lib import model
+from scripts.loraprompt_lib import ajax_action
+from scripts.loraprompt_lib import dataframe_edit
+from scripts.loraprompt_lib import localization
+from scripts.loraprompt_lib import util
+from scripts.loraprompt_lib import setting
+
+model.get_custom_model_folder()
+setting.load_setting()
+util.set_debug_logging_state(ajax_action.flag_to_boolean(setting.get_setting("debug")))
+
+def on_ui_tabs():
+    local_code = getattr(shared.opts, "localization", "en")
+    if getattr(shared.opts, "bilingual_localization_enabled", False) and (local_code == "en" or str(local_code).lower() == "none"):
+        local_code = getattr(shared.opts, "bilingual_localization_file", local_code)
+    localization.load_localization(local_code)
+    with gr.Blocks(analytics_enabled=False) as lora_prompt_helper:
+        txt2img_prompt = modules.ui.txt2img_paste_fields[0][0]
+        txt2img_neg_prompt = modules.ui.txt2img_paste_fields[1][0]
+        img2img_prompt = modules.ui.img2img_paste_fields[0][0]
+        img2img_neg_prompt = modules.ui.img2img_paste_fields[1][0]
+        with gr.Tab(localization.get_localize('Edit Model Trigger Words')):
+            with gr.Box(elem_classes="lorahelp_box"):
+                #模型基礎資料區
+                with gr.Column():
+                    gr.Markdown(f"### {localization.get_localize('Edit Model Basic Data')}")
+                    with gr.Row():
+                        with gr.Column():
+                            js_model_type = gr.Textbox(label=localization.get_localize("Model type"), interactive=False)
+                            js_subtype = gr.Textbox(label=localization.get_localize("Type"), interactive=True, placeholder="EX: LoCon")
+                            js_model_name = gr.Textbox(label=localization.get_localize("Name"), interactive=True)
+                            js_model_path = gr.Textbox(label=localization.get_localize("Model Path"), interactive=False)
+                        gr.HTML(f"<div id=\"lorahelp_js_image_area\">{localization.get_localize('You DID NOT load any model!')}</div>")
+                    with gr.Row():
+                        js_suggested_weight = gr.Textbox(label=localization.get_localize("Suggested weight"), interactive=True, placeholder="EX: 1.0")
+                        js_model_params = gr.Textbox(label=localization.get_localize("Model params"), interactive=True, placeholder="EX: 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0")
+            with gr.Box(elem_classes="lorahelp_box"):
+                #提詞編輯區
+                with gr.Column():
+                    gr.Markdown(f"### {localization.get_localize('Edit Model Trigger Words')}")
+                    with gr.Tab(localization.get_localize('Easy editing')):
+                        with gr.Column(elem_id="lorahelp_simpleedit_group_main"):
+                            simpleedit_main_name = gr.Textbox(label=localization.get_localize("name"), interactive=True, placeholder=localization.get_localize("EX: draw a Mahiro"))
+                            simpleedit_main_triggerword = gr.Textbox(label=localization.get_localize("Trigger Word"), interactive=True, placeholder="EX: mahiro_\\(onimai\\)")
+                        with gr.Column(elem_id="lorahelp_simpleedit_supergroup_other"):
+                            with gr.Column(elem_id="lorahelp_simpleedit_group_extra"):
+                                simpleedit_extra_enable = gr.Checkbox(value=False,label=localization.get_localize("Additional description"), interactive=True, elem_id="lorahelp_simpleedit_group_extra_enabled")
+                                with gr.Column(elem_id="lorahelp_simpleedit_group_extra_body"):
+                                    simpleedit_extra_name = gr.Textbox(label=localization.get_localize("Additional description name"), interactive=True, placeholder=localization.get_localize("EX: Characteristics of Mahiro"))
+                                    simpleedit_extra_triggerword = gr.Textbox(label=localization.get_localize("Description prompt"), interactive=True, placeholder="EX: long_hair, brown_eyes")
+                            with gr.Column(elem_id="lorahelp_simpleedit_group_neg"):
+                                simpleedit_neg_enable = gr.Checkbox(value=False,label=localization.get_localize("Dedicated negative prompt"), interactive=True, elem_id="lorahelp_simpleedit_group_neg_enabled")
+                                with gr.Column(elem_id="lorahelp_simpleedit_group_neg_body"):
+                                    simpleedit_neg_name = gr.Textbox(label=localization.get_localize("Dedicated negative prompt name"), interactive=True, placeholder=localization.get_localize("EX: negative prompt for Mahiro"))
+                                    simpleedit_neg_triggerword = gr.Textbox(label=localization.get_localize("Negative prompt"), interactive=True, placeholder="EX: ugly, bad")
+                        simpleedit_apply = gr.Button(value=localization.get_localize("Apply data"))
+                        simpleedit_parms=[simpleedit_main_name, simpleedit_main_triggerword, simpleedit_extra_enable, simpleedit_extra_name, simpleedit_extra_triggerword, simpleedit_neg_enable, simpleedit_neg_name, simpleedit_neg_triggerword]
+
+                    with gr.Tab(localization.get_localize('Advanced editing'),elem_id="js_tab_adv_edit"):
+                        js_dataedit_select_index = gr.Textbox(label="Select Index", visible=False, lines=1, value="", elem_id="lorahelp_dataedit_select_index_txtbox")
+                        js_copy_paste_box = gr.Textbox(label="Copy paste", visible=False, lines=1, value="", elem_id="lorahelp_copy_paste_txtbox")
+                        dataedit_add_event = gr.Button(value=libdata.add_symbol, visible=False, elem_id="lorahelp_dataedit_add_event")
+                        dataedit_delete_event = gr.Button(value=libdata.delete_symbol, visible=False, elem_id="lorahelp_dataedit_delete_event")
+                        dataedit_up_event = gr.Button(value=libdata.up_symbol, visible=False, elem_id="lorahelp_dataedit_up_event")
+                        dataedit_down_event = gr.Button(value=libdata.down_symbol, visible=False, elem_id="lorahelp_dataedit_down_event")
+                        dataedit_paste_event = gr.Button(value=libdata.paste_symbol, visible=False, elem_id="lorahelp_dataedit_paste_event")
+                        dataedit_paste_append_event = gr.Button(value=libdata.paste_append_symbol, visible=False, elem_id="lorahelp_dataedit_paste_append_event")
+
+                        #編輯工具列
+                        with gr.Row():
+                            ToolButton(value=libdata.add_symbol, elem_id="lorahelp_dataedit_add_btn")
+                            ToolButton(value=libdata.delete_symbol, elem_id="lorahelp_dataedit_delete_btn")
+                            ToolButton(value=libdata.up_symbol, elem_id="lorahelp_dataedit_up_btn")
+                            ToolButton(value=libdata.down_symbol, elem_id="lorahelp_dataedit_down_btn")
+                            ToolButton(value=libdata.copy_symbol, elem_id="lorahelp_dataedit_copy_btn")
+                            ToolButton(value=libdata.paste_symbol, elem_id="lorahelp_dataedit_paste_btn")
+                            ToolButton(value=libdata.paste_append_symbol, elem_id="lorahelp_dataedit_paste_append_btn")
+                            ToolButton(value="", elem_id="lorahelp_oyama_mahiro")
+                            dataedit_refresh_event = ToolButton(value=libdata.refresh_symbol, elem_id="lorahelp_dataedit_refresh_event_btn")
+                            gr.Button(value=localization.get_localize("Translate prompt words into:"), elem_id="lorahelp_dataedit_translate_btn")
+                        gr.HTML(f"<div id=\"lorahelp_translate_area\"></div>")
+
+                        #編輯區: 資料表
+                        js_dataedit = gr.Dataframe(headers=[
+                                localization.get_localize("name"), 
+                                localization.get_localize("Enter your prompt word (trigger word/prompt/negative prompt)"), 
+                                localization.get_localize("Categorys of prompt"), 
+                                localization.get_localize("Negative prompt: please enter Y if this prompt is a negative prompt.")
+                            ], datatype=["str", "str", "str", "str"], col_count=(4, "fixed"), elem_id="lorahelp_js_trigger_words_dataframe", interactive=True)
+                        
+                        #操作區
+                        with gr.Row():
+                            js_remove_duplicate_prompt_btn = gr.Button(value=localization.get_localize("Remove duplicate prompts"))
+                            js_remove_empty_prompt_btn = gr.Button(value=localization.get_localize("Remove empty prompts"))
+                        with gr.Column():
+                            with gr.Row():
+                                js_dataframe_filter = gr.Textbox(label=localization.get_localize("Search..."), interactive=True, elem_id="lorahelp_js_dataframe_filter")
+                            gr.Checkbox(value=False,label=localization.get_localize("Sorting"), interactive=True, elem_id="lorahelp_sorting_group_enabled")
+                        with gr.Column(elem_id="lorahelp_sorting_group"):
+                            #排序功能
+                            with gr.Row():
+                                js_sort_order = gr.Radio(
+                                    choices=[e.value for e in libdata.SortOrder], interactive=True, 
+                                    label=localization.get_localize('Sort Order'),
+                                    elem_id="lorahelp_js_sort_order_radio"
+                                )
+                                js_sort_by_title_btn = gr.Button(value=localization.get_localize("Sort by title"))
+                                js_sort_by_prompt_btn = gr.Button(value=localization.get_localize("Sort by prompt"))
+                    with gr.Tab(localization.get_localize('JSON')):
+                        with gr.Column():
+                            with gr.Row():
+                                json_refresh_event = ToolButton(value=libdata.refresh_symbol, elem_id="lorahelp_json_refresh_event_btn")
+                            js_json_preview = gr.JSON()
+            #輸出訊息框
+            with gr.Box(elem_classes="lorahelp_box"):
+                with gr.Column():
+                    js_message_report = gr.Textbox(label=localization.get_localize("Message"), interactive=False, elem_id="lorahelp_js_output_message")
+            js_save_model_setting_btn = gr.Button(value=localization.get_localize("Save"), 
+                elem_id="lorahelp_js_save_model_setting_btn", variant="primary"
+            )
+
+            #導入功能區
+            with gr.Box(elem_classes="lorahelp_box"):
+                with gr.Column():
+                    gr.Markdown(f"### {localization.get_localize('Batch import prompts')}")
+                    with gr.Row():
+                        with gr.Column():
+                            js_load_textbox_prompt_btn = gr.Button(value=localization.get_localize("Read prompts from text boxes"), elem_id="lorahelp_js_load_textbox_prompt_btn")
+                            js_load_civitai_setting_btn = gr.Button(value=localization.get_localize("Download configuration files from CivitAI"), 
+                                elem_id="lorahelp_js_load_civitai_setting_btn")
+                            with gr.Row():
+                                js_db_model_name = gr.Dropdown(
+                                    label="Model", choices=sorted(model.get_db_models()), interactive=True
+                                )
+                                create_refresh_button(
+                                    js_db_model_name,
+                                    model.get_db_models,
+                                    lambda: {"choices": sorted(model.get_db_models())},
+                                    "lorahelp_refresh_db_models",
+                                )
+                            js_load_dreambooth_setting_btn = gr.Button(value=localization.get_localize("Load trigger words from Dreambooth model"), 
+                                elem_id="lorahelp_js_load_dreambooth_setting_btn")
+                        text_import_txtbox = gr.Textbox(label=localization.get_localize("Enter prompts (one line for one trigger words)"), lines=10, value="", 
+                            elem_id="lorahelp_text_import_txtbox")
+
+            json_ajax_txtbox = gr.Textbox(label="Model JSON", visible=False, lines=1, value="", elem_id="lorahelp_model_json_txtbox")
+        with gr.Tab(localization.get_localize('Settings')):
+            with gr.Box(elem_classes="lorahelp_box"):
+                with gr.Column():
+                    gr.Markdown(f"### {localization.get_localize_message('Settings')}")
+                    with gr.Row():
+                        js_debug_logging = gr.Checkbox(label=localization.get_localize("Show debug message"), value=ajax_action.flag_to_boolean(setting.get_setting("debug")), elem_id="lorahelp_js_debug_logging")
+                        js_touch_mode = gr.Checkbox(label=localization.get_localize("Force touch mode"), value=ajax_action.flag_to_boolean(setting.get_setting("touch_mode")), elem_id="lorahelp_js_touch_mode")
+                    js_save_ext_setting_btn = gr.Button(value=localization.get_localize("Save Setting"), 
+                        elem_id="lorahelp_js_save_ext_setting_btn", variant="primary"
+                    )
+                    js_save_ext_setting_btn.click(setting.save_setting)
+                    
+        try:
+            js_dataedit.select(dataframe_edit.get_select_index, outputs=[js_dataedit_select_index])
+        except:
+            gr.Textbox(label="select not support", lines=1, visible=False, value="", elem_id="lorahelp_select_not_support")
+        from scripts.loraprompt_lib import extension_data
+        gr.Textbox(label="extension name", lines=1, visible=False, value=extension_data.extension_name, elem_id="lorahelp_extension_name")
+
+        js_debug_logging.change(util.set_debug_logging_state, inputs=[js_debug_logging]) 
+        js_touch_mode.change(setting.set_touch_mode, inputs=[js_touch_mode]) 
+
+        model_data_ui_input = [js_subtype, js_model_name, js_model_path, js_suggested_weight, js_model_params]
+
+        #工具列事件
+        dataedit_add_event.click(dataframe_edit.add_row, inputs=[js_dataedit_select_index, js_dataedit], outputs=[js_dataedit])
+        dataedit_delete_event.click(dataframe_edit.delete_row, inputs=[js_dataedit_select_index, js_dataedit], outputs=[js_dataedit])
+        dataedit_up_event.click(dataframe_edit.up_row, inputs=[js_dataedit_select_index, js_dataedit], outputs=[js_dataedit])
+        dataedit_down_event.click(dataframe_edit.down_row, inputs=[js_dataedit_select_index, js_dataedit], outputs=[js_dataedit])
+        dataedit_paste_event.click(dataframe_edit.paste_cell, inputs=[js_dataedit_select_index, js_copy_paste_box, js_dataedit], outputs=[js_dataedit])
+        dataedit_paste_append_event.click(dataframe_edit.paste_merge_cell, inputs=[js_dataedit_select_index, js_copy_paste_box, js_dataedit], outputs=[js_dataedit])
+
+        simpleedit_apply.click(dataframe_edit.save_to_dataframe, inputs=[js_dataedit, *simpleedit_parms], outputs=[js_dataedit])
+
+        dataedit_refresh_event.click(ajax_action.reload_trigger_words, inputs=[js_model_type, js_model_path], 
+            outputs=[js_model_type, *model_data_ui_input, js_dataedit, *simpleedit_parms, json_ajax_txtbox, js_json_preview])
+        json_refresh_event.click(ajax_action.update_trigger_words_json, inputs=[*model_data_ui_input, js_dataedit, *simpleedit_parms, json_ajax_txtbox], 
+            outputs=[js_json_preview])
+
+
+        js_save_model_setting_btn.click(ajax_action.save_trigger_words, 
+            inputs=[js_model_type, *model_data_ui_input, js_dataedit, *simpleedit_parms, json_ajax_txtbox], 
+            outputs=[js_message_report]
+        )
+        js_load_civitai_setting_btn.click(ajax_action.get_setting_from_Civitai, 
+            inputs=[js_model_type, *model_data_ui_input, js_dataedit, *simpleedit_parms, json_ajax_txtbox], 
+            outputs=[js_message_report, js_model_type, *model_data_ui_input, js_dataedit, *simpleedit_parms, json_ajax_txtbox, js_json_preview]
+        )
+        js_load_dreambooth_setting_btn.click(ajax_action.get_setting_from_dreambooth, 
+            inputs=[js_db_model_name, js_dataedit], 
+            outputs=[js_message_report, js_dataedit]
+        )
+        js_load_textbox_prompt_btn.click(dataframe_edit.load_prompt_from_textbox, 
+            inputs=[text_import_txtbox, js_dataedit], 
+            outputs=[js_dataedit]
+        )
+
+        js_remove_duplicate_prompt_btn.click(dataframe_edit.remove_duplicate_prompt, 
+            inputs=[js_dataedit], 
+            outputs=[js_dataedit]
+        )
+        js_remove_empty_prompt_btn.click(dataframe_edit.remove_empty_prompt, 
+            inputs=[js_dataedit], 
+            outputs=[js_dataedit]
+        )
+        js_sort_by_title_btn.click(dataframe_edit.sort_by_title, 
+            inputs=[js_sort_order, js_dataedit], 
+            outputs=[js_dataedit]
+        )
+        js_sort_by_prompt_btn.click(dataframe_edit.sort_by_prompt, 
+            inputs=[js_sort_order, js_dataedit], 
+            outputs=[js_dataedit]
+        )
+
+        #, visible=False,
+        js_ajax_txtbox = gr.Textbox(label="Request Msg From Js", visible=False, lines=1, value="", elem_id="lorahelp_js_ajax_txtbox")
+        py_ajax_txtbox = gr.Textbox(label="Response Msg From Python", visible=False, lines=1, value="", elem_id="lorahelp_py_ajax_txtbox")
+
+        js_cors_request_btn = gr.Button(value="CORS request", visible=False, elem_id="lorahelp_js_cors_request_btn")
+        js_cors_request_btn.click(ajax_action.cors_request, inputs=[js_ajax_txtbox], outputs=[js_ajax_txtbox])
+
+        js_update_trigger_words_btn = gr.Button(value="Update Trigger Words", visible=False, elem_id="lorahelp_js_update_trigger_words_btn")
+        js_update_trigger_words_btn.click(ajax_action.update_trigger_words, 
+            inputs=[js_ajax_txtbox], 
+            outputs=[js_model_type, *model_data_ui_input, js_dataedit, *simpleedit_parms, json_ajax_txtbox, js_json_preview]
+        )
+
+        js_show_trigger_words_btn = gr.Button(value="Show Trigger Words", visible=False, elem_id="lorahelp_js_show_trigger_words_btn")
+        js_show_trigger_words_btn.click(ajax_action.show_trigger_words, inputs=[js_ajax_txtbox], outputs=[js_ajax_txtbox])
+
+        js_add_selected_trigger_word_btn = gr.Button(value="Add Selected Trigger Words", visible=False, elem_id="lorahelp_js_add_selected_trigger_word_btn")
+        js_add_selected_trigger_word_btn.click(ajax_action.add_selected_trigger_word, inputs=[js_ajax_txtbox], outputs=[txt2img_prompt, img2img_prompt])
+
+        js_add_selected_neg_trigger_word_btn = gr.Button(value="Add Selected Neg Trigger Words", visible=False, elem_id="lorahelp_js_add_selected_neg_trigger_word_btn")
+        js_add_selected_neg_trigger_word_btn.click(ajax_action.add_selected_trigger_word, inputs=[js_ajax_txtbox], outputs=[txt2img_neg_prompt, img2img_neg_prompt])
+
+    from scripts.loraprompt_lib import extension_data
+    # the third parameter is the element id on html, with a "tab_" as prefix
+    return (lora_prompt_helper , extension_data.extension_name_display, extension_data.extension_id),
+
+script_callbacks.on_ui_tabs(on_ui_tabs)

+ 5 - 0
scripts/loraprompt_lib/__init__.py

@@ -0,0 +1,5 @@
+#目錄中必須含有 __init__.py 檔案,才會被 Pyhon 當成套件;這樣可以避免一些以常用名稱命名(例如 string)的目錄,無意中隱藏了較晚出現在模組搜尋路徑中的有效模組。
+#在最簡單的情況,__init__.py 可以只是一個空白檔案
+#==================================================
+#反正我也不知道要寫什麼,就這樣吧!
+#<s>緒山真尋!</s>

+ 732 - 0
scripts/loraprompt_lib/ajax_action.py

@@ -0,0 +1,732 @@
+import os
+import json
+import re
+import math
+from . import libdata
+from . import util
+from . import loraprompttool
+from . import ajax_handler
+from . import localization
+from .dataframe_edit import get_simple_from_df
+from .dataframe_edit import save_to_dataframe
+from .dataframe_edit import append_empty
+source_filename = "ajax_action"
+
+def cors_request(msg):
+    result = ajax_handler.parse_ajax_msg(msg)
+    if not result:
+        util.console.error("Parsing ajax failed", f"{source_filename}.cors_request")
+        return ""
+    response = loraprompttool.sent_cors_request(result["url"])
+    response_state = loraprompttool.check_model_state(response)
+    response_body = { "status": "ok" }
+    if response_state == "error":
+        response_body["status"] = "error"
+        response_body["message"] = loraprompttool.get_model_error_message(response)
+    else:
+        response_body["message"] = response["message"]
+    return json.dumps(response_body, indent=4)
+
+#用於顯示右鍵選單
+def show_trigger_words(msg):
+    """pass trigger words JSON to browser
+
+    Parameters
+    ----------
+    msg : JSON
+        requset message
+
+    Returns
+    -------
+    JSON
+        the trigger words JSON of selected model
+    """
+    util.console.start("loading trigger words for context menu")
+    result = ajax_handler.parse_ajax_msg(msg)
+    if not result:
+        util.console.error("Parsing ajax failed", f"{source_filename}.show_trigger_words")
+        return ""
+    
+    model_type = result["model_type"]
+    model_path = result["model_path"]
+
+    model_info = loraprompttool.load_model_info_by_model_path(model_type, model_path)
+    #no data
+    if not model_info:
+        return ""
+    util.console.end("loading trigger words for context menu")
+    #sent to client
+    return json.dumps(model_info, indent=4)
+
+#避免沒有這個key而出錯
+def get_key(dist1, key : str, default_val):
+    """get key from dictionary, if key doesn't exist, return default value.
+
+    Parameters
+    ----------
+    dist1 : dist
+        source dictionary
+    key : str
+        key to find
+    default_val : any
+        default value
+
+    Returns
+    -------
+    object
+        The object of the specified key in the dictionary
+    """
+    if key not in dist1.keys():
+        return default_val
+    value = dist1[key]
+    if not value:
+        return default_val
+    return value
+
+#這是在webui顯示用的;No會造成翻譯時出現與 "標號" (No)衝突,改用Not
+def boolean_flag_to_display(flag):
+    if load_boolean_flag(flag) == 1:
+        return "Yes"
+    else:
+        return "Not"
+
+#將各種是/非值正規劃
+def load_boolean_flag(flag):
+    if flag == True:
+        return 1
+    if flag == False:
+        return ''
+    flag_str = str(flag)
+    flag_str = flag_str.lower().strip()
+    if flag_str in ['yes','true','是','y','t']:
+        return 1
+    flag_num = int(util.load_json_number(flag_str))
+    if flag_num != 0:
+        return 1
+    return ""
+
+def flag_to_boolean(flag):
+    return load_boolean_flag(flag) == 1
+
+def get_setting_from_dreambooth(db_model_name, df):
+    from . import model
+    dreambooth_info = model.get_db_model_setting(db_model_name)
+    if not dreambooth_info:
+        return [localization.get_localize_message("trigger word not found."), append_empty(df.values.tolist())]
+    prompt_list = []
+    if "concepts_path" in dreambooth_info.keys():
+        if dreambooth_info["concepts_path"].strip() != "":
+            concepts_file = model.load_model_info(dreambooth_info["concepts_path"])
+            if not concepts_file:
+                libdata.noop_func()
+            else:
+                for concept in concepts_file:
+                    if "instance_token" in concept.keys():
+                        prompt = concept["instance_token"]
+                        if prompt.strip() != "":
+                            prompt_list.append(prompt)
+    if "concepts_list" in dreambooth_info.keys():
+        for concept in dreambooth_info["concepts_list"]:
+            if "instance_token" in concept.keys():
+                prompt = concept["instance_token"]
+                if prompt.strip() != "":
+                    prompt_list.append(prompt)
+    if len(prompt_list) <= 0:
+        return [localization.get_localize_message("trigger word not found."), append_empty(df.values.tolist())]
+    
+    if df is None:
+        libdata.noop_func()
+    else:
+        prompt_data = df.values.tolist()
+        for prompt in prompt_list:
+            prompt_data.append(["", prompt, "", ""])
+        return [localization.get_localize_message("Successfully load trigger word from Dreambooth model."), append_empty(prompt_data)]
+    #反正程式現在跑不到這一行,就不理他了XD
+    return ["你去問緒山真尋這程式寫好沒!", append_empty(df.values.tolist())]
+
+#從CivitAI站導入模型資料 (只限於從CivitAI站下載的模型...)
+def get_setting_from_Civitai(model_type_display, model_sub_type, model_name, model_path, input_weight, input_param, 
+        df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger,
+        loadded_json_text):
+    """get JSON from CivitAI.
+
+    Parameters
+    ----------
+    model_type_display
+        model type to display
+    model_sub_type
+        Variants of the model, for example, LoRA has variants LoCon, LoHA, etc.
+    model_name
+        name of model
+    model_path
+        path of model
+    df : Dataframe
+        prompts input by user
+    loadded_json_text
+        loadded JSON
+    """
+    util.console.start("get_setting_from_Civitai")
+
+    returned_json = None
+    try:
+        returned_json = json.loads(loadded_json_text)
+    except Exception:
+        returned_json = {}
+
+    #no model are selected
+    if model_path == "":
+        util.console.error("Parsing ajax failed", f"{source_filename}.get_setting_from_Civitai")
+        return [localization.get_localize_message("Read failed, no model selected."), model_type_display, model_sub_type, model_name, 
+                model_path, input_weight, input_param, 
+                append_empty(save_to_dataframe(df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger)), 
+                main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger,
+                loadded_json_text, returned_json]
+    
+    model_type = libdata.model_type_dict[model_type_display]
+    model_weight = input_weight
+    model_param = input_param
+    #load data from CivitAI
+    Civitai_info = loraprompttool.load_model_info_from_Civitai(model_type, model_path)
+
+    #error handling
+    model_state = loraprompttool.check_model_state(Civitai_info)
+    if model_state == "empty":
+        return  [localization.get_localize_message("CivitAI does not have this model, or it has been taken down."), 
+                model_type_display, model_sub_type, model_name,
+                model_path, input_weight, input_param, 
+                append_empty(save_to_dataframe(df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger)),
+                main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger,
+                loadded_json_text, returned_json]
+    elif model_state == "error":
+        return  [loraprompttool.get_model_error_message(Civitai_info), model_type_display, model_sub_type, model_name,
+                model_path, input_weight, input_param, 
+                append_empty(save_to_dataframe(df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger)),
+                main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger,
+                loadded_json_text, returned_json]
+    
+    #load user inputed information 
+    loadded_json = None
+    try:
+        loadded_json = json.loads(loadded_json_text)
+    except Exception as err:
+        loadded_json = loraprompttool.load_model_info_by_model_path(model_type, model_path)
+
+    #if no name, get from model path, remove file extension
+    check_name, ext = os.path.splitext(model_path)
+    check_name = check_name.replace("\\", "/")
+    check_name = check_name.split("/")
+
+    if not loadded_json:
+        loadded_json = { "name":check_name[-1] }
+
+    #first step: copy all prompt into loadded_json
+    prompt_list = []
+    if "prompts" in loadded_json.keys():
+        if loadded_json["prompts"]:
+            if isinstance(loadded_json["prompts"], str):
+                prompt_item = {
+                    "title": "", 
+                    "prompt": loadded_json["prompts"], 
+                    "categorys": "",
+                    "neg":""
+                }
+                prompt_list.append(prompt_item)
+            else:
+                for prompt in loadded_json["prompts"]:
+                    prompt_item = {
+                        "title": get_key(prompt, "title", ""), 
+                        "prompt": prompt["prompt"],
+                        "categorys": get_key(prompt, "categorys", ""),
+                        "neg": load_boolean_flag(get_key(prompt, "neg", "")),
+                    }
+                    prompt_list.append(prompt_item)
+    civitai_prompt_list = []
+    if "trainedWords" in loadded_json.keys():
+        trainedWords = loadded_json["trainedWords"]
+        if isinstance(trainedWords, str):
+            civitai_prompt_list.append(trainedWords)
+        else:
+            for word in trainedWords:
+                civitai_prompt_list.append(word)
+
+    if df is None:
+        libdata.noop_func()
+    else:
+        prompt_data = save_to_dataframe(df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger)
+        for prompt in prompt_data:
+            prompt_title = prompt[0]
+            prompt_value = prompt[1]
+            prompt_category = prompt[2]
+            prompt_neg = load_boolean_flag(prompt[3])
+            if isinstance(prompt, str):
+                prompt_item = {
+                    "title": "", 
+                    "prompt": prompt, 
+                    "categorys": "",
+                    "neg":""
+                }
+                prompt_list.append(prompt_item)
+            if prompt_value == "":
+                continue
+            if prompt_title == "##Civitai##":
+                civitai_prompt_list.append(prompt_value)
+            else:
+                prompt_item = {
+                    "prompt": prompt_value
+                }
+                if prompt_title.strip() != "":
+                    prompt_item["title"] = prompt_title
+                if prompt_category.strip() != "":
+                    prompt_item["categorys"] = prompt_category
+                if prompt_neg.strip() != "":
+                    prompt_item["neg"] = prompt_neg
+                prompt_list.append(prompt_item)
+
+    #second step: merge prompt list
+    if "prompts" not in Civitai_info.keys():
+        if len(prompt_list) > 0:
+            Civitai_info["prompts"] = []
+
+    if len(prompt_list) > 0:
+        if isinstance(Civitai_info["prompts"], str):
+            Civitai_info["prompts"] = [{
+                "prompt": Civitai_info["prompts"]
+            }]
+        for prompt in prompt_list:
+            #find if prompt already exist
+            has_same = False
+            prompt_title = get_key(prompt, "title", "").strip()
+            prompt_prompt = get_key(prompt, "prompt", "").strip()
+            prompt_neg = load_boolean_flag(get_key(prompt, "neg", "").strip())
+            for i, check_prompt in enumerate(Civitai_info["prompts"]):
+
+                check_prompt_title = get_key(check_prompt, "title", "").strip()
+                check_prompt_prompt = get_key(check_prompt, "prompt", "").strip()
+                check_prompt_neg = load_boolean_flag(get_key(check_prompt, "neg", "").strip())
+                if check_prompt_title == prompt_title and \
+                    check_prompt_prompt == prompt_prompt and\
+                    prompt_prompt != "" and prompt_neg == check_prompt_neg:
+                    has_same = True
+                    if "categorys" in check_prompt.keys():
+                        Civitai_info["prompts"][i]["categorys"] = get_key(prompt, "categorys", "")
+                    if "neg" in check_prompt.keys():
+                        Civitai_info["prompts"][i]["neg"] = load_boolean_flag(get_key(prompt, "neg", ""))
+                    break
+            if not has_same:
+                Civitai_info["prompts"].append(prompt)
+
+    if "trainedWords" not in Civitai_info.keys():
+        if len(civitai_prompt_list) > 0:
+            Civitai_info["trainedWords"] = []
+
+    if len(civitai_prompt_list) > 0:
+        if isinstance(Civitai_info["trainedWords"], str):
+            Civitai_info["trainedWords"] = [Civitai_info["trainedWords"]]
+        for prompt in civitai_prompt_list:
+            #find if prompt already exist
+            has_same = False
+            for i, check_prompt in enumerate(Civitai_info["trainedWords"]):
+                if check_prompt == prompt:
+                    has_same = True
+            if not has_same:
+                Civitai_info["trainedWords"].append(prompt)
+
+    new_model_name = model_name
+    new_model_sub_type = model_sub_type
+    if "model" in Civitai_info.keys():
+        new_model_name = Civitai_info["model"]["name"]
+        new_model_sub_type = Civitai_info["model"]["type"]
+        model_weight = get_key(Civitai_info, "weight", input_weight)
+        model_param = get_key(Civitai_info, "param", input_param)
+
+    prompt_list = []
+    if "prompts" in Civitai_info.keys():
+         if Civitai_info["prompts"]:
+            if isinstance(Civitai_info["prompts"], str):
+                prompt_item = []
+                prompt_item.extend(["", Civitai_info["prompts"], "", "Not"])
+                prompt_list.append(prompt_item)
+            else:
+                for prompt in Civitai_info["prompts"]:
+                    prompt_item = []
+                    prompt_item.extend([
+                        get_key(prompt, "title", ""), 
+                        prompt["prompt"],
+                        get_key(prompt, "categorys", ""),
+                        boolean_flag_to_display(get_key(prompt, "neg", ""))])
+                    prompt_list.append(prompt_item)
+    
+    #support for Civitai's JSON
+    if "trainedWords" in Civitai_info.keys():
+        trainedWords = Civitai_info["trainedWords"]
+        if isinstance(trainedWords, str):
+            prompt_item = []
+            prompt_item.extend(["##Civitai##", trainedWords, "civitai", "Not"])
+            prompt_list.append(prompt_item)
+        else:
+            for word in trainedWords:
+                prompt_item = []
+                prompt_item.extend(["##Civitai##", word, "civitai", "Not"])
+                prompt_list.append(prompt_item)
+
+    if len(prompt_list) <= 0:
+        prompt_list = [libdata.dataframe_empty_row]
+
+    util.console.end("get_setting_from_Civitai")
+    outputed_json_text = json.dumps(Civitai_info, indent=4)
+    return [localization.get_localize_message("Successfully downloaded model data from CivitAI."), 
+            model_type_display, new_model_sub_type, 
+            new_model_name, model_path, model_weight, model_param, 
+            append_empty(prompt_list), *get_simple_from_df(prompt_list),
+            outputed_json_text, 
+            update_trigger_words_json(model_sub_type, model_name, model_path, model_weight, model_param, 
+                df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger,
+            outputed_json_text)]
+
+def update_trigger_words_json(model_sub_type, model_name, model_path, model_weight, model_params, 
+        df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger,
+        loadded_json):
+    model_info = None
+    try:
+        model_info = json.loads(loadded_json)
+    except Exception as err:
+        pass
+
+    if model_path == "":
+        return model_info
+
+    check_name, ext = os.path.splitext(model_path)
+    check_name = check_name.replace("\\", "/")
+    check_name = check_name.split("/")
+
+    if not model_info:
+        model_info = { "name":check_name[-1] }
+
+    is_civitai = False
+    if "model" in model_info.keys():
+        is_civitai = True
+    
+    if model_params.strip() != "":
+        model_info["params"] = model_params
+    try:
+        load_weight = float(str(model_weight))
+        if math.isfinite(load_weight):
+            model_info["weight"] = load_weight
+    except Exception:
+        pass
+
+
+    if df is None:
+        libdata.noop_func()
+    else:
+        civitai_it = 0
+        it = 0
+        prompt_data = save_to_dataframe(df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger)
+        if is_civitai:
+            model_info["trainedWords"] = []
+        model_info["prompts"] = []
+        for prompt in prompt_data:
+            prompt_title = prompt[0]
+            prompt_value = prompt[1]
+            prompt_category = prompt[2]
+            prompt_neg = load_boolean_flag(prompt[3])
+            if isinstance(prompt, str):
+                prompt_title = ""
+                prompt_value = prompt
+                prompt_category = ""
+            if prompt_value == "":
+                continue
+            if is_civitai and prompt_title == "##Civitai##":
+                if civitai_it >= len(model_info["trainedWords"]):
+                    model_info["trainedWords"].append(prompt_value)
+                else:
+                    model_info["trainedWords"][civitai_it] = prompt_value
+                civitai_it += 1
+            else:
+                prompt_item = { "prompt" : prompt_value }
+                if prompt_title != "":
+                    prompt_item["title"] = prompt_title
+                if prompt_category != "":
+                    prompt_item["categorys"] = prompt_category
+                if prompt_neg != "":
+                    prompt_item["neg"] = load_boolean_flag(prompt_neg)
+
+                if it >= len(model_info["prompts"]):
+                    model_info["prompts"].append(prompt_item)
+                else:
+                    model_info["prompts"][it] = prompt_item
+                it += 1
+        if len(model_info["prompts"]) <= 0:
+            model_info.pop("prompts")
+
+    if model_name != "":
+        if is_civitai:
+            model_info["model"]["name"] = model_name
+        else:
+            model_info["name"] = model_name
+
+    if model_sub_type != "":
+        if is_civitai:
+            model_info["model"]["type"] = model_sub_type
+        else:
+            model_info["type"] = model_sub_type
+
+    return model_info
+
+#儲存編輯好的提詞表
+def save_trigger_words(model_type_display, model_sub_type, model_name, model_path, model_weight, model_params, 
+        df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger,
+        loadded_json):
+    """save user inputed trigger words to JSON file.
+
+    Parameters
+    ----------
+    model_type_display
+        model type to display
+    model_sub_type
+        Variants of the model, for example, LoRA has variants LoCon, LoHA, etc.
+    model_name
+        name of model
+    model_path
+        path of model
+    df : Dataframe
+        prompts input by user
+    loadded_json
+        loadded JSON
+    """
+    util.console.start("save_trigger_words")
+    if model_path == "":
+        util.console.error("Parsing ajax failed", f"{source_filename}.save_trigger_words")
+        return localization.get_localize_message("Save failed, no model selected.")
+
+    model_type = libdata.model_type_dict[model_type_display]
+
+    check_name, ext = os.path.splitext(model_path)
+    check_name = check_name.replace("\\", "/")
+    check_name = check_name.split("/")
+
+    model_info = None
+    try:
+        model_info = json.loads(loadded_json)
+    except Exception as err:
+        model_info = loraprompttool.load_model_info_by_model_path(model_type, model_path)
+
+    if not model_info:
+        model_info = { "name":check_name[-1] }
+
+    is_civitai = False
+    if "model" in model_info.keys():
+        is_civitai = True
+    if model_params.strip() != "":
+        model_info["params"] = model_params
+    try:
+        load_weight = float(str(model_weight))
+        if math.isfinite(load_weight):
+            model_info["weight"] = load_weight
+    except Exception:
+        pass
+
+    if df is None:
+        libdata.noop_func()
+    else:
+        civitai_it = 0
+        it = 0
+        prompt_data = save_to_dataframe(df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger)
+        if is_civitai:
+            model_info["trainedWords"] = []
+        model_info["prompts"] = []
+        for prompt in prompt_data:
+            prompt_title = prompt[0]
+            prompt_value = prompt[1]
+            prompt_category = prompt[2]
+            prompt_neg = load_boolean_flag(prompt[3])
+            if isinstance(prompt, str):
+                prompt_title = ""
+                prompt_value = prompt
+                prompt_category = ""
+            if prompt_value == "":
+                continue
+            if is_civitai and prompt_title == "##Civitai##":
+                if civitai_it >= len(model_info["trainedWords"]):
+                    model_info["trainedWords"].append(prompt_value)
+                else:
+                    model_info["trainedWords"][civitai_it] = prompt_value
+                civitai_it += 1
+            else:
+                prompt_item = { "prompt" : prompt_value }
+                if prompt_title != "":
+                    prompt_item["title"] = prompt_title
+                if prompt_category != "":
+                    prompt_item["categorys"] = prompt_category
+                if prompt_neg != "":
+                    prompt_item["neg"] = load_boolean_flag(prompt_neg)
+
+                if it >= len(model_info["prompts"]):
+                    model_info["prompts"].append(prompt_item)
+                else:
+                    model_info["prompts"][it] = prompt_item
+                it += 1
+        if len(model_info["prompts"]) <= 0:
+            model_info.pop("prompts")
+
+    if model_name != "":
+        if is_civitai:
+            model_info["model"]["name"] = model_name
+        else:
+            model_info["name"] = model_name
+
+    if model_sub_type != "":
+        if is_civitai:
+            model_info["model"]["type"] = model_sub_type
+        else:
+            model_info["type"] = model_sub_type
+    try:
+        loraprompttool.save_model_info_by_model_path(model_info, model_type, model_path)
+    except Exception as err:
+        return "Error: " + err
+    
+    util.console.end("save_trigger_words")
+    return localization.get_localize_message("Save complete")
+
+#將提詞表傳到前端WebUI供編輯
+def reload_trigger_words(model_type_input, model_path):
+    """pass model JSON to browser for edit
+
+    Parameters
+    ----------
+    msg : JSON
+        request header.
+    """
+    model_type = model_type_input
+    try:
+        model_type = libdata.model_type_dict[model_type_input]
+    except Exception:
+        pass
+    
+    model_type_display = libdata.model_type_names[model_type]
+
+    check_name, ext = os.path.splitext(model_path)
+    check_name = check_name.replace("\\", "/")
+    check_name = check_name.split("/")
+
+    model_info = loraprompttool.load_model_info_by_model_path(model_type, model_path)
+    
+    if not model_info:
+        return [model_type_display, "", check_name[-1], model_path, "", "", [libdata.dataframe_empty_row], *get_simple_from_df([libdata.dataframe_empty_row]), "", {}]
+
+    model_sub_type = get_key(model_info, "type", model_type_display)
+    model_name = get_key(model_info, "name", check_name[-1])
+    model_weight = get_key(model_info, "weight", "")
+    model_params = get_key(model_info, "params", "")
+
+    #check is Civitai's JSON
+    if "model" in model_info.keys():
+        model_sub_type = get_key(model_info, "type", model_info["model"]["type"])
+        model_name = model_info["model"]["name"]
+        model_weight = get_key(model_info, "weight", model_weight)
+
+    prompt_list = []
+    if "prompts" in model_info.keys():
+         if model_info["prompts"]:
+            if isinstance(model_info["prompts"], str):
+                prompt_item = []
+                prompt_item.extend(["", model_info["prompts"], "", "Not"])
+                prompt_list.append(prompt_item)
+            else:
+                for prompt in model_info["prompts"]:
+                    prompt_item = []
+                    prompt_item.extend([
+                        get_key(prompt, "title", ""), 
+                        prompt["prompt"],
+                        get_key(prompt, "categorys", ""),
+                        boolean_flag_to_display(get_key(prompt, "neg", ""))])
+                    prompt_list.append(prompt_item)
+    
+    #support for Civitai's JSON
+    if "trainedWords" in model_info.keys():
+        trainedWords = model_info["trainedWords"]
+        if isinstance(trainedWords, str):
+            prompt_item = []
+            prompt_item.extend(["##Civitai##", trainedWords, "civitai", "Not"])
+            prompt_list.append(prompt_item)
+        else:
+            for word in trainedWords:
+                prompt_item = []
+                prompt_item.extend(["##Civitai##", word, "civitai", "Not"])
+                prompt_list.append(prompt_item)
+
+    if len(prompt_list) <= 0:
+        prompt_list = [libdata.dataframe_empty_row]
+
+    return [model_type_display, model_sub_type, model_name, model_path, model_weight, model_params, append_empty(prompt_list), *get_simple_from_df(prompt_list), json.dumps(model_info, indent=4), model_info]
+
+
+def update_trigger_words(msg):
+    """pass model JSON to browser for edit
+
+    Parameters
+    ----------
+    msg : JSON
+        request header.
+    """
+    util.console.start("load trigger words of model for edit")
+    result = ajax_handler.parse_ajax_msg(msg)
+    if not result:
+        util.console.error("Parsing ajax failed", f"{source_filename}.update_trigger_words")
+        return [localization.get_localize_message("Model not loaded."), "", "", "", "", "", [libdata.dataframe_empty_row], ""]
+    
+    model_type = result["model_type"]
+    model_path = result["model_path"]
+    gradio_outputs = reload_trigger_words(model_type, model_path)
+    util.console.end("load trigger words of model for edit")
+    return gradio_outputs
+
+#將提詞加入提詞輸入框
+def add_selected_trigger_word(msg):
+    """add selected trigger word to prompt textbox.
+
+    Parameters
+    ----------
+    msg : JSON
+        request header.
+    """
+    result = ajax_handler.parse_ajax_msg(msg)
+    if not result:
+        util.console.error("Parsing ajax failed", f"{source_filename}.add_selected_trigger_word")
+        return ""
+    
+    txt2img_prompt = result["txt2img_prompt"]
+    img2img_prompt = result["img2img_prompt"]
+    active_tab_type = result["active_tab_type"]
+    addprompt = result["addprompt"]
+
+    overwrite = False
+    if "overwrite" in result.keys():
+        if flag_to_boolean(result["overwrite"]):
+            overwrite = True
+
+    prompt = txt2img_prompt if active_tab_type == "txt2img" else img2img_prompt
+    if overwrite:
+        prompt = ""
+
+    need_comma = True
+    prompt_check = prompt.strip()
+    if prompt_check == "":
+        need_comma = False
+    elif prompt_check[-1] == ",":
+        need_comma = False 
+
+    re_pattern_insert = ",\s*,"
+    if re.search(re_pattern_insert, prompt):
+        new_prompt = re.sub(re_pattern_insert, f",{addprompt} ,", prompt)
+    else:
+        new_prompt = prompt + (", " if need_comma else "") + addprompt
+
+    result_prompts = [txt2img_prompt, img2img_prompt]
+    if active_tab_type == "txt2img":
+        result_prompts[0] = new_prompt
+    elif active_tab_type == "img2img":
+        result_prompts[1] = new_prompt
+
+    # add to prompt
+    return result_prompts

+ 82 - 0
scripts/loraprompt_lib/ajax_handler.py

@@ -0,0 +1,82 @@
+import json
+from . import libdata
+from . import util
+
+source_filename = "ajax_handler"
+
+#模擬AJAX。前端 -> 後端
+def parse_ajax_msg(msg):
+    """parse message from browser
+
+    Parameters
+    ----------
+    msg : JSON
+        requset message
+
+    Returns
+    -------
+    JSON
+        parsed result
+    """
+    try:
+        msg_dict = json.loads(msg)
+    except Exception as err:
+        util.console.error(err, f"{source_filename}.parse_ajax_msg")
+        util.console.log("Error load Json!")
+        return
+
+    # in case client side run JSON.stringify twice
+    if (type(msg_dict) == str):
+        msg_dict = json.loads(msg_dict)
+
+    if "action" not in msg_dict.keys():
+        util.console.error("Can not find action from js request", f"{source_filename}.parse_ajax_msg")
+        return
+
+    action = msg_dict["action"]
+    if not action:
+        util.console.error("Action from js request is None", f"{source_filename}.parse_ajax_msg")
+        return
+
+    if action not in libdata.ajax_actions:
+        util.console.error("Unknow action: " + action, f"{source_filename}.parse_ajax_msg")
+        return
+
+    return msg_dict
+
+#模擬AJAX。後端 -> 前端
+def build_py_msg(action:str, content:dict):
+    """sent message to browser
+
+    Parameters
+    ----------
+    action : str
+        requset header
+    content : dict
+        requset content
+
+    Returns
+    -------
+    JSON
+        message to sent
+    """
+    util.console.start("build_py_msg")
+    if not content:
+        util.console.error("Content is None", f"{source_filename}.build_py_msg")
+        return
+    
+    if not action:
+        util.console.error("Action is None", f"{source_filename}.build_py_msg")
+        return
+
+    if action not in libdata.py_actions:
+        util.console.error("Unknow action: " + action, f"{source_filename}.build_py_msg")
+        return
+
+    msg = {
+        "action" : action,
+        "content": content
+    }
+
+    util.console.end("build_py_msg")
+    return json.dumps(msg)

+ 356 - 0
scripts/loraprompt_lib/dataframe_edit.py

@@ -0,0 +1,356 @@
+from operator import itemgetter
+import json
+import gradio as gr
+from . import libdata
+from . import ajax_action
+
+source_filename = "dataframe_edit"
+
+#fallback unsupport class
+my_SelectData = gr.Dataframe
+try:
+    my_SelectData = gr.SelectData
+except Exception:
+    pass
+
+def get_select_index(evt: my_SelectData):#
+    """get select index from DataFrame
+
+    Parameters
+    ----------
+    evt : SelectData
+        DataFrame select event object
+
+    Returns
+    -------
+    Tuple[int, int]
+        select index in DataFrame
+    """
+    return evt.index
+
+def load_select_index(select_json):
+    """load select index from JSON
+
+    Parameters
+    ----------
+    select_json : JSON
+        select index JSON
+
+    Returns
+    -------
+    Tuple[int, int]
+        select index
+    """
+    try:
+        return json.loads(select_json)
+    except Exception as err:
+        return [-1, -1]
+
+def add_row(select_json, df):
+    """add a row to DataFrame
+
+    Parameters
+    ----------
+    select_json : JSON
+        select index
+    df : DataFrame
+        DataFrame to add
+    """
+    prompt_data = df.values.tolist()
+    select_index = load_select_index(select_json)
+    new_prompt_data = []
+    i = 0
+    for prompt_item in prompt_data:
+        new_prompt_data.append(prompt_item)
+        if i == select_index[0]:
+            new_prompt_data.append(libdata.dataframe_empty_row)
+        i += 1
+    if len(new_prompt_data) <= 0:
+        new_prompt_data = [libdata.dataframe_empty_row]
+    return new_prompt_data
+
+def delete_row(select_json, df):
+    """delete a row to DataFrame
+
+    Parameters
+    ----------
+    select_json : JSON
+        select index
+    df : DataFrame
+        DataFrame to delete
+    """
+    prompt_data = df.values.tolist()
+    select_index = load_select_index(select_json)
+    new_prompt_data = []
+    i = 0
+    for prompt_item in prompt_data:
+        if i != select_index[0]:
+            new_prompt_data.append(prompt_item)
+        i += 1
+    if len(new_prompt_data) <= 0:
+        new_prompt_data = [libdata.dataframe_empty_row]
+    return new_prompt_data
+
+def up_row(select_json, df):
+    """Move selected row up one space
+
+    Parameters
+    ----------
+    select_json : JSON
+        select index
+    df : DataFrame
+        DataFrame to change
+    """
+    prompt_data = df.values.tolist()
+    if len(prompt_data) <= 1:
+        return prompt_data
+    select_index = load_select_index(select_json)
+    if select_index[0] <= 0:
+        return prompt_data
+    #swap
+    tmp_row = prompt_data[select_index[0] - 1]
+    prompt_data[select_index[0] - 1] = prompt_data[select_index[0]]
+    prompt_data[select_index[0]] = tmp_row
+    return prompt_data
+
+def down_row(select_json, df):
+    """Move selected row down one space
+
+    Parameters
+    ----------
+    select_json : JSON
+        select index
+    df : DataFrame
+        DataFrame to change
+    """
+    prompt_data = df.values.tolist()
+    prompt_len = len(prompt_data)
+    if prompt_len <= 1:
+        return prompt_data
+    select_index = load_select_index(select_json)
+    if select_index[0] >= prompt_len - 1:
+        return prompt_data
+    #swap
+    tmp_row = prompt_data[select_index[0] + 1]
+    prompt_data[select_index[0] + 1] = prompt_data[select_index[0]]
+    prompt_data[select_index[0]] = tmp_row
+    return prompt_data
+
+def paste_cell(select_json, paste_text, df):
+    """Paste text from the clipboard to the selected cell 
+
+    Parameters
+    ----------
+    select_json : JSON
+        select index
+    paste_text : JSON
+        text to paste
+    df : DataFrame
+        DataFrame to paste
+    """
+    prompt_data = df.values.tolist()
+    select_index = load_select_index(select_json)
+    if select_index[0] < 0:
+        return prompt_data
+    if paste_text.strip() == "":
+        return prompt_data
+    prompt_data[select_index[0]][select_index[1]] = paste_text
+    return prompt_data
+
+def paste_merge_cell(select_json, paste_text, df):
+    """Paste text from the clipboard to the selected cell, if cell not empty, merge it.
+
+    Parameters
+    ----------
+    select_json : JSON
+        select index
+    paste_text : JSON
+        text to paste
+    df : DataFrame
+        DataFrame to paste
+    """
+    prompt_data = df.values.tolist()
+    select_index = load_select_index(select_json)
+    if select_index[0] < 0:
+        return prompt_data
+    if paste_text.strip() == "":
+        return prompt_data
+    prompt = prompt_data[select_index[0]][select_index[1]]
+    need_comma = True
+    prompt_check = prompt.strip()
+    if prompt_check == "":
+        need_comma = False
+    elif prompt_check[-1] == ",":
+        need_comma = False 
+
+    prompt_data[select_index[0]][select_index[1]] = prompt + (", " if need_comma else "") + paste_text
+    return prompt_data
+
+def append_empty(df):
+    try:
+        prompt_data = df.values.tolist()
+    except:
+        prompt_data = df
+    if len(prompt_data) <= 0:
+        return prompt_data
+    if ("").join(prompt_data[-1]).strip() != "":
+        prompt_data.append(["" for x in prompt_data[-1]])
+    return prompt_data
+
+def get_simple_from_df(df):
+    try:
+        prompt_data = df.values.tolist()
+    except:
+        prompt_data = df
+    main_name : str = ""
+    main_trigger : str = ""
+    has_extra = False
+    extra_name : str = ""
+    extra_trigger : str = ""
+    has_neg = False
+    neg_name : str = ""
+    neg_trigger : str = ""
+    i = 0
+    for prompt_item in prompt_data:
+        if libdata.DEFAULT_KEY in [x.strip() for x in prompt_item[2].split(",")]:
+            if i == 0:
+                main_name = str(prompt_item[0])
+                main_trigger = str(prompt_item[1])
+            elif i == 1:
+                has_extra = True
+                extra_name = str(prompt_item[0])
+                extra_trigger = str(prompt_item[1])
+            else:
+                if ajax_action.flag_to_boolean(prompt_item[3]):
+                    if not has_neg:
+                        has_neg = True
+                        neg_name = str(prompt_item[0])
+                        neg_trigger = str(prompt_item[1])
+            i += 1
+    return main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger
+
+def save_to_dataframe(df, main_name, main_trigger, has_extra, extra_name, extra_trigger, has_neg, neg_name, neg_trigger):
+    try:
+        prompt_data = df.values.tolist()
+    except:
+        prompt_data = df
+    insert_data = []
+    if main_trigger.strip() != "":
+        insert_data.append([main_name, main_trigger, libdata.DEFAULT_KEY, "Not"])
+    if has_extra and extra_trigger.strip() != "":
+        insert_data.append([extra_name, extra_trigger, libdata.DEFAULT_KEY, "Not"])
+    if has_neg and neg_trigger.strip() != "":
+        insert_data.append([neg_name, neg_trigger, libdata.DEFAULT_KEY, "Yes"])
+    new_prompt_data = []
+    if len(insert_data) > 0:
+        i=0
+        for prompt_item in prompt_data:
+            if libdata.DEFAULT_KEY in [x.strip() for x in prompt_item[2].split(",")]:
+                if i < len(insert_data):
+                    new_prompt_data.append(insert_data[i])
+                i += 1
+            else:
+                if prompt_item[0].strip() != "" and prompt_item[1].strip() != "":
+                    new_prompt_data.append(prompt_item)
+        while i < len(insert_data):
+            new_prompt_data.append(insert_data[i])
+            i += 1
+    else:
+        return prompt_data
+
+    return new_prompt_data
+
+def sort_by_title(order, df):
+    """Sort the data in the DataFrame according to the title
+
+    Parameters
+    ----------
+    order
+        Sort order
+    df : DataFrame
+        DataFrame to sort
+    """
+    prompt_data = df.values.tolist()
+    if order == libdata.SortOrder.DESC.value:
+        return sorted(prompt_data, key=itemgetter(0,1), reverse=True)
+    return sorted(prompt_data, key=itemgetter(0,1))
+
+def sort_by_prompt(order, df):
+    """Sort the data in the DataFrame according to the prompt
+
+    Parameters
+    ----------
+    order
+        Sort order
+    df : DataFrame
+        DataFrame to sort
+    """
+    prompt_data = df.values.tolist()
+    if order == libdata.SortOrder.DESC.value:
+        return sorted(prompt_data, key=itemgetter(1,0), reverse=True)
+    return sorted(prompt_data, key=itemgetter(1,0))
+
+def load_prompt_from_textbox(input_text: str, df):
+    """load prompts line by line into DataFrame
+
+    Parameters
+    ----------
+    input_text
+        input
+    df : DataFrame
+        DataFrame to load into
+    """
+    prompt_data = df.values.tolist()
+    if input_text.strip() == "":
+        return prompt_data
+    lines = input_text.splitlines()
+    for line in lines:
+        if line.strip() != "":
+            prompt_data.append(["",line,""])
+    return prompt_data
+
+def remove_duplicate_prompt(df):
+    """Remove duplicate prompt from DataFrame
+
+    Parameters
+    ----------
+    df : DataFrame
+        DataFrame to change
+    """
+    prompt_data = df.values.tolist()
+    new_prompt_data = []
+    for prompt_item in prompt_data:
+        has_same = False
+        prompt_title = prompt_item[0]
+        prompt_prompt = prompt_item[1]
+        for check_prompt_item in new_prompt_data:
+            check_prompt_title = check_prompt_item[0]
+            check_prompt_prompt = check_prompt_item[1]
+            if check_prompt_title == prompt_title and \
+                check_prompt_prompt == prompt_prompt and\
+                prompt_prompt != "":
+                has_same = True
+                break
+        if not has_same:
+            new_prompt_data.append(prompt_item)
+    if len(new_prompt_data) <= 0:
+        new_prompt_data = [libdata.dataframe_empty_row]
+    return new_prompt_data
+
+def remove_empty_prompt(df):
+    """Remove empty prompt from DataFrame
+
+    Parameters
+    ----------
+    df : DataFrame
+        DataFrame to change
+    """
+    prompt_data = df.values.tolist()
+    new_prompt_data = []
+    for prompt_item in prompt_data:
+        prompt_prompt = prompt_item[1].strip()
+        if prompt_prompt != "":
+            new_prompt_data.append(prompt_item)
+    if len(new_prompt_data) <= 0:
+        new_prompt_data = [libdata.dataframe_empty_row]
+    return new_prompt_data

+ 7 - 0
scripts/loraprompt_lib/extension_data.py

@@ -0,0 +1,7 @@
+source_filename = "extension_data"
+
+version = "1.0.0"
+
+extension_name = "lora-prompt-tool"
+extension_id = "lora_prompt_helper"
+extension_name_display = "LoRA prompt helper"

+ 109 - 0
scripts/loraprompt_lib/libdata.py

@@ -0,0 +1,109 @@
+import modules.scripts as scripts
+from modules import shared as ws
+import os
+from enum import Enum
+
+source_filename = "libdata"
+
+# root path
+root_path = os.getcwd()
+script_path = os.sep.join(__file__.split(os.sep)[0:-5]) if root_path is None else root_path
+models_path = os.path.join(script_path, "models")
+dreambooth_models_path = os.path.join(models_path, "dreambooth")
+try:
+    dreambooth_models_path = ws.cmd_opts.dreambooth_models_path or dreambooth_models_path
+except:
+    pass
+
+DEFAULT_KEY = "##default##"
+
+# extension path
+extension_path = scripts.basedir()
+
+setting_file_name = "setting.json"
+dreambooth_setting_file_name = "db_config.json"
+
+up_symbol = '\u2b06\ufe0f' #⬆️
+down_symbol ='\u2b07\ufe0f' #⬇️
+delete_symbol = '\u274c' #❌
+add_symbol = '\u2795' #➕
+paste_symbol ='\U0001F4CB\u200B' #📋
+copy_symbol = '\U0001F4DA' #📚
+paste_append_symbol = '\U0001F4DD' #📝
+refresh_symbol = '\U0001f504'  # 🔄
+
+folders = {
+    "ti": os.path.join(root_path, "embeddings"),
+    "hyper": os.path.join(root_path, "models", "hypernetworks"),
+    "ckp": os.path.join(root_path, "models", "Stable-diffusion"),
+    "lora": os.path.join(root_path, "models", "Lora"),
+    "lyco": os.path.join(root_path, "models", "LyCORIS"),
+}
+
+exts = (".bin", ".pt", ".safetensors", ".ckpt")
+info_ext = [".json", ".info", ".civitai.info"]
+vae_suffix = ".vae"
+
+http_state_codes = {
+    100 : "Continue",101 : "Switching Protocols",102 : "Processing",103 : "Early Hints",
+    110 : "Response is Stale",111 : "Revalidation Failed",112 : "Disconnected Operation",113 : "Heuristic Expiration",
+    199 : "Miscellaneous Warning",
+    200 : "OK",201 : "Created",202 : "Accepted",203 : "Non-Authoritative Information",204 : "No Content",205 : "Reset Content",206 : "Partial Content",207 : "Multi-Status",208 : "Already Reported",
+    214 : "Transformation Applied",226 : "IM Used",299 : "Miscellaneous Persistent Warning",
+    300 : "Multiple Choices",301 : "Moved Permanently",302 : "Found",303 : "See Other",304 : "Not Modified",305 : "Use Proxy",306 : "Switch Proxy",307 : "Temporary Redirect",308 : "Permanent Redirect",
+    400 : "Bad Request",401 : "Unauthorized",402 : "Payment Required",403 : "Forbidden",404 : "Not Found",405 : "Method Not Allowed",406 : "Not Acceptable",407 : "Proxy Authentication Required",408 : "Request Timeout",409 : "Conflict",
+    410 : "Gone",411 : "Length Required",412 : "Precondition Failed",413 : "Request Entity Too Large",414 : "Request-URI Too Long",415 : "Unsupported Media Type",416 : "Requested Range Not Satisfiable",417 : "Expectation Failed",418 : "I'm a teapot",419 : "Page Expired",
+    420 : "Method Failure/Enhance Your Calm",421 : "Misdirected Request",422 : "Unprocessable Entity",423 : "Locked",424 : "Failed Dependency",425 : "Too Early",426 : "Upgrade Required",428 : "Precondition Required",429 : "Too Many Requests",
+    430 : "Request Header Fields Too Large",431 : "Request Header Fields Too Large",
+    440 : "Login Time-out",444 : "No Response",449 : "Retry With",450 : "Blocked by Windows Parental Controls",451 : "Unavailable For Legal Reasons/Redirect",
+    460 : "Client closed the connection with the load balancer before the idle timeout period elapsed",463 : "The load balancer received an X-Forwarded-For request header with more than 30 IP addresses",
+    494 : "Request Header Too Large",495 : "SSL Certificate Error",496 : "SSL Certificate Required",497 : "HTTP Request Sent to HTTPS Port",498 : "Invalid Token",499 : "Client Closed Request/Token Required",
+    500 : "Internal Server Error",501 : "Not Implemented",502 : "Bad Gateway",503 : "Service Unavailable",504 : "Gateway Timeout",505 : "HTTP Version Not Supported",506 : "Variant Also Negotiates",507 : "Insufficient Storage",508 : "Loop Detected",509 : "Bandwidth Limit Exceeded",
+    510 : "Not Extended",511 : "Network Authentication Required",520 : "Web Server Returned an Unknown Error",521 : "Web Server Is Down",522 : "Connection Timed Out",523 : "Origin Is Unreachable",524 : "A Timeout Occurred",525 : "SSL Handshake Failed",526 : "Invalid SSL Certificate",527 : "Railgun Error",529 : "Site is overloaded",
+    530 : "Site is frozen",561 : "Unauthorized",598 : "(Informal convention) Network read timeout error",599 : "Network Connect Timeout Error",
+}
+
+def_headers = {'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148'}
+proxies = None
+
+class SortOrder(Enum):
+    ASC = 'Ascending'
+    DESC = 'Descending'
+
+# action list
+ajax_actions = ( "open_url", 
+                 "add_selected_trigger_word", 
+                 "show_trigger_words", 
+                 "update_trigger_words",
+                 "cors_request"
+            )
+py_actions = ("open_url")
+
+model_type_dict = {
+    "Checkpoint": "ckp",
+    "TextualInversion": "ti",
+    "Hypernetwork": "hyper",
+    "LORA": "lora",
+    "LoCon": "lora",
+    "LyCORIS": "lyco",
+}
+
+model_type_names = {
+    "ckp": "Checkpoint",
+    "ti": "TextualInversion",
+    "hyper": "Hypernetwork",
+    "lora": "LORA",
+    "lyco": "LyCORIS",
+}
+
+civitai_apis = {
+    "modelPage":"https://civitai.com/models/",
+    "modelId": "https://civitai.com/api/v1/models/",
+    "modelVersionId": "https://civitai.com/api/v1/model-versions/",
+    "hash": "https://civitai.com/api/v1/model-versions/by-hash/"
+}
+
+dataframe_empty_row = ["","","",""]
+
+def noop_func():
+    return

+ 388 - 0
scripts/loraprompt_lib/localization.py

@@ -0,0 +1,388 @@
+import os
+import json
+import re
+from modules import shared
+
+source_filename = "localization"
+
+local_data = {}
+local_id = ""
+
+localizations = {}
+localizations_dir = shared.cmd_opts.localizations_dir if "localizations_dir" in shared.cmd_opts else "localizations"
+
+def list_localizations(dirname):
+    localizations.clear()
+    for file in os.listdir(dirname):
+        fn, ext = os.path.splitext(file)
+        if ext.lower() != ".json":
+            continue
+
+        localizations[fn] = os.path.join(dirname, file)
+
+    from modules import scripts
+    for file in scripts.list_scripts("localizations", ".json"):
+        fn, ext = os.path.splitext(file.filename)
+        localizations[fn] = file.path
+list_localizations(localizations_dir)
+
+my_localization_data = {
+  "Edit Model Basic Data": {
+    "zh_TW": "編輯模型基礎資料",
+    "ja": "モデルの基本データを編集する",
+    "ko": "모델 기본 데이터 편집",
+    "zh_CN": "编辑模型基础资料"
+  },
+  "You DID NOT load any model!": {
+    "zh_TW": "你沒有載入模型!",
+    "ja": "モデルを読み込んでいません!",
+    "ko": "모델을 로드하지 않았습니다!",
+    "zh_CN": "你没有加载模型!"
+  },
+  "Edit Model Trigger Words": {
+    "zh_TW": "編輯模型觸發詞",
+    "ja": "モデルトリガーワードの編集",
+    "ko": "모델 트리거 단어 수정",
+    "zh_CN": "编辑模型触发词"
+  },
+  "Enter your prompt word (trigger word/prompt/negative prompt)": {
+    "zh_TW": "輸入你的提示詞 (觸發詞/提示詞/反向提示詞)",
+    "ja": "プロンプトワードを入力してください (トリガーワード/プロンプト/否定プロンプト)",
+    "ko": "프롬프트 단어 입력(트리거 단어/프롬프트/부정 프롬프트)",
+    "zh_CN": "输入你的提示词 (触发词/提示词/反向提示词)"
+  },
+  "Categorys of prompt": {
+    "zh_TW": "分類",
+    "ja": "カテゴリー",
+    "ko": "카테고리",
+    "zh_CN": "分类"
+  },
+  "Apply data": {
+    "zh_TW": "確定",
+    "ja": "確認する",
+    "ko": "확인하다",
+    "zh_CN": "确定"
+  },
+  "Suggested weight": {
+    "zh_TW": "建議權重",
+    "ja": "推奨モデル重量",
+    "ko": "권장 모델 무게",
+    "zh_CN": "建议权重"
+  },
+  "Sorting": {
+    "zh_TW": "打開排序功能選單",
+    "ja": "ソート機能メニューを開く",
+    "ko": "정렬 기능 메뉴 열기",
+    "zh_CN": "打开排序功能选单"
+  },
+  "Negative prompt: please enter Y if this prompt is a negative prompt.": {
+    "zh_TW": "反向提示詞: 為反向提詞時請輸入Y",
+    "ja": "ネガティブプロンプト: このプロンプトが否定的なプロンプトである場合は、Y を入力してください。",
+    "ko": "부정적인 프롬프트: 이 프롬프트가 부정적인 프롬프트인 경우 Y를 입력하십시오.",
+    "zh_CN": "反向提示词: 为反向提词时请输入Y"
+  },
+  "Translate prompt words into:": {
+    "zh_TW": "將提示詞翻譯為:",
+    "ja": "プロンプトの単語を他の言語に翻訳する: ",
+    "ko": "프롬프트 단어를 다른 언어로 번역: ",
+    "zh_CN": "将提示词翻译为: "
+  },
+  "Easy editing": {
+    "zh_TW": "簡易編輯",
+    "ja": "簡単な編集",
+    "ko": "쉬운 편집",
+    "zh_CN": "一键编辑"
+  },
+  "Advanced editing": {
+    "zh_TW": "進階編輯",
+    "ja": "高度な編集",
+    "ko": "고급 편집",
+    "zh_CN": "高级编辑"
+  },
+  "Additional description": {
+    "zh_TW": "額外描述",
+    "ja": "追加説明",
+    "ko": "추가 설명",
+    "zh_CN": "额外描述"
+  },
+  "Additional description name": {
+    "zh_TW": "額外描述名稱",
+    "ja": "追加説明の名前",
+    "ko": "추가 설명의 이름",
+    "zh_CN": "额外描述名称"
+  },
+  "Description prompt": {
+    "zh_TW": "描述提詞",
+    "ja": "プロンプト",
+    "ko": "설명 프롬프트",
+    "zh_CN": "描述提词"
+  },
+  "Dedicated negative prompt": {
+    "zh_TW": "專用反向提詞",
+    "ja": "専用の否定プロンプト",
+    "ko": "전용 네거티브 프롬프트",
+    "zh_CN": "专用反向提词"
+  },
+  "Dedicated negative prompt name": {
+    "zh_TW": "專用反向提詞名稱",
+    "ja": "専用ネガティブプロンプトの名前",
+    "ko": "전용 네거티브 프롬프트의 이름",
+    "zh_CN": "专用反向提词名称"
+  },
+  "EX: draw a Mahiro": {
+    "zh_TW": "EX: 叫出真尋",
+    "ja": "EX: まひろを描く",
+    "ko": "EX: XXX 그리기",
+    "zh_CN": "EX: 叫出真寻"
+  },
+  "EX: Characteristics of Mahiro": {
+    "zh_TW": "EX: 真尋的特徵",
+    "ja": "EX: ひろの特徴",
+    "ko": "EX: XXX 그리기",
+    "zh_CN": "EX: 真寻的特征"
+  },
+  "EX: negative prompt for Mahiro": {
+    "zh_TW": "EX: 真尋反向提詞",
+    "ja": "EX: まひろに対する否定的なプロンプト",
+    "ko": "EX: XXX에 대한 부정적인 프롬프트",
+    "zh_CN": "EX: 真寻反向提词"
+  },
+  "Type": {
+    "zh_TW": "類別",
+    "ja": "タイプ",
+    "ko": "유형",
+    "zh_CN": "类别"
+  },
+  "Name": {
+    "zh_TW": "名稱",
+    "ja": "名前",
+    "ko": "이름",
+    "zh_CN": "名称"
+  },
+  "Model Path": {
+    "zh_TW": "模型路徑",
+    "ja": "モデルパス",
+    "ko": "모델 경로",
+    "zh_CN": "模型路径"
+  },
+  "name": {
+    "zh_TW": "名稱",
+    "ja": "名前",
+    "ko": "이름",
+    "zh_CN": "名称"
+  },
+  "Trigger Word": {
+    "zh_TW": "模型觸發詞",
+    "ja": "トリガーワード",
+    "ko": "트리거 단어",
+    "zh_CN": "模型触发词"
+  },
+  "Categorys": {
+    "zh_TW": "種類",
+    "ja": "カテゴリー",
+    "ko": "카테고리",
+    "zh_CN": "种类"
+  },
+  "Negative prompt": {
+    "zh_TW": "反向提詞",
+    "ja": "ネガティブプロンプト",
+    "ko": "부정적인 프롬프트",
+    "zh_CN": "反向提词"
+  },
+  "Remove duplicate prompts": {
+    "zh_TW": "移除重複的提詞",
+    "ja": "重複するプロンプトを削除する",
+    "ko": "중복 프롬프트 제거",
+    "zh_CN": "移除重复的提词"
+  },
+  "Remove empty prompts": {
+    "zh_TW": "移除空白的提詞",
+    "ja": "空のプロンプトを削除する",
+    "ko": "빈 프롬프트 제거",
+    "zh_CN": "移除空白的提词"
+  },
+  "Sort Order": {
+    "zh_TW": "排序方式",
+    "ja": "ソート順",
+    "ko": "정렬 순서",
+    "zh_CN": "排序方式"
+  },
+  "Sort by title": {
+    "zh_TW": "依標題排序",
+    "ja": "タイトル順に並べ替える",
+    "zh_CN": "依标题排序"
+  },
+  "Sort by prompt": {
+    "zh_TW": "依提詞排序",
+    "ja": "プロンプトで並べ替える",
+    "ko": "프롬프트별로 정렬",
+    "zh_CN": "依提词排序"
+  },
+  "Message": {
+    "zh_TW": "訊息",
+    "ja": "メッセージ",
+    "ko": "메시지",
+    "zh_CN": "消息"
+  },
+  "Batch import prompts": {
+    "zh_TW": "批次導入提詞",
+    "ja": "プロンプトの一括インポート",
+    "ko": "프롬프트 일괄 가져 오기",
+    "zh_CN": "批量导入提词"
+  },
+  "Read prompts from text boxes": {
+    "zh_TW": "從文字框讀取提詞",
+    "ja": "テキストボックスからプロンプトを読み取る",
+    "ko": "텍스트 상자에서 프롬프트 읽기",
+    "zh_CN": "从文字框读取提词"
+  },
+  "Download configuration files from CivitAI": {
+    "zh_TW": "從CivitAI抓取設定檔",
+    "ja": "CivitAIから設定ファイルをダウンロードする",
+    "ko": "CivitAI에서 설정 파일 다운로드",
+    "zh_CN": "从CivitAI抓取配置文件"
+  },
+  "Enter prompts (one line for one trigger words)": {
+    "zh_TW": "輸入提詞 (一行為一組)",
+    "ja": "プロンプトを入力する(1行に1つのトリガーワード)",
+    "ko": "프롬프트 입력 (한 줄에 하나의 트리거 단어)",
+    "zh_CN": "输入提词 (一行为一组)"
+  },
+  "Read failed, no model selected.": {
+    "zh_TW": "讀取失敗,無選擇的模型。",
+    "ja": "読み込みに失敗しました、モデルが選択されていません。",
+    "ko": "로드 실패, 모델이 선택되지 않았습니다.",
+    "zh_CN": "读取失败,无选择的模型。"
+  },
+  "CivitAI does not have this model, or it has been taken down.": {
+    "zh_TW": "CivitAI沒有這個模型,或者已被下架。",
+    "ja": "CivitAIにはこのモデルがないか、取り下げられました。",
+    "ko": "CivitAI에는이 모델이 없거나 다운되었습니다.",
+    "zh_CN": "CivitAI没有这个模型,或者已被下架。"
+  },
+  "Successfully downloaded model data from CivitAI.": {
+    "zh_TW": "已成功從CivitAI抓取模型資料。",
+    "ja": "CivitAIからモデルデータを正常にダウンロードしました。",
+    "ko": "CivitAI에서 모델 데이터를 성공적으로 다운로드했습니다.",
+    "zh_CN": "已成功从CivitAI抓取模型资料。"
+  },
+  "Save failed, no model selected.": {
+    "zh_TW": "儲存失敗,無選擇的模型。",
+    "ja": "モデルが選択されていませんので、保存に失敗しました。",
+    "zh_CN": "保存失败,无选择的模型。"
+  },
+  "Load Successful": {
+    "zh_TW": "讀取成功",
+    "ja": "読み込み成功",
+    "ko": "로드 성공",
+    "zh_CN": "读取成功"
+  },
+  "Save complete": {
+    "zh_TW": "儲存完成",
+    "ja": "保存完了",
+    "ko": "저장 완료",
+    "zh_CN": "保存完成"
+  },
+  "Model not loaded.": {
+    "zh_TW": "未載入模型。",
+    "ja": "モデルが読み込まれていません。",
+    "ko": "모델이 로드되지 않았습니다.",
+    "zh_CN": "未加载模型。"
+  },
+  "HTTP ERROR": {
+    "zh_TW": "HTTP錯誤",
+    "ja": "HTTPエラー",
+    "ko": "HTTP 오류",
+    "zh_CN": "HTTP错误"
+  },
+  "hash calculate failed": {
+    "zh_TW": "hash計算失敗",
+    "ja": "ハッシュの計算に失敗しました。",
+    "ko": "해시 계산 실패",
+    "zh_CN": "hash计算失败"
+  },
+  "fail to load data": {
+    "zh_TW": "資料讀取失敗",
+    "ja": "データの読み込みに失敗しました。",
+    "ko": "데이터 로드 실패",
+    "zh_CN": "资料读取失败"
+  },
+  "error, content from CivitAI is None": {
+    "zh_TW": "錯誤,CivitAI傳回資料為空",
+    "ja": "エラー、CivitAIからのコンテンツがありません。",
+    "ko": "오류, CivitAI에서 반환 된 콘텐츠가 없습니다.",
+    "zh_CN": "错误,CivitAI传回资料为空"
+  },
+  "error, Can not connect to CivitAI.": {
+    "zh_TW": "錯誤,無法連線到CivitAI",
+    "ja": "エラー、CivitAIに接続できません。",
+    "ko": "오류, CivitAI에 연결할 수 없습니다.",
+    "zh_CN": "错误,无法连线到CivitAI"
+  },
+  "Successfully load trigger word from Dreambooth model.": {
+    "zh_TW": "已成功從Dreambooth模型抓取觸發詞資料。",
+    "ja": "Dreamboothモデルからトリガーワードを正常に読み込みました。",
+    "ko": "Dreambooth 모델에서 트리거 단어를 성공적으로 로드했습니다.",
+    "zh_CN": "已成功从Dreambooth模型抓取触发词资料。"
+  },
+  "trigger word not found.": {
+    "zh_TW": "找不到模型觸發詞",
+    "ja": "トリガーワードが見つかりません。",
+    "ko": "트리거 단어를 찾을 수 없습니다.",
+    "zh_CN": "找不到模型触发词"
+  },
+  "Show debug message": {
+    "zh_TW": "顯示除錯Debug資訊。",
+    "ja": "デバッグメッセージを表示",
+    "zh_CN": "显示调试Debug信息。"
+  },
+  "Load trigger words from Dreambooth model": {
+    "zh_TW": "從Dreambooth模型抓取觸發詞",
+    "ja": "Dreamboothモデルからトリガーワードを読み込む",
+    "zh_CN": "从Dreambooth模型抓取触发词"
+  },
+  "Force touch mode": {
+    "zh_TW": "使用觸控模式",
+    "ja": "タッチモードを強制する",
+    "zh_CN": "使用触控模式"
+  },
+  "Model params": {
+    "zh_TW": "建議的模型參數",
+    "ja": "モデルのパラメーター",
+    "zh_CN": "建议的模型参数"
+  }
+}
+
+def load_localization(current_localization_name):
+    global local_data
+    global local_id
+    local_id = current_localization_name
+    fn = localizations.get(current_localization_name, None)
+    if fn is not None:
+        try:
+            with open(fn, "r", encoding="utf8") as file:
+                local_data = json.load(file)
+        except Exception:
+            print(f"Error loading localization from {fn}")
+
+def get_localize(msg):
+    if msg in local_data.keys():
+        return msg
+    if msg in my_localization_data.keys():
+        if local_id in my_localization_data[msg].keys():
+            return my_localization_data[msg][local_id]
+        prefix_id = re.sub(r"[_\-\s]+","_",local_id).split("_")[0]
+        if prefix_id in my_localization_data[msg].keys():
+            return my_localization_data[msg][prefix_id]
+    return msg
+
+def get_localize_message(msg):
+    if msg in local_data.keys():
+        return local_data[msg]
+    if msg in my_localization_data.keys():
+        if local_id in my_localization_data[msg].keys():
+            return my_localization_data[msg][local_id]
+        prefix_id = re.sub(r"[_\-\s]+","_",local_id).split("_")[0]
+        if prefix_id in my_localization_data[msg].keys():
+            return my_localization_data[msg][prefix_id]
+    return msg

+ 263 - 0
scripts/loraprompt_lib/loraprompttool.py

@@ -0,0 +1,263 @@
+import os
+import requests
+from . import libdata
+from . import util
+from . import model
+from . import localization
+
+source_filename = "loraprompttool"
+
+def load_model_info_by_model_path(model_type, model_path):
+    """load model information JSON file by model path
+
+    Parameters
+    ----------
+    model_type
+        model type, you can choose between Checkpoint, TextualInversion, Hypernetwork and LORA
+    model_path
+        model path
+        
+    Returns
+    -------
+    JSON
+        model information JSON file content
+    """
+    util.console.debug(f"Load model info of {model_path} in {model_type}")
+    if model_type not in libdata.folders.keys():
+        util.console.error("unknow model type: " + model_type, f"{source_filename}.load_model_info_by_model_path")
+        return
+    
+    # model_path = subfolderpath + model name + ext. And it always start with a / even there is no sub folder
+    base, ext = os.path.splitext(model_path)
+    model_info_base = base
+    if base[:1] == "/":
+        model_info_base = base[1:]
+
+    finded_file = False
+    first_path = ""
+    model_info_filepath = ""
+    model_folder = libdata.folders[model_type]
+    for info_ext in libdata.info_ext:
+        if finded_file:
+            break
+        model_info_filename = model_info_base + info_ext
+        model_info_filepath = os.path.join(model_folder, model_info_filename)
+        if first_path == "":
+            first_path = model_info_filepath
+        if not os.path.isfile(model_info_filepath):
+            continue
+        finded_file = True
+    if not finded_file:
+        util.console.log("Can not find model info file: " + first_path)
+        return
+    if model_info_filepath == "":
+        util.console.error("Error load info file!", f"{source_filename}.load_model_info_by_model_path")
+        return
+    return model.load_model_info(model_info_filepath)
+
+def check_model_state(model_info):
+    if model_info is None:
+        return "empty"
+    if "loading state" in model_info.keys():
+        return model_info["loading state"]
+    return "ok"
+
+def get_model_error_message(model_info):
+    model_state = check_model_state(model_info)
+    if model_state == "ok":
+        return localization.get_localize_message("Load Successful")
+    elif model_state == "error":
+        if "message" in model_info.keys():
+            if model_info["message"] == "HTTP ERROR":
+                status_code = int(model_info["status code"])
+                return localization.get_localize_message("HTTP ERROR") + " : " +\
+                    status_code + " " +\
+                    localization.get_localize_message(libdata.http_state_codes[status_code])
+            if model_info["message"] == "fail to load data":
+                return localization.get_localize_message(model_info["message"]) + "\n" +\
+                    localization.get_localize_message("response") + ":\n" +\
+                    model_info["response"]
+            return localization.get_localize_message(model_info["message"])
+        return localization.get_localize_message("Error")
+    return localization.get_localize_message("unknown")
+
+def sent_cors_request(url):
+    r : requests.Response
+    try:
+        r = requests.get(url, headers=libdata.def_headers, proxies=libdata.proxies)
+    except Exception as e:
+        return {
+            "loading state":"error",
+            "message": "error, Can not connect to url."
+        }
+    if not r.ok:
+        util.console.error("Get error code: " + str(r.status_code), f"{source_filename}.sent_cors_request")
+        util.console.log(r.text)
+        return {
+            "loading state":"error",
+            "message": "HTTP ERROR",
+            "status code": r.status_code
+        }
+    return {
+        "loading state":"ok",
+        "message": r.text
+    }
+
+def get_model_info_by_hash(hash:str):
+    """using the model hash to find model information, this will connect to civitAI
+
+    Parameters
+    ----------
+    hash : str
+        the model hash
+
+    Returns
+    -------
+    JSON
+        model information JSON file content
+    """
+    if not hash:
+        util.console.error("hash is empty", f"{source_filename}.get_model_info_by_hash")
+        return {
+            "loading state":"error",
+            "message": "hash calculate failed"
+        }
+    r : requests.Response
+    try:
+        r = requests.get(libdata.civitai_apis["hash"]+hash, headers=libdata.def_headers, proxies=libdata.proxies)
+    except Exception as e:
+        return {
+            "loading state":"error",
+            "message": "error, Can not connect to CivitAI."
+        }
+    if not r.ok:
+        if r.status_code == 404:
+            # this is not a civitai model
+            util.console.log("Civitai does not have this model")
+            return {
+                "loading state":"error",
+                "message": "CivitAI does not have this model, or it has been taken down."
+            }
+        else:
+            util.console.error("Get error code: " + str(r.status_code), f"{source_filename}.get_model_info_by_hash")
+            util.console.log(r.text)
+            return {
+                "loading state":"error",
+                "message": "HTTP ERROR",
+                "status code": r.status_code
+            }
+
+    # try to get content
+    content = None
+    try:
+        content = r.json()
+    except Exception as e:
+        util.console.error("Parse response json failed", f"{source_filename}.get_model_info_by_hash")
+        util.console.log(str(e))
+        util.console.log("response:")
+        util.console.log(r.text)
+        return {
+            "loading state":"error",
+            "message": "fail to load data",
+            "response": r.text
+        }
+    
+    if not content:
+        util.console.error("error, content from civitai is None", f"{source_filename}.get_model_info_by_hash")
+        return {
+            "loading state":"error",
+            "message": "error, content from CivitAI is None"
+        }
+    
+    return content
+
+def load_model_info_from_Civitai(model_type, model_path):
+    """load model information from CivitAI
+
+    Parameters
+    ----------
+    model_type
+        model type, you can choose between Checkpoint, TextualInversion, Hypernetwork and LORA
+    model_path
+        model path
+
+    Returns
+    -------
+    JSON
+        model information JSON file content
+    """
+    util.console.debug(f"Load model info of {model_path} in {model_type}")
+    if model_type not in libdata.folders.keys():
+        util.console.error("unknow model type: " + model_type, f"{source_filename}.load_model_info_from_Civitai")
+        return
+
+    model_exts = ("",)
+    if f"{model_path}".find(".") < 0:
+        model_exts = libdata.exts
+
+    model_base = model_path
+    if model_path[:1] == "/" or model_path[:1] == "\\":
+        model_base = model_path[1:]
+
+    first_model_filename = None
+    model_folder = libdata.folders[model_type]
+    for ext in model_exts:
+        model_filename = model_base
+        model_filepath = os.path.join(model_folder, model_filename) + ext
+        if first_model_filename is None:
+            first_model_filename = os.path.join(model_folder, model_filename)
+        if not os.path.isfile(model_filepath):
+            continue
+        break
+    if not os.path.isfile(model_filepath):
+        util.console.debug("Can not find model file: " + first_model_filename)
+        return
+    hash = util.gen_file_sha256(model_filepath)
+    return get_model_info_by_hash(hash)
+
+
+def save_model_info_by_model_path(model_info, model_type, model_path):
+    """save model information JSON file by model path
+
+    Parameters
+    ----------
+    model_type
+        model type, you can choose between Checkpoint, TextualInversion, Hypernetwork and LORA
+    model_path
+        model path
+    """
+    util.console.debug(f"Write model info of {model_path} in {model_type}")
+    if model_type not in libdata.folders.keys():
+        util.console.error("unknow model type: " + model_type, f"{source_filename}.save_model_info_by_model_path")
+        return
+    
+    # model_path = subfolderpath + model name + ext. And it always start with a / even there is no sub folder
+    base, ext = os.path.splitext(model_path)
+    model_info_base = base
+    if base[:1] == "/" or base[:1] == "\\":
+        model_info_base = base[1:]
+
+    finded_file = False
+    not_file = False
+    first_path = ""
+    model_info_filepath = ""
+    model_folder = libdata.folders[model_type]
+    for info_ext in libdata.info_ext:
+        if finded_file:
+            break
+        not_file = False
+        model_info_filename = model_info_base + info_ext
+        model_info_filepath = os.path.join(model_folder, model_info_filename)
+        if first_path == "":
+            first_path = model_info_filepath
+        if os.path.exists(model_info_filepath):
+            if not os.path.isfile(model_info_filepath):
+                not_file = True
+                continue
+            finded_file = True
+    if not_file:
+        util.console.error("not a file: " + first_path, f"{source_filename}.save_model_info_by_model_path")
+        return
+    if not finded_file:
+        model_info_filepath = first_path
+    model.write_model_info(model_info_filepath, model_info)

+ 96 - 0
scripts/loraprompt_lib/model.py

@@ -0,0 +1,96 @@
+import os
+import re
+import json
+from . import util
+from . import libdata
+from modules import shared
+
+source_filename = "model"
+
+def get_db_models():
+    rgx = re.compile(r"\[.*\]")
+    output = [""]
+    try:
+        out_dir = libdata.dreambooth_models_path
+        if os.path.exists(out_dir):
+            for item in os.listdir(out_dir):
+                check_path = os.path.join(out_dir, item)
+                if os.path.isdir(check_path) and not rgx.search(item):
+                    json_path = os.path.join(check_path, libdata.dreambooth_setting_file_name)
+                    if not os.path.isfile(json_path):
+                        continue
+                    output.append(item)
+    except Exception:
+        pass
+    return output
+
+def get_db_model_setting(model_name):
+    try:
+        model_path = os.path.join(libdata.dreambooth_models_path, model_name, libdata.dreambooth_setting_file_name)
+        return load_model_info(model_path)
+    except Exception as e1:
+        return
+
+def get_custom_model_folder():
+    """load model folder by user setting"""
+    util.console.log("Get Custom Model Folder")
+
+    if shared.cmd_opts.embeddings_dir and os.path.isdir(shared.cmd_opts.embeddings_dir):
+        libdata.folders["ti"] = shared.cmd_opts.embeddings_dir
+
+    if shared.cmd_opts.hypernetwork_dir and os.path.isdir(shared.cmd_opts.hypernetwork_dir):
+        libdata.folders["hyper"] = shared.cmd_opts.hypernetwork_dir
+
+    if shared.cmd_opts.ckpt_dir and os.path.isdir(shared.cmd_opts.ckpt_dir):
+        libdata.folders["ckp"] = shared.cmd_opts.ckpt_dir
+
+    if hasattr(shared.cmd_opts, "lora_dir"):
+        if shared.cmd_opts.lora_dir and os.path.isdir(shared.cmd_opts.lora_dir):
+            libdata.folders["lora"] = shared.cmd_opts.lora_dir
+
+    if hasattr(shared.cmd_opts, "lyco_dir"):
+        if shared.cmd_opts.lyco_dir and os.path.isdir(shared.cmd_opts.lyco_dir):
+            libdata.folders["lyco"] = shared.cmd_opts.lyco_dir
+
+def write_model_info(path, model_info):
+    """write model JSON data
+
+    Parameters
+    ----------
+    path
+        file path to write
+    model_info
+        data to write
+    """
+    util.console.log("Write model info to file: " + path)
+    with open(os.path.realpath(path), 'w') as f:
+        f.write(json.dumps(model_info, indent=4))
+
+
+def load_model_info(path):
+    """load model JSON data
+
+    Parameters
+    ----------
+    path
+        file path to load
+        
+    Returns
+    -------
+    JSON
+        loadded JSON data
+    """
+    model_info = None
+    try:
+        with open(os.path.realpath(path), 'r') as f:
+            try:
+                model_info = json.load(f)
+            except Exception as e:
+                util.console.error("Selected file is not json: " + path, f"{source_filename}.load_model_info")
+                util.console.log(e)
+                return
+    except Exception as e1:
+        util.console.error("file not found: " + path, f"{source_filename}.load_model_info")
+        return
+    return model_info
+

+ 48 - 0
scripts/loraprompt_lib/setting.py

@@ -0,0 +1,48 @@
+import os
+import json
+from . import libdata
+
+source_filename = "setting"
+
+data = {
+    "debug": False,
+    "touch_mode": False
+}
+default_setting = {
+    "debug": False,
+    "touch_mode": False
+}
+
+def load_setting():
+    global data
+    setting_data = None
+    try:
+        with open(os.path.realpath(os.path.join(libdata.extension_path, libdata.setting_file_name)), 'r') as f:
+            try:
+                setting_data = json.load(f)
+            except Exception as e:
+                return
+    except Exception as e1:
+        return
+    if not setting_data:
+        return
+    data = setting_data
+
+def save_setting():
+    try:
+        with open(os.path.realpath(os.path.join(libdata.extension_path, libdata.setting_file_name)), 'w') as f:
+            f.write(json.dumps(data, indent=4))
+    except Exception as e1:
+        return
+
+def get_setting(key):
+    if key in data.keys():
+        return data[key]
+    return default_setting[key]
+
+def set_setting(key, value):
+    global data
+    data[key] = value
+
+def set_touch_mode(value):
+    set_setting('touch_mode', value)

+ 200 - 0
scripts/loraprompt_lib/util.py

@@ -0,0 +1,200 @@
+import os
+import io
+import hashlib
+from . import extension_data
+from . import setting
+
+source_filename = "util"
+
+#習慣用console.log就宣告一個console.log來用...
+class Console:
+    """
+    A class used to output the extension message to console
+
+    Attributes
+    ----------
+    package_name : str
+        extension name.
+
+    Methods
+    -------
+    log(msg : str)
+        outputs a message to the python console.
+    """
+    def __init__(self, package_name : str):
+        """
+        Parameters
+        ----------
+        package_name : str
+            set extension name.
+        """
+        self.package_name = package_name
+        self.debug_enabled = True
+
+    def log(self, msg):
+        """outputs a message to the python console.
+
+        Parameters
+        ----------
+        msg : any
+            message to output.
+        """
+        print(f"[{self.package_name}] {msg}")
+
+    def error(self, msg, func=None):
+        """outputs a error message to the python console.
+
+        Parameters
+        ----------
+        msg : any
+            message to output.
+        """
+        self.log(f" [Error] {msg}" + ("" if func is None else f", in {func}"))
+
+    def debug(self, msg):
+        """outputs a debug message to the python console.
+
+        Parameters
+        ----------
+        msg : any
+            message to output.
+        """
+        if self.debug_enabled:
+            self.log(f" [Debug] {msg}")
+
+    def start(self, process):
+        """outputs a process start message to the python console.
+
+        Parameters
+        ----------
+        process : any
+            process name.
+        """
+        self.debug(f"start process : {process}")
+
+    def end(self, process):
+        """outputs a process end message to the python console.
+
+        Parameters
+        ----------
+        process : any
+            process name.
+        """
+        self.debug(f"end process : {process}")
+
+console = Console(extension_data.extension_name)
+
+def set_debug_logging_state(value):
+    setting.set_setting('debug', value)
+    console.debug_enabled = value
+
+def load_json_number(input) -> float:
+    """a safe way to load a jumber from JSON
+
+    Parameters
+    ----------
+    input : any
+        item from JSON object
+
+    Returns
+    -------
+    float
+        a float value equivalent to JSON object
+    """
+    try:
+        return float(str(input))
+    except Exception:
+        return 0
+
+def read_chunks(file, size=io.DEFAULT_BUFFER_SIZE):
+    """Yield pieces of data from a file-like object until EOF."""
+    while True:
+        chunk = file.read(size)
+        if not chunk:
+            break
+        yield chunk
+
+def get_subfolders(folder:str) -> list:
+    """get subfolder list
+
+    Parameters
+    ----------
+    folder : str
+        The directory to look for subdirectories
+
+    Returns
+    -------
+    list
+        list of subdirectories
+    """
+    console.debug("Get subfolder for: " + folder)
+    if not folder:
+        console.error("folder can not be None", f"{source_filename}.get_subfolders")
+        return
+    
+    if not os.path.isdir(folder):
+        console.error("path is not a folder", f"{source_filename}.get_subfolders")
+        return
+    
+    prefix_len = len(folder)
+    subfolders = []
+    for root, dirs, files in os.walk(folder, followlinks=True):
+        for dir in dirs:
+            full_dir_path = os.path.join(root, dir)
+            # get subfolder path from it
+            subfolder = full_dir_path[prefix_len:]
+            subfolders.append(subfolder)
+
+    return subfolders
+
+def get_relative_path(item_path:str, parent_path:str) -> str:
+    """get relative path
+
+    Parameters
+    ----------
+    item_path : str
+        relative path to get
+    parent_path : str
+        relative to parent path
+
+    Returns
+    -------
+    path
+        the result path
+    """
+    if not item_path:
+        return ""
+    if not parent_path:
+        return ""
+    if not item_path.startswith(parent_path):
+        return item_path
+
+    relative = item_path[len(parent_path):]
+    if relative[:1] == "/" or relative[:1] == "\\":
+        relative = relative[1:]
+
+    return relative
+
+def gen_file_sha256(filname) -> str:
+    """get relative path
+
+    Parameters
+    ----------
+    filname : path
+        path to the file for sha256 calculation
+
+    Returns
+    -------
+    str
+        sha256 result
+    """
+    blocksize=1 << 20
+    h = hashlib.sha256()
+    length = 0
+    with open(os.path.realpath(filname), 'rb') as f:
+        for block in read_chunks(f, size=blocksize):
+            length += len(block)
+            h.update(block)
+
+    hash_value =  h.hexdigest()
+    return hash_value

+ 43 - 0
style.css

@@ -0,0 +1,43 @@
+.lora-context-menu {
+    position: fixed;
+    z-index: 10000;
+    background: #1b1a1a;
+    border-radius: 5px;
+    transform: scale(0);
+    transform-origin: top left;
+}
+
+.lora-context-menu.visible {
+    transform: scale(1);
+    transition: transform 200ms ease-in-out;
+}
+
+.lora-context-menu .item {
+    padding: 8px 10px;
+    font-size: 15px;
+    color: #eee;
+    cursor: pointer;
+    border-radius: inherit;
+}
+
+.lora-context-menu .hritem {
+    color: #eee;
+    border-radius: inherit;
+}
+
+.lora-context-menu .item:hover {
+    background: #343434;
+}
+
+.lorahelp-touch-icon {
+    position: absolute;
+    top: 0;
+    right: 0;
+    background: rgba(0,0,0,0.5);
+    padding: 0 6px 0 6px;
+    color: white;
+}
+
+#translate_language_selector option {
+    background-color: var(--background-fill-primary);
+}

Some files were not shown because too many files changed in this diff