using System;
using System.Windows.Forms;
public static class ClipboardFusionHelper
{
public static string ProcessText(string text)
{
string retVal = text;
bool isHtmlDataOnClipboard = Clipboard.ContainsData(DataFormats.Html);
if (isHtmlDataOnClipboard)
{
string htmlText = Clipboard.GetText(TextDataFormat.Html);
// Spotify link detection:
if (htmlText.ToLower().StartsWith( "version:" ) &&
(htmlText.ToLower().Contains("<a href=\"spotify") ||
htmlText.ToLower().Contains("<a href=\"http://open.spotify.com")))
{
string hrefSubstring = htmlText.Substring(htmlText.IndexOf("<a href", 0, StringComparison.InvariantCultureIgnoreCase));
int indexOfLinkTitle = hrefSubstring.IndexOf('>') + 1; // Index of '>' in the opening <a href> tag + 1.
int indexOfHrefEndtag = hrefSubstring.IndexOf("</a>", 0,StringComparison.InvariantCultureIgnoreCase);
int lengthOfLinkTitle = indexOfHrefEndtag - indexOfLinkTitle; // Obtained by factoring out hrefSubstring.Length in the following statement: hrefSubstring.Length - indexOfLinkTitle - (hrefSubstring.Length - indexOfHrefEndtag);
retVal = hrefSubstring.Substring(indexOfLinkTitle, lengthOfLinkTitle);
// Handle special characters.
retVal = System.Web.HttpUtility.HtmlDecode( retVal );
}
}
BFS.Clipboard.PasteText(retVal);
return retVal;
}
}