Skip to content

Commit 272a57a

Browse files
committed
Added missing GM api alongside documentation.
1 parent ad00098 commit 272a57a

File tree

2 files changed

+191
-5
lines changed

2 files changed

+191
-5
lines changed

CSharpToJavaScript/APIs/JS/Ecma/Number.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ namespace CSharpToJavaScript.APIs.JS
77
public partial class Number : NumberPrototype
88
{
99
public dynamic Value { get; set; }
10+
1011
public static implicit operator Number(double value) { return new Number { Value = value }; }
12+
public static implicit operator Number(int value) { return new Number { Value = value }; }
13+
1114
public static implicit operator double(Number value) { return new Number { Value = value }; }
15+
public static implicit operator int(Number value) { return new Number { Value = value }; }
1216

1317
[To(ToAttribute.FirstCharToLowerCase)]
1418
public static NumberPrototype Prototype { get; } = new();
@@ -24,6 +28,7 @@ public partial class Number : NumberPrototype
2428

2529
public Number() { }
2630
public Number(double value) { }
31+
public Number(int value) { }
2732

2833
[To(ToAttribute.FirstCharToLowerCase)]
2934
public bool IsFinite(double number)

CSharpToJavaScript/APIs/JS/GM.cs

Lines changed: 186 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,236 @@
11
using CSharpToJavaScript.Utils;
22
using System;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
64
using System.Threading.Tasks;
75

86
namespace CSharpToJavaScript.APIs.JS
97
{
8+
/// <summary>
9+
/// <see href="https://wiki.greasespot.net/Greasemonkey_Manual:API">Greasemonkey API</see>
10+
/// </summary>
1011
[To(ToAttribute.Default)]
1112
public partial class GM
1213
{
14+
/// <summary>
15+
///
16+
/// </summary>
1317
public GM() { }
18+
19+
/// <summary>
20+
/// This method deletes an existing name / value pair from storage.
21+
/// See GM.setValue for details regarding the storage of these values.
22+
/// </summary>
23+
/// <remarks>
24+
/// <para><seealso href="https://wiki.greasespot.net/GM.deleteValue"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
25+
/// </remarks>
26+
/// <param name="name">Property name to delete. See GM.setValue for details on what names are valid.</param>
1427
[To(ToAttribute.FirstCharToLowerCase)]
1528
public static void DeleteValue(string name)
1629
{
1730

1831
}
19-
32+
/// <summary>
33+
/// This method retrieves a value that was set with GM.setValue. See GM.setValue for details on the storage of these values.
34+
/// </summary>
35+
/// <remarks>
36+
/// <para><seealso href="https://wiki.greasespot.net/GM.getValue"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
37+
/// </remarks>
38+
/// <param name="name">String The property name to get. See GM.setValue for details.</param>
39+
/// <returns></returns>
2040
[To(ToAttribute.FirstCharToLowerCase)]
2141
public static Task<dynamic> GetValue(string name)
2242
{
2343
return new Task<dynamic>(() => { return 0; });
2444
}
25-
45+
/// <summary>
46+
/// This method allows user script authors to persist simple values across page loads and across origins.
47+
/// Strings, booleans, and integers are currently the only allowed data types.
48+
/// </summary>
49+
/// <remarks>
50+
/// <para><seealso href="https://wiki.greasespot.net/GM.setValue"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
51+
/// </remarks>
52+
/// <param name="name">String The unique (within this script) name for this value. Should be restricted to valid Javascript identifier characters.</param>
53+
/// <param name="value">String, Integer or Boolean Any valid value of these types. Any other type may cause undefined behavior, including crashes.</param>
2654
[To(ToAttribute.FirstCharToLowerCase)]
2755
public static void SetValue(string name, dynamic value)
2856
{
2957

3058
}
31-
59+
/// <summary>
60+
/// This method retrieves an array of preference names that this script has stored. See GM.setValue for details on the storage of these values.
61+
/// </summary>
62+
/// <remarks>
63+
/// <para><seealso href="https://wiki.greasespot.net/GM.listValues"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
64+
/// </remarks>
65+
/// <returns></returns>
3266
[To(ToAttribute.FirstCharToLowerCase)]
3367
public static Task<List<dynamic>> ListValues()
3468
{
3569
return new Task<List<dynamic>>(() => { return new List<dynamic>(); });
3670
}
71+
/// <summary>
72+
/// Given a defined @resource, this method returns it as a URL.
73+
/// Compatibility: Greasemonkey 4.0+
74+
/// </summary>
75+
/// <remarks>
76+
/// <para><seealso href="https://wiki.greasespot.net/GM.getResourceUrl"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
77+
/// </remarks>
78+
/// <param name="resourceName">String The name provided when the @resource was defined, follow that link for valid naming restrictions.</param>
79+
/// <returns>A Promise, rejected on failure and resolved with a String URL on success. Treat the result as opaque string. It will work where you need a URL (for a link or style for CSS, for and img tag, or similar). </returns>
80+
[To(ToAttribute.FirstCharToLowerCase)]
81+
public static Task<string> GetResourceUrl(string resourceName)
82+
{
83+
return new Task<string>(() => { return "string url"; });
84+
}
85+
/// <summary>
86+
/// This method displays a notification to the user, using the underlying browser and operating system's notification mechanism.
87+
/// </summary>
88+
/// <remarks>
89+
/// <para><seealso href="https://wiki.greasespot.net/GM.notification"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
90+
/// </remarks>
91+
/// <param name="text">String The main notification text.</param>
92+
/// <param name="title">String Optional. The title of the notification. If not provided, the title will be "Greasemonkey".</param>
93+
/// <param name="image">String Optional. The URL for an image to display in the dialog. If not provided, the Greasemonkey logo will be used.</param>
94+
/// <param name="onclick">Function Optional. Callback, triggered when the notification window is clicked.</param>
95+
[To(ToAttribute.FirstCharToLowerCase)]
96+
public static void Notification(string text, string title = "", string image = "", Action? onclick = null)
97+
{
3798

99+
}
100+
/// <summary>
101+
/// This method opens the specified URL in a new tab.
102+
/// </summary>
103+
/// <remarks>
104+
/// <para><seealso href="https://wiki.greasespot.net/GM.openInTab"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
105+
/// </remarks>
106+
/// <param name="url">String The URL to navigate the new tab to.</param>
107+
/// <param name="open_in_background">Boolean Optional: force tab to/to not open in a background tab. Default (unspecified) behavior honors Firefox configuration.</param>
38108
[To(ToAttribute.FirstCharToLowerCase)]
39109
public static void OpenInTab(string url, bool open_in_background = false)
40110
{
41111

42112
}
113+
/// <summary>
114+
/// This method allows user scripts to add an item to the User Script Commands menu.
115+
/// Compatibility: Greasemonkey 4.11+
116+
/// </summary>
117+
/// <remarks>
118+
/// <para><seealso href="https://wiki.greasespot.net/GM.registerMenuCommand"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
119+
/// </remarks>
120+
/// <param name="caption">String The caption to display on the menu item.</param>
121+
/// <param name="commandFunc">Function The function to call when this menu item is selected by the user.</param>
122+
/// <param name="accessKey"> String A single character that can be used to select command when the menu is open. It should be a letter in the caption.</param>
123+
[To(ToAttribute.FirstCharToLowerCase)]
124+
public static void RegisterMenuCommand(string caption, Action commandFunc, string accessKey)
125+
{
43126

127+
}
128+
/// <summary>
129+
/// Sets the current contents of the operating system's clipboard.
130+
/// </summary>
131+
/// <remarks>
132+
/// <para><seealso href="https://wiki.greasespot.net/GM.setClipboard"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
133+
/// </remarks>
134+
/// <param name="text">String Any text.</param>
135+
[To(ToAttribute.FirstCharToLowerCase)]
136+
public static void SetClipboard(string text)
137+
{
138+
139+
}
140+
141+
//TODO!
142+
/// <summary>
143+
/// This method performs a similar function to the standard XMLHttpRequest object, but allows these requests to cross the same origin policy boundaries.
144+
/// </summary>
145+
/// <remarks>
146+
/// <para><seealso href="https://wiki.greasespot.net/GM.xmlHttpRequest"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
147+
/// </remarks>
148+
/// <param name="details"></param>
149+
[To(ToAttribute.FirstCharToLowerCase)]
150+
public static void XmlHttpRequest(object details)
151+
{
152+
153+
}
154+
/// <summary>
155+
/// An object that exposes various information about Greasemonkey and the running User Script.
156+
/// Compatibility: Greasemonkey 0.9.16+
157+
/// </summary>
158+
/// <remarks>
159+
/// <para><seealso href="https://wiki.greasespot.net/GM.info"> <em> See also on Greasemonkey Wiki</em> </seealso></para>
160+
/// </remarks>
44161
[To(ToAttribute.FirstCharToLowerCase)]
45162
public static class Info
46163
{
164+
/// <summary>
165+
/// An object containing data about the currently running script. See more detail below.
166+
/// </summary>
47167
[To(ToAttribute.FirstCharToLowerCase)]
48168
public static class Script
49169
{
170+
/// <summary>
171+
/// Possibly empty string.
172+
/// </summary>
173+
[To(ToAttribute.FirstCharToLowerCase)]
174+
public static string Description { get; set; } = string.Empty;
175+
/// <summary>
176+
/// Possibly empty array of strings.
177+
/// </summary>
178+
[To(ToAttribute.FirstCharToLowerCase)]
179+
public static string[] Excludes { get; set; } = Array.Empty<string>();
180+
/// <summary>
181+
/// Possibly empty array of strings.
182+
/// </summary>
183+
[To(ToAttribute.FirstCharToLowerCase)]
184+
public static string[] Includes { get; set; } = Array.Empty<string>();
185+
/// <summary>
186+
/// Possibly empty array of strings.
187+
/// </summary>
188+
[To(ToAttribute.FirstCharToLowerCase)]
189+
public static string[] Matches { get; set; } = Array.Empty<string>();
190+
/// <summary>
191+
/// String.
192+
/// </summary>
193+
[To(ToAttribute.FirstCharToLowerCase)]
194+
public static string Name { get; set; } = string.Empty;
195+
/// <summary>
196+
/// Possibly empty string.
197+
/// </summary>
198+
[Value("namespace")]
199+
public static string Namespace_ { get; set; } = string.Empty;
200+
//TODO!
201+
/// <summary>
202+
/// An object keyed by resource name. Each value is an object with keys name and mimetype and url with string values.
203+
/// </summary>
204+
[To(ToAttribute.FirstCharToLowerCase)]
205+
public static object? Resources { get; set; } = null;
206+
/// <summary>
207+
/// String.
208+
/// </summary>
209+
[Value("run-at")]
210+
public static string RunAt { get; set; } = string.Empty;
211+
/// <summary>
212+
/// Possibly empty string.
213+
/// </summary>
50214
[To(ToAttribute.FirstCharToLowerCase)]
51215
public static string Version { get; set; } = string.Empty;
52216
}
217+
218+
/// <summary>
219+
/// A string, the entire literal Metadata Block (without the delimiters) for the currently running script.
220+
/// </summary>
221+
[To(ToAttribute.FirstCharToLowerCase)]
222+
public static string ScriptMetaStr { get; set; } = string.Empty;
223+
224+
/// <summary>
225+
/// The name of the user script engine handling this script's execution. The string Greasemonkey.
226+
/// </summary>
227+
[To(ToAttribute.FirstCharToLowerCase)]
228+
public static string ScriptHandler { get; set; } = string.Empty;
229+
/// <summary>
230+
/// The version of Greasemonkey, a string e.g. 4.0.
231+
/// </summary>
232+
[To(ToAttribute.FirstCharToLowerCase)]
233+
public static string Version { get; set; } = string.Empty;
53234
}
54235
}
55236
}

0 commit comments

Comments
 (0)