- Joined
- Jul 4, 2008
- Messages
- 1,106
About
Source
Tampermonkey
Legend
Drop2Pastebin (D2Pastebin), as a script, allows for Drag & Drop functionality (within chat).
- Find the file you want to throw to pastebin.
- Drag the file inside the chat window.
- Drop the file as it is inside the chat window.
- After the upload to pastebin, give the user/target the pastebin link + file info.
JavaScript:
try {
var D2Pastebin = {
parent: document.documentElement,
it: function(evnt) {
evnt.preventDefault();
var file = evnt.dataTransfer.files,
xhr = new XMLHttpRequest,
form = new FormData,
timestamp = Date.now(),
url = "./pastebin.php/?do=save",
filenames = [],
totalsize = 0,
status = chat.users[chat.userid].status,
targetUser = evnt.target,
targetUserName = targetUser.innerHTML.match(/([^:]+)/)?targetUser.innerHTML.match(/([^:]+)/)[1]:0;
form.append("text", "D2Pastebin Data, "+timestamp);
form.append("keep", "1");
form.append("name", "["+timestamp+"] D2Pastebin Data");
for (var i in file) if (!isNaN(i)) {
form.append("file"+i, file[i].name);
form.append(file[i].name, file[i]);
totalsize += file[i].size;
filenames.push(file[i].name);
}
if (evnt.target.nodeName == "SPAN") evnt.target.classList.contains("D2Pastebin-Effect")? evnt.target.classList.remove("D2Pastebin-Effect"): 0;
if (!totalsize) {chat.tell(":("); return false}
if (xhr.upload) xhr.upload.onprogress = function(_evnt) {chat.tell(_evnt.loaded+" / "+totalsize+" ("+Math.floor((_evnt.loaded / totalsize) * 100)+"%)")}
xhr.onload = function (_evnt) {
var finalURL = this.getResponseHeader("TM-finalURL"),
filelist = (""+filenames).replace(/,/g, ", "),
userid = targetUser.nodeName == "SPAN"? chat.getUserId(targetUserName): 0;
if (!userid) {
if (file.length > 1) chat.tell("Uploaded "+filelist.length+" files: http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+" - "+totalsize+" bytes)");
else chat.tell("Uploaded a file: http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+", "+totalsize+" bytes)");
} else {
if (filelist.length > 60) filelist = filelist.substr(0,60) + "...";
if (file.length > 1) chat.input("/raw 1p"+userid+" http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+" - "+totalsize+" bytes)");
else chat.input("/raw 1p"+userid+" http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+", "+totalsize+" bytes)");
}
};
xhr.open("post", url);
xhr.send(form);
return false;
},
effect: function(evnt) {
evnt.preventDefault();
if (evnt.target.nodeName == "SPAN") !evnt.target.classList.contains("D2Pastebin-Effect")? evnt.target.classList.add("D2Pastebin-Effect"): 0;
return false;
},
clearEffect: function(evnt) {
evnt.preventDefault();
if (evnt.target.nodeName == "SPAN") evnt.target.classList.contains("D2Pastebin-Effect")? evnt.target.classList.remove("D2Pastebin-Effect"): 0;
return false;
},
};
D2Pastebin.parent.ondrop = D2Pastebin.it;
D2Pastebin.parent.ondragover = D2Pastebin.effect;
D2Pastebin.parent.ondragleave = D2Pastebin.clearEffect;
D2Pastebin.parent.ondragend = D2Pastebin.clearEffect;
} catch(e) {// Comment the alert out if you want to.
alert("D2Pastebin doesn't support your browser.");
}
Download Tampermonkey to Chrome from: https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo
JavaScript:
// ==UserScript==
// @name D2Pastebin
// @namespace http://www.hiveworkshop.com/forums/chat.php
// @version 0
// @description Something useful.
// @match http://www.hiveworkshop.com/forums/chat.php
// @copyright
// ==/UserScript==
try {
var D2Pastebin = {
parent: document.documentElement,
it: function(evnt) {
evnt.preventDefault();
var file = evnt.dataTransfer.files,
xhr = new XMLHttpRequest,
form = new FormData,
timestamp = Date.now(),
url = "./pastebin.php/?do=save",
filenames = [],
totalsize = 0,
status = chat.users[chat.userid].status,
targetUser = evnt.target,
targetUserName = targetUser.innerHTML.match(/([^:]+)/)?targetUser.innerHTML.match(/([^:]+)/)[1]:0;
form.append("text", "D2Pastebin Data, "+timestamp);
form.append("keep", "1");
form.append("name", "["+timestamp+"] D2Pastebin Data");
for (var i in file) if (!isNaN(i)) {
form.append("file"+i, file[i].name);
form.append(file[i].name, file[i]);
totalsize += file[i].size;
filenames.push(file[i].name);
}
if (evnt.target.nodeName == "SPAN") evnt.target.classList.contains("D2Pastebin-Effect")? evnt.target.classList.remove("D2Pastebin-Effect"): 0;
if (!totalsize) {chat.tell(":("); return false}
if (xhr.upload) xhr.upload.onprogress = function(_evnt) {chat.tell(_evnt.loaded+" / "+totalsize+" ("+Math.floor((_evnt.loaded / totalsize) * 100)+"%)")}
xhr.onload = function (_evnt) {
var finalURL = this.getResponseHeader("TM-finalURL"),
filelist = (""+filenames).replace(/,/g, ", "),
userid = targetUser.nodeName == "SPAN"? chat.getUserId(targetUserName): 0;
if (!userid) {
if (file.length > 1) chat.tell("Uploaded "+filelist.length+" files: http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+" - "+totalsize+" bytes)");
else chat.tell("Uploaded a file: http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+", "+totalsize+" bytes)");
} else {
if (filelist.length > 60) filelist = filelist.substr(0,60) + "...";
if (file.length > 1) chat.input("/raw 1p"+userid+" http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+" - "+totalsize+" bytes)");
else chat.input("/raw 1p"+userid+" http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+", "+totalsize+" bytes)");
}
};
xhr.open("post", url);
xhr.send(form);
return false;
},
effect: function(evnt) {
evnt.preventDefault();
if (evnt.target.nodeName == "SPAN") !evnt.target.classList.contains("D2Pastebin-Effect")? evnt.target.classList.add("D2Pastebin-Effect"): 0;
return false;
},
clearEffect: function(evnt) {
evnt.preventDefault();
if (evnt.target.nodeName == "SPAN") evnt.target.classList.contains("D2Pastebin-Effect")? evnt.target.classList.remove("D2Pastebin-Effect"): 0;
return false;
},
};
D2Pastebin.parent.ondrop = D2Pastebin.it;
D2Pastebin.parent.ondragover = D2Pastebin.effect;
D2Pastebin.parent.ondragleave = D2Pastebin.clearEffect;
D2Pastebin.parent.ondragend = D2Pastebin.clearEffect;
} catch(e) {// Comment the alert out if you want to.
alert("D2Pastebin doesn't support your browser.");
}
[reaction=http://www.hiveworkshop.com/forums/images_all/icons/icon4.gif]Fixed.[/reaction]
[reaction=http://www.hiveworkshop.com/forums/images_all/icons/icon5.gif]Questionable.[/reaction]
Suggestions? Improvements? Comments?
Last edited: