Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Pure Paste + Spotify Paste

Description
Pastes the embedded artist/album/song text in Spotify URI's.
Language
C#.net
Minimum Version
Created By
igorb
Contributors
-
Date Created
Aug 19, 2014
Date Last Modified
Aug 19, 2014

Macro Code

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;
      }
  }