Drafts Action Directory

Website DuckDuckGo Search

Posted by craigmcclellan, Last update 3 months ago

This script is useful for people who articles from websites (their own or others) frequently. It will prompt you for the website you want to search and the term to search for, then use DuckDuckGo’s website search in Safari View Controller to open the search. Once you find the article you want, tap and hold the URL bar to copy the URL. When you return to Drafts, it will run the Markdown Link action and using the URL you copied to your clipboard.

Install

Steps

  • script

    // Website DuckDuckGo Search
    
    /* 
    This script is useful for people who articles from websites (their own or others) frequently. It will prompt you for the website you want to search and the term to search for, then use DuckDuckGo's website search in Safari View Controller to open the search. Once you find the article you want, tap and hold the URL bar to copy the URL. When you return to Drafts, it will run the Markdown Link action and using the URL you copied to your clipboard.
    */
    
    
    // Insert the title and url of websites you wish to search regularly into the dictionary below:
     
    var sites = {
    	"The Class Nerd": "theclassnerd.com",
    	"Craig McClellan": "craigmcclellan.com",
    	"MacStories": "macstories.net",
    	"DuckDuckGo": "", // This row allows you to search all of DuckDuckGo
    	"Enter another URL": ""}; // This will be used in the Prompt to allow you to enter another website to search.
    
    var siteArray = Object.keys(sites);
    
    // Create prompt to asking for search query and website
    var p = Prompt.create();
    
    p.title = "DuckDuckGo Search";
    p.message = "Select Search Parameters";
    
    p.addTextField("query", "Query", "");
    p.addSelect("website", "Select Website:", siteArray, [], false);
    p.addButton("Done");
    
    p.show();
    
    var selection = p.fieldValues['website'];
    
    // Condition for creating a new prompt asking for a different URL.
    if (selection == "Enter another URL") {
    	var q = Prompt.create();
    	q.title = "Custom URL";
    	q.message = "Enter a URL to search without the http://www.";
    
    	q.addTextField("url", "http://www.", "");
    	q.addButton("Done");
    	q.show();
    
    	var siteURL = q.fieldValues["url"]
    }
    else {
    	var siteURL = sites[selection];
    }
    
    var query = p.fieldValues['query'];
    
    // Build URL using DuckDuckGo's Parameters
    var fullQuery = query + " site: " + siteURL;
    var encodedQuery = encodeURIComponent(fullQuery);
    
    // Queue Markdown Link script for use with copied URL from Safari View Controller
    var mdLink = Action.find("Markdown Link");
    app.queueAction(mdLink, draft);
    
    // Open URL
    fullURL = "https://duckduckgo.com/?q=" + encodedQuery;
    app.openURL(fullURL, true);

Options

  • After Success Nothing
    Notification Info
    Log Level Info

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.