Skip to content

Instantly share code, notes, and snippets.

@mikker
Created November 4, 2023 13:53
Show Gist options
  • Save mikker/c847162db0ade5631053f68c52f60936 to your computer and use it in GitHub Desktop.
Save mikker/c847162db0ade5631053f68c52f60936 to your computer and use it in GitHub Desktop.

Revisions

  1. mikker created this gist Nov 4, 2023.
    12 changes: 12 additions & 0 deletions action.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    {
    "always_run_in_app" : false,
    "icon" : {
    "color" : "deep-purple",
    "glyph" : "magic"
    },
    "name" : "Add to Newsletters",
    "script" : "const input = args.plainTexts[0] || \"[email protected]\";\nconst emails = input.match(\/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9._-]+)\/gi);\nconst email = emails[0];\n\n\nconst containers = await ContactsContainer.all();\n\nlet container, group;\nfor (const c of containers) {\n const groups = await ContactsGroup.all([c]);\n const newsletters = groups.find(g => g.name === \"Newsletters\");\n if (!newsletters) continue;\n container = c;\n group = newsletters;\n}\n\nconst contact = new Contact();\ncontact.emailAddresses =[{ value: email }];\nContact.add(contact, container.identifier);\ngroup.addMember(contact);\n\nawait Contact.persistChanges();\n\nconst alert = new Alert();\nalert.title = email;\nalert.addAction(\"OK\")\nalert.present();\n\n",
    "share_sheet_inputs" : [
    "plain-text"
    ]
    }