|
| 1 | +// Storing the omg.lol credentials in Draft's Credential instead of the action code directly |
| 2 | +var credential = Credential.create("omg.lol status", "Keep privately your omg.lol API key and your username"); |
| 3 | +credential.addTextField("omg_username", "Your username"); |
| 4 | +credential.addPasswordField("omg_api_key", "API Key"); |
| 5 | +credential.authorize(); |
| 6 | + |
| 7 | +// We'll get the values and store them in our own variables |
| 8 | +let omg_api_key = credential.getValue("omg_api_key") |
| 9 | +let omg_username = credential.getValue("omg_username") |
| 10 | + |
| 11 | +// Get the safe title of the current Draft and replace spaces with - |
| 12 | +var slugText = draft.processTemplate("Link content slug"); |
| 13 | +var slug = slugText.toLowerCase() |
| 14 | + .replace(/["'=:!?@£#$%&\*\(\)\[\]_\+\|;~`<>,\.]+/g, '') |
| 15 | + .replace(/ +/g,'-'); |
| 16 | +let title = slug |
| 17 | + |
| 18 | +// Get the body of the of the current Draft removing empty line before and after |
| 19 | +let content = draft.processTemplate("[[trimmed_body]]") |
| 20 | + |
| 21 | +// Create paste.lol direct link and copy to clipboard |
| 22 | +let link = "https://"+omg_username+".paste.lol/"+title |
| 23 | +let clipboard = app.setClipboard(link) |
| 24 | + |
| 25 | +// Check if paste exists |
| 26 | +// API - https://api.omg.lol/#noauth-get-pastebin-retrieve-a-specific-paste |
| 27 | + |
| 28 | +// var http = HTTP.create(); |
| 29 | +// var response = http.request({ |
| 30 | +// "url": "https://api.omg.lol/address/" + omg_username + "/pastebin", |
| 31 | +// "method": "GET" |
| 32 | +// }); |
| 33 | + |
| 34 | +// If above request.success = true |
| 35 | +// show title already exists error dialog |
| 36 | +// Click OK to return to your draft |
| 37 | +// else |
| 38 | +// continue with script |
| 39 | + |
| 40 | +// use https://api.omg.lol/address/jomalo/pastebin/post-to-pastebin to verify |
| 41 | + |
| 42 | +// Confirming there is more than one line in the current Draft then submit to the omg.lol pastebin :) |
| 43 | +// This creates a public paste - remove "listed": 1 for private |
| 44 | +// Should be made into a public Yes|No dialog |
| 45 | +if (title !== '' && content!== '') { |
| 46 | + var http = HTTP.create(); |
| 47 | + var response = http.request({ |
| 48 | + "url": "https://api.omg.lol/address/" + omg_username + "/pastebin", |
| 49 | + "method": "POST", |
| 50 | + "data": { |
| 51 | + "title": title, |
| 52 | + "content": content, |
| 53 | + "listed": 1 |
| 54 | + }, |
| 55 | + "headers": { |
| 56 | + "Authorization": "Bearer " + omg_api_key |
| 57 | + } |
| 58 | + }); |
| 59 | +} |
| 60 | + |
0 commit comments