1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-06-07 11:34:07 +02:00

Allow dragging Twitter account links onto the app to view their profile

Closes 
This commit is contained in:
chylex 2020-02-16 11:35:20 +01:00
parent 175b067a17
commit c2c9160ed9

View File

@ -945,20 +945,23 @@
// Block: Allow drag & drop behavior for dropping links on columns to open their detail view. // Block: Allow drag & drop behavior for dropping links on columns to open their detail view.
// //
execSafe(function supportDragDropOverColumns(){ execSafe(function supportDragDropOverColumns(){
const tweetRegex = /^https?:\/\/twitter\.com\/[A-Za-z0-9_]+\/status\/(\d+)\/?\??/; const regexTweet = /^https?:\/\/twitter\.com\/[A-Za-z0-9_]+\/status\/(\d+)\/?\??/;
const selector = "section.js-column"; const regexAccount = /^https?:\/\/twitter\.com\/(?!signup$|tos$|privacy$|search$|search-)([^/?]+)\/?$/;
let isDraggingValid = false; let dragType = false;
const events = { const events = {
dragover: function(e){ dragover: function(e){
e.originalEvent.dataTransfer.dropEffect = isDraggingValid ? "all" : "none"; e.originalEvent.dataTransfer.dropEffect = dragType ? "all" : "none";
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
}, },
drop: function(e){ drop: function(e){
let match = tweetRegex.exec(e.originalEvent.dataTransfer.getData("URL")); let url = e.originalEvent.dataTransfer.getData("URL");
if (dragType === "tweet"){
let match = regexTweet.exec(url);
if (match.length === 2){ if (match.length === 2){
let column = TD.controller.columnManager.get($(this).attr("data-column")); let column = TD.controller.columnManager.get($(this).attr("data-column"));
@ -972,19 +975,34 @@
}); });
} }
} }
}
else if (dragType === "account"){
let match = regexAccount.exec(url);
if (match.length === 2){
$(document).trigger("uiShowProfile", { id: match[1] });
}
}
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
} }
}; };
const selectors = {
tweet: "section.js-column",
account: app
};
window.TDGF_onGlobalDragStart = function(type, data){ window.TDGF_onGlobalDragStart = function(type, data){
if (type === "link"){ if (dragType){
isDraggingValid = tweetRegex.test(data); app.undelegate(selectors[dragType], events);
app.delegate(selector, events); dragType = null;
} }
else{
app.undelegate(selector, events); if (type === "link"){
dragType = regexTweet.test(data) ? "tweet" : regexAccount.test(data) ? "account": null;
app.delegate(selectors[dragType], events);
} }
}; };
}); });