Action

Open URLs in Selection/Draft

Posted by Chris Grieser, Last update 28 days ago

If text is selected, opens on URLs in the selection.

If no text is selection, opens all URLs in the whole draft.

Steps

  • script

    
    //checks ether there is an in selection at the moment
    if (editor.getSelectedText() == "") {
    	var textToCheck = draft.content; 
    } else {
    	var textToCheck = editor.getSelectedText();
    }
    
    //identifies URL and opens all
    let matches = textToCheck.match(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/ig); // URL-Regex from https://stackoverflow.com/a/11209098
    if (matches != null){
    	for (i = 0; i < matches.length; i++) {
     	 	app.openURL(matches[i]);
    	}
    } else {
    	app.displayErrorMessage("No URL found");
    }

Options

  • After Success Nothing
    Notification Error
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.