bugfix for `GM_getValue()`, as suggested by https://github.com/qsniyg/
[guerillascript.git] / chrome / guerilla-newpkg.xul
blobc8cc59dd84527f1e787274009b9c9f7974f19d84
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
3 <dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
4 id="gsnewpkgui"
5 windowtype="guerilla:newpkg"
6 width="600"
7 buttons="accept,cancel"
8 buttonlabelaccept="OK"
9 buttonlabelcancel="Cancel"
10 ondialogaccept="onAccept();"
11 ondialogcancel="onCancel();"
12 onload="onLoad();">
13 <vbox id="mainvbox">
14 <grid>
15 <columns>
16 <column />
17 <column flex="1"/>
18 </columns>
19 <rows>
20 <row align="center">
21 <label control="name" value="Package name:" accesskey="n" style="text-align:right" />
22 <textbox id="name" type="text" tooltiptext="Internal package name (no spaces, please)" flex="1"/>
23 </row>
24 <row align="center">
25 <label control="url" value="Package url:" accesskey="u" style="text-align:right" />
26 <textbox id="url" type="text" tooltiptext="URL to download the package" flex="1"/>
27 </row>
28 </rows>
29 </grid>
30 </vbox>
31 <script type="application/javascript"><![CDATA[
32 function onLoad () {
33 window.sizeToContent();
34 if (typeof(window.arguments[0].name) === "string") {
35 document.getElementById("name").value = window.arguments[0].name;
37 if (typeof(window.arguments[0].url) === "string") {
38 document.getElementById("url").value = window.arguments[0].url;
42 function onCancel () {
43 window.arguments[0].closeReason = "cancel";
46 function onAccept () {
47 let name = document.getElementById("name").value.replace(/^\s+/, "").replace(/\s+$/, "");
48 if (name.length === 0 || /\s/.test(name)) {
49 alert("Invalid package name!");
50 throw new Error();
52 if (window.arguments[0].isPkgExists(name)) {
53 alert("Duplicate package name!");
54 throw new Error();
56 let url = document.getElementById("url").value.replace(/^\s+/, "").replace(/\s+$/, "");
57 if (url.length === 0 || !(/^https?:/.test(url))) {
58 alert("Invalid package URL!");
59 throw new Error();
61 let pname = window.arguments[0].isUrlExists(url);
62 if (pname) {
63 alert("Duplicate package url; package '"+pname+"' already using it!");
64 throw new Error();
66 window.arguments[0].name = name;
67 window.arguments[0].url = url;
68 window.arguments[0].closeReason = "accept";
70 ]]></script>
71 </dialog>