Overview
This script adds a new command to upload all selected files anonymously to imgur.
Installation
- Download imgurUploader.js.txt (6.0 KB)
- Open Preferences / Toolbars / Scripts, then drag it to the list.
A minimum of DOpus V11.5 is required.
Usage
Once the script is installed there is a new command imgurUpload
available in the command editor.
The command uploads all selected images to imgur and, after all uploads are finished, copies the links to the clipboard.
Remark
The imgur API has some restrictions regarding uploads per day. I am not sure about the quota but probably the integrated default key reaches its limit fast. For further usage create your own ClientID. If the quota limit is reached, the script will stop working!!!
Feel free to use, optimize and enhance the script. Please post your changes in this thread of the Dopus Resource Centre forum.
Script Code
The script code from the download above is reproduced here for reference.
// ************************** Script Information **************************
// imgur Uploader V0.9b
// (tested with Directory Opus 11.7.5b)
// © 2014 /^\\iran
//
// ****************************** Change log ******************************
// 2014-11-18 v0.9b Inital Version
//
//
// ************************************************************************
// * Script-Data *
// ************************************************************************
SCRIPT_NAME = "imgur Uploader";
SCRIPT_VERSION = "V0.9b";
SCRIPT_DATE = "18.11.2104";
COPYRIGHT = "© 2014 /^\\iran";
MIN_VERSION = "11.5";
// ************************************************************************
// * System-Settings *
// ************************************************************************
imgur_ClientID = "b4af6ea447d2a6a";
imgur_BaseUrl = "https://api.imgur.com/3/";
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
// DOpus Version Check
if(!DOpus.version.atLeast(MIN_VERSION)){DOpus.OutputString("ERR: DOpus Version " + MIN_VERSION + "required to run this script!")}
// Provide basic information about the Script
initData.name = SCRIPT_NAME;
initData.desc = "Upload images anonymously to imgur.";
initData.copyright = COPYRIGHT;
initData.min_version = MIN_VERSION;
initData.default_enable = true;
// Configuration Options of the Script
initData.config.LogLevel = vecLogLevel;
initData.config.imgurClientID = "";
// Command initialisation
var cmd = initData.AddCommand();
cmd.name = "imgurUpload";
cmd.method = "OnIMGUR";
cmd.desc = initData.desc;
cmd.template = "";
return false;
}
function OnIMGUR(funcData)
{
LogLevel = Script.config.LogLevel;
Logger (LOG_DEBUG, ("LogLevelName: " + vecLogLevel(LogLevel+1)));
// ************************************************************************
// * Functions *
// ************************************************************************
links = "";
selectedFiles = new Enumerator(funcData.func.sourcetab.selected_files);
while (!selectedFiles.atEnd())
{
if(!selectedFiles.item.is_dir) {
var ostream = new ActiveXObject("ADODB.Stream");
ostream.type=1; //binary
ostream.mode=3; //read-write
ostream.open();
ostream.LoadFromFile(selectedFiles.item());
var xhr = new ActiveXObject("Msxml2.XMLHTTP.6.0");
url = imgur_BaseUrl + "upload";
xhr.open("POST", url, false);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ClientID = imgur_ClientID;
if(Script.config.imgurClientID != "") {ClientID = Script.config.imgurClientID; Logger (LOG_INFO, ("Config ClientID: " + ClientID))};
xhr.setRequestHeader("Authorization:", "Client-ID " + ClientID);
xhr.send(ostream.Read(-1));
ostream.close;
if(xhr.status != 200)
{
Logger (LOG_ERR, ("Status: " + xhr.status));
Logger (LOG_ERR, ("Response: " + xhr.responseText));
}
else
{
Logger (LOG_DEBUG, ("Status: " + xhr.status));
Logger (LOG_DEBUG, ("Response: " + xhr.responseText));
res = eval("(function(){return " + xhr.responseText+ ";})()");
links += res.data.link + "\n";
Logger (LOG_INFO, ("URL: " + res.data.link));
}
}
selectedFiles.moveNext();
}
DOpus.SetClip(links);
Logger (LOG_ALERT, ("Upload ready, Clipboard filled."));
}
// ************************************************************************
// * About-Dialog *
// ************************************************************************
function OnAboutScript(aboutData)
{
LogLevel = Script.config.LogLevel;
Logger (LOG_DEBUG, ("LogLevelName: " + vecLogLevel(LogLevel+1)));
Logger (LOG_DEBUG, "*** Enter About");
About = "";
About += SCRIPT_NAME + " " + SCRIPT_VERSION +"\n";
About += SCRIPT_DATE + "\n\n";
About += COPYRIGHT + "\n\n";
About += "Feel free to use, optimize and enhance the script. Please post your comments and changes in the respective thread of the Dopus Resource Centre forum.\n";
Commands = "";
Commands += "*** Command Parameters ***\n";
Commands += "\n";
Commands += "No command Parameter, the script tries to upload all selected files from source lister.";
Commands += "\n";
Config = "";
Config += "*** Configuration Parameters ***\n";
Config += "\n";
Config += "LOGLEVEL\n";
Config += "Defines the details of log information the script outputs to the dopus other log.\n";
Config += "Default: WARNING\n";
Config += "\n";
Config += "IMGURCLIENTID\n";
Config += "Your personal imgur Client ID. Required to extend your individual request quota.\n";
Config += "Default: \n";
// Create Dialog
dlg = DOpus.Dlg;
dlg.window = aboutData.window;
dlg.title = "Template";
dlg.buttons = "About|Command Parameter|Config Parameter|Exit";
dlg.icon = "info";
ret = 1;
do {
if(ret == 1) dlg.message = About;
if(ret == 2) dlg.message = Commands;
if(ret == 3) dlg.message = Config;
ret = dlg.show;
}
while (ret != 0);
Logger (LOG_DEBUG, "*** Exit About");
return false;
}
// ************************************************************************
// * Utility Functions *
// ************************************************************************
var LOG_DEBUG = 0;
var LOG_INFO = 1;
var LOG_WARN = 2;
var LOG_ERR = 3;
var LOG_ALERT = 4;
var LogLevel = LOG_WARN;
vecLogLevel = DOpus.NewVector
vecLogLevel.push_back(2);
vecLogLevel.push_back("DEBUG");
vecLogLevel.push_back("INFO");
vecLogLevel.push_back("WARNING");
vecLogLevel.push_back("ERROR");
vecLogLevel.push_back("ALERT");
function Logger(Level, strMessage)
{
if (Level>=LogLevel)
{
DOpus.OutputString(" " + strMessage);
}
}