Action

Find Long Drafts

Posted by agiletortoise, Last update over 4 years ago

Search your drafts history for drafts with more than a certain number of characters and generate a new draft with links to those drafts for review.

Mostly meant as an example, but useful to hunt down large drafts that might be taking up a lot of space, etc.

Steps

  • script

    // find long drafts
    let min = 100000;
    
    let p = Prompt.create();
    p.title = "Find Long Drafts";
    p.message = "Locate drafts with more than the requested number of characters and generate a new draft with links to the drafts found.";
    
    p.addTextField("chars", "Min. Characters", min.toString());
    p.addButton("OK", "Scan Drafts", true);
    if (p.show()) {
    	min = parseInt(p.fieldValues["chars"]);
    	let found = [];
    	let all = Draft.query("", "all");
    	for (let d of all) {
    		if (d.content.length > min) {
    			found.push(d);
    		}
    	}
    
    	if (found.length > 0) {
    		let s = "Below is a list of links to drafts with more than " + min + " characters. Use link mode to enable links in this draft and navigate to the drafts.\n\n";
    		for (let d of found) {
    			s = s + `- ${d.title}: ${d.permalink}\n`;
    		}
    		let newDraft = Draft.create();
    		newDraft.content = s;
    		newDraft.update();
    		editor.load(newDraft);
    	}
    	else {
    		alert("No drafts with more than " + min + " characters found.");
    	}
    }
    else {
    	context.cancel();
    }
    
    

Options

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