• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

chat.php/Drop2Pastebin

Status
Not open for further replies.

About

Source

Tampermonkey

Legend



Drop2Pastebin (D2Pastebin), as a script, allows for Drag & Drop functionality (within chat).
  1. Find the file you want to throw to pastebin.
  2. Drag the file inside the chat window.
  3. Drop the file as it is inside the chat window.
  4. After the upload to pastebin, give the user/target the pastebin link + file info.
To send the file directly to a user, drop it over their username.


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:
Level 23
Joined
Apr 16, 2012
Messages
4,041
JavaScript:
                if (file.length > 1) chat.input("/me uploaded "+filelist.length+" files: http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+" - "+totalsize+" bytes)");
                else chat.input("/me uploaded a file: http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+", "+totalsize+" bytes)");

this is nice and all, and when you use it alone there is no problem with it, but if more people use it, this will spam chat like crazy, and I dont think that anyone in chat cares about who uploaded what files of what size
 
JavaScript:
                if (file.length > 1) chat.input("/me uploaded "+filelist.length+" files: http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+" - "+totalsize+" bytes)");
                else chat.input("/me uploaded a file: http://www.hiveworkshop.com/forums/"+finalURL+" ("+filelist+", "+totalsize+" bytes)");

this is nice and all, and when you use it alone there is no problem with it, but if more people use it, this will spam chat like crazy, and I dont think that anyone in chat cares about who uploaded what files of what size

 
whats the point of quoting other users without posting anything? + you multiposted when you could easily edit the first post where you quoted me and put the second quote there

1. Read the "Legend" tab.
- Also, because I'm lazy to write anything useful.
2. Status updates aren't counted as multiposting, if done by the thread creator.
 
So, I've so far made the pastebin linking somewhat more spam-friendly.
Instead of using chat.input at all times, it's checking whether or not you dropped the file over a user. If you did, it'll use chat.input to send a whisper/private message to target user.
Otherways, it'll use chat.tell to only display the link for you.

Progress of the file transfer is also now done through chat.tell.

Empty-Drops now give you a sadface via chat.tell.

* Removed debugging code.

** Added filenames shortener back for PM/Whisper. Normal Drag & Drop will display all file names, since only you get to see messages from that. * Scratch that, it's not working properly. Why? Don't ask me. ** And it's working.
 
Last edited:
Status
Not open for further replies.
Top