コード例 #1
0
        public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
        {
            string pattern = parameters[0];

            if (!string.IsNullOrEmpty(pattern))
            {
                Match match = Regex.Match(parser.ResponseInfo.ResponseText, pattern);

                if (match.Success)
                {
                    if (parameters.Length > 1)
                    {
                        string group = parameters[1];

                        if (!string.IsNullOrEmpty(group))
                        {
                            if (int.TryParse(group, out int groupNumber))
                            {
                                return(match.Groups[groupNumber].Value);
                            }
                            else
                            {
                                return(match.Groups[group].Value);
                            }
                        }
                    }

                    return(match.Value);
                }
            }

            return(null);
        }
コード例 #2
0
        public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
        {
            // https://www.w3schools.com/xml/xpath_syntax.asp
            string input, xpath;

            if (parameters.Length > 1)
            {
                // {xml:input|xpath}
                input = parameters[0];
                xpath = parameters[1];
            }
            else
            {
                // {xml:xpath}
                input = parser.ResponseInfo.ResponseText;
                xpath = parameters[0];
            }

            if (!string.IsNullOrEmpty(input) && !string.IsNullOrEmpty(xpath))
            {
                using (StringReader sr = new StringReader(input))
                {
                    XPathDocument  doc  = new XPathDocument(sr);
                    XPathNavigator nav  = doc.CreateNavigator();
                    XPathNavigator node = nav.SelectSingleNode(xpath);

                    if (node != null)
                    {
                        return(node.Value);
                    }
                }
            }

            return(null);
        }
コード例 #3
0
        public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
        {
            string title        = "ShareX - Prompt";
            string defaultValue = "";

            if (parameters.Length > 0)
            {
                title = parameters[0];

                if (parameters.Length > 1)
                {
                    defaultValue = parameters[1];
                }
            }

            using (InputBox inputBox = new InputBox(title, defaultValue))
            {
                if (inputBox.ShowDialog() == DialogResult.OK)
                {
                    return(inputBox.InputText);
                }
            }

            return(defaultValue);
        }
コード例 #4
0
        private void CustomUploaderSyntaxHighlight(RichTextBox rtb)
        {
            string text = rtb.Text;

            if (!string.IsNullOrEmpty(text))
            {
                int start  = rtb.SelectionStart;
                int length = rtb.SelectionLength;
                rtb.BeginUpdate();

                rtb.SelectionStart  = 0;
                rtb.SelectionLength = rtb.TextLength;
                rtb.SelectionColor  = rtb.ForeColor;

                ShareXCustomUploaderSyntaxParser parser = new ShareXCustomUploaderSyntaxParser();

                for (int i = 0; i < text.Length; i++)
                {
                    char c = text[i];

                    if (c == parser.SyntaxStart || c == parser.SyntaxEnd || c == parser.SyntaxParameterStart ||
                        c == parser.SyntaxParameterDelimiter || c == parser.SyntaxEscape)
                    {
                        rtb.SelectionStart  = i;
                        rtb.SelectionLength = 1;
                        rtb.SelectionColor  = Color.Lime;
                    }
                }

                rtb.SelectionStart  = start;
                rtb.SelectionLength = length;
                rtb.EndUpdate();
            }
        }
コード例 #5
0
        public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
        {
            // https://goessner.net/articles/JsonPath/
            string input, jsonPath;

            if (parameters.Length > 1)
            {
                // {json:input|jsonPath}
                input    = parameters[0];
                jsonPath = parameters[1];
            }
            else
            {
                // {json:jsonPath}
                input    = parser.ResponseInfo.ResponseText;
                jsonPath = parameters[0];
            }

            if (!string.IsNullOrEmpty(input) && !string.IsNullOrEmpty(jsonPath))
            {
                if (!jsonPath.StartsWith("$."))
                {
                    jsonPath = "$." + jsonPath;
                }

                return((string)JToken.Parse(input).SelectToken(jsonPath));
            }

            return(null);
        }
コード例 #6
0
        public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
        {
            if (parser.URLEncode)
            {
                return(URLHelpers.URLEncode(parser.FileName));
            }

            return(parser.FileName);
        }
コード例 #7
0
        public string GetHttpHomePath()
        {
            string homePath = HttpHomePath.Replace("%host", Host);

            ShareXCustomUploaderSyntaxParser parser = new ShareXCustomUploaderSyntaxParser();

            parser.UseNameParser  = true;
            parser.NameParserType = NameParserType.URL;
            return(parser.Parse(homePath));
        }
コード例 #8
0
        public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
        {
            string text = parameters[0];

            if (!string.IsNullOrEmpty(text))
            {
                return(TranslatorHelper.TextToBase64(text));
            }

            return(null);
        }
コード例 #9
0
        public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
        {
            string[] values = parameters.Where(x => !string.IsNullOrEmpty(x)).ToArray();

            if (values.Length > 0)
            {
                using (ParserSelectForm form = new ParserSelectForm(values))
                {
                    form.ShowDialog();
                    return(form.SelectedText);
                }
            }

            return(null);
        }
コード例 #10
0
        public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
        {
            string input, pattern, group = "";

            if (parameters.Length > 2)
            {
                // {regex:input|pattern|group}
                input   = parameters[0];
                pattern = parameters[1];
                group   = parameters[2];
            }
            else
            {
                // {regex:pattern}
                input   = parser.ResponseInfo.ResponseText;
                pattern = parameters[0];

                if (parameters.Length > 1)
                {
                    // {regex:pattern|group}
                    group = parameters[1];
                }
            }

            if (!string.IsNullOrEmpty(input) && !string.IsNullOrEmpty(pattern))
            {
                Match match = Regex.Match(input, pattern);

                if (match.Success)
                {
                    if (!string.IsNullOrEmpty(group))
                    {
                        if (int.TryParse(group, out int groupNumber))
                        {
                            return(match.Groups[groupNumber].Value);
                        }
                        else
                        {
                            return(match.Groups[group].Value);
                        }
                    }

                    return(match.Value);
                }
            }

            return(null);
        }
コード例 #11
0
        private string ParseSyntax(ResponseInfo responseInfo, string urlSyntax)
        {
            if (responseInfo == null || string.IsNullOrEmpty(urlSyntax))
            {
                return(null);
            }

            ShareXCustomUploaderSyntaxParser parser = new ShareXCustomUploaderSyntaxParser()
            {
                FileName     = "example.png",
                ResponseInfo = responseInfo,
                URLEncode    = true
            };

            return(parser.Parse(urlSyntax));
        }
コード例 #12
0
        public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
        {
            // https://goessner.net/articles/JsonPath/
            string jsonPath = parameters[0];

            if (!string.IsNullOrEmpty(jsonPath))
            {
                if (!jsonPath.StartsWith("$."))
                {
                    jsonPath = "$." + jsonPath;
                }

                return((string)JToken.Parse(parser.ResponseInfo.ResponseText).SelectToken(jsonPath));
            }

            return(null);
        }
コード例 #13
0
 public override string Call(ShareXCustomUploaderSyntaxParser parser, string[] parameters)
 {
     return(RandomFast.Pick(parameters));
 }