2019-09-20 22:32:52 +02:00
|
|
|
|
//META{"name":"ReverseImageSearch","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ReverseImageSearch","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/ReverseImageSearch/ReverseImageSearch.plugin.js"}*//
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
|
|
|
|
class ReverseImageSearch {
|
2019-01-17 23:48:29 +01:00
|
|
|
|
getName () {return "ReverseImageSearch";}
|
|
|
|
|
|
2019-11-07 10:15:10 +01:00
|
|
|
|
getVersion () {return "3.4.7";}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2019-01-17 23:48:29 +01:00
|
|
|
|
getAuthor () {return "DevilBro";}
|
|
|
|
|
|
|
|
|
|
getDescription () {return "Adds a reverse image search option to the context menu.";}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2019-09-04 12:34:02 +02:00
|
|
|
|
constructor () {
|
2019-02-18 09:27:40 +01:00
|
|
|
|
this.changelog = {
|
2019-11-07 10:15:10 +01:00
|
|
|
|
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
2019-02-18 09:27:40 +01:00
|
|
|
|
};
|
2019-09-04 12:34:02 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initConstructor () {
|
2018-10-11 10:21:26 +02:00
|
|
|
|
this.imgUrlReplaceString = "DEVILBRO_BD_REVERSEIMAGESEARCH_REPLACE_IMAGEURL";
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
|
this.defaults = {
|
2019-10-05 17:46:38 +02:00
|
|
|
|
settings: {
|
2019-10-06 16:41:40 +02:00
|
|
|
|
addUserAvatarEntry: {value:true, description:"User Avatars"},
|
|
|
|
|
addGuildIconEntry: {value:true, description:"Server Icons"},
|
|
|
|
|
addEmojiEntry: {value:true, description:"Custom Emojis/Emotes"}
|
2019-10-05 17:46:38 +02:00
|
|
|
|
},
|
2018-10-11 10:21:26 +02:00
|
|
|
|
engines: {
|
2019-10-19 11:41:39 +02:00
|
|
|
|
_all: {value:true, name:BDFDB.LanguageUtils.LanguageStrings.FORM_LABEL_ALL, url:null},
|
2018-10-11 10:21:26 +02:00
|
|
|
|
Baidu: {value:true, name:"Baidu", url:"http://image.baidu.com/pcdutu?queryImageUrl=" + this.imgUrlReplaceString},
|
|
|
|
|
Bing: {value:true, name:"Bing", url:"https://www.bing.com/images/search?q=imgurl:" + this.imgUrlReplaceString + "&view=detailv2&iss=sbi&FORM=IRSBIQ"},
|
|
|
|
|
Google: {value:true, name:"Google", url:"https://images.google.com/searchbyimage?image_url=" + this.imgUrlReplaceString},
|
|
|
|
|
IQDB: {value:true, name:"IQDB", url:"https://iqdb.org/?url=" + this.imgUrlReplaceString},
|
|
|
|
|
Reddit: {value:true, name:"Reddit", url:"http://karmadecay.com/search?q=" + this.imgUrlReplaceString},
|
|
|
|
|
SauceNAO: {value:true, name:"SauceNAO", url:"https://saucenao.com/search.php?db=999&url=" + this.imgUrlReplaceString},
|
|
|
|
|
Sogou: {value:true, name:"Sogou", url:"http://pic.sogou.com/ris?flag=1&drag=0&query=" + this.imgUrlReplaceString + "&flag=1"},
|
|
|
|
|
TinEye: {value:true, name:"TinEye", url:"https://tineye.com/search?url=" + this.imgUrlReplaceString},
|
2018-11-02 22:39:42 +01:00
|
|
|
|
WhatAnime: {value:true, name:"WhatAnime", url:"https://trace.moe/?url=" + this.imgUrlReplaceString},
|
2018-10-11 10:21:26 +02:00
|
|
|
|
Yandex: {value:true, name:"Yandex", url:"https://yandex.com/images/search?url=" + this.imgUrlReplaceString + "&rpt=imageview"}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getSettingsPanel () {
|
2019-01-22 11:28:32 +01:00
|
|
|
|
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
2019-11-07 10:15:10 +01:00
|
|
|
|
let settings = BDFDB.DataUtils.get(this, "engines");
|
2019-10-22 19:49:57 +02:00
|
|
|
|
let engines = BDFDB.DataUtils.get(this, "engines");
|
2019-11-07 10:15:10 +01:00
|
|
|
|
let settingsitems = [], inneritems = [];
|
|
|
|
|
|
|
|
|
|
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
|
|
|
|
className: BDFDB.disCN.marginbottom8,
|
|
|
|
|
type: "Switch",
|
|
|
|
|
plugin: this,
|
|
|
|
|
keys: ["settings", key],
|
|
|
|
|
label: this.defaults.settings[key].description,
|
|
|
|
|
value: settings[key]
|
|
|
|
|
}));
|
|
|
|
|
for (let key in engines) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
|
|
|
|
className: BDFDB.disCN.marginbottom8,
|
|
|
|
|
type: "Switch",
|
|
|
|
|
plugin: this,
|
|
|
|
|
keys: ["engines", key],
|
|
|
|
|
label: this.defaults.engines[key].name,
|
|
|
|
|
value: engines[key]
|
|
|
|
|
}));
|
|
|
|
|
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
|
|
|
|
title: "Search Engines:",
|
|
|
|
|
first: settingsitems.length == 0,
|
|
|
|
|
last: true,
|
|
|
|
|
children: inneritems
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
|
//legacy
|
|
|
|
|
load () {}
|
|
|
|
|
|
|
|
|
|
start () {
|
2019-02-04 09:13:15 +01:00
|
|
|
|
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
|
|
|
|
|
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
|
2019-05-26 13:55:26 +02:00
|
|
|
|
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
|
|
|
|
|
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
2018-10-11 10:21:26 +02:00
|
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
|
libraryScript = document.createElement("script");
|
2019-05-26 13:55:26 +02:00
|
|
|
|
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
2018-10-11 10:21:26 +02:00
|
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
2019-10-18 10:56:41 +02:00
|
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
2019-01-17 23:48:29 +01:00
|
|
|
|
libraryScript.setAttribute("date", performance.now());
|
2019-05-26 13:55:26 +02:00
|
|
|
|
libraryScript.addEventListener("load", () => {this.initialize();});
|
2018-10-11 10:21:26 +02:00
|
|
|
|
document.head.appendChild(libraryScript);
|
2019-05-26 13:55:26 +02:00
|
|
|
|
}
|
|
|
|
|
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
2019-11-01 10:27:07 +01:00
|
|
|
|
this.startTimeout = setTimeout(() => {
|
|
|
|
|
try {return this.initialize();}
|
|
|
|
|
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
|
|
|
|
}, 30000);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initialize () {
|
2019-01-17 23:48:29 +01:00
|
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-01-22 11:05:54 +01:00
|
|
|
|
if (this.started) return;
|
2019-10-22 18:55:25 +02:00
|
|
|
|
BDFDB.PluginUtils.init(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
}
|
2019-11-01 10:14:50 +01:00
|
|
|
|
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
2018-10-11 10:21:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stop () {
|
2019-01-17 23:48:29 +01:00
|
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-10-22 11:37:23 +02:00
|
|
|
|
this.stopping = true;
|
|
|
|
|
|
2019-10-22 18:55:25 +02:00
|
|
|
|
BDFDB.PluginUtils.clear(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
|
// begin of own functions
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2019-11-07 10:15:10 +01:00
|
|
|
|
onGuildContextMenu (e) {
|
2019-11-11 10:48:30 +01:00
|
|
|
|
if (e.instance.props.guild && e.instance.props.target) {
|
2019-11-07 10:15:10 +01:00
|
|
|
|
let guildicon = BDFDB.DOMUtils.containsClass(e.instance.props.target, BDFDB.disCN.avataricon) ? e.instance.props.target : e.instance.props.target.querySelector(BDFDB.dotCN.guildicon);
|
|
|
|
|
if (guildicon && BDFDB.DataUtils.get(this, "settings", "addGuildIconEntry")) this.injectItem(e, guildicon.tagName == "IMG" ? guildicon.getAttribute("src") : guildicon.style.getPropertyValue("background-image"));
|
2019-10-06 16:41:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-07 10:15:10 +01:00
|
|
|
|
onUserContextMenu (e) {
|
2019-11-11 10:48:30 +01:00
|
|
|
|
if (e.instance.props.user && e.instance.props.target) {
|
2019-11-07 10:15:10 +01:00
|
|
|
|
let avatar = BDFDB.DOMUtils.containsClass(e.instance.props.target, BDFDB.disCN.avataricon) ? e.instance.props.target : e.instance.props.target.querySelector(BDFDB.dotCN.avatar);
|
|
|
|
|
if (avatar && BDFDB.DataUtils.get(this, "settings", "addUserAvatarEntry")) this.injectItem(e, avatar.tagName == "IMG" ? avatar.getAttribute("src") : avatar.style.getPropertyValue("background-image"));
|
2019-10-05 17:46:38 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-07 10:15:10 +01:00
|
|
|
|
onNativeContextMenu (e) {
|
2019-11-11 10:48:30 +01:00
|
|
|
|
if (e.instance.props.type == "NATIVE_IMAGE" && (e.instance.props.href || e.instance.props.src)) this.injectItem(e, e.instance.props.href || e.instance.props.src);
|
2019-01-03 11:30:54 +01:00
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2019-11-07 10:15:10 +01:00
|
|
|
|
onMessageContextMenu (e) {
|
2019-11-11 10:48:30 +01:00
|
|
|
|
if (e.instance.props.message && e.instance.props.channel && e.instance.props.target) {
|
2019-11-07 10:15:10 +01:00
|
|
|
|
if (e.instance.props.attachment) this.injectItem(e, e.instance.props.attachment.url);
|
|
|
|
|
else if (e.instance.props.target.tagName == "A" && e.instance.props.message.embeds && e.instance.props.message.embeds[0] && e.instance.props.message.embeds[0].type == "image") this.injectItem(e, e.instance.props.target.href);
|
|
|
|
|
else if (e.instance.props.target.tagName == "IMG" && BDFDB.DOMUtils.containsClass(e.instance.props.target, "emoji", "emote", false) && BDFDB.DataUtils.get(this, "settings", "addEmojiEntry")) this.injectItem(e, e.instance.props.target.src);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2019-11-07 10:15:10 +01:00
|
|
|
|
injectItem (e, url) {
|
2019-02-28 22:56:56 +01:00
|
|
|
|
if (url && url.indexOf("discordapp.com/assets/") == -1 && !url.endsWith(".mp4")) {
|
2019-10-06 16:41:40 +02:00
|
|
|
|
url = url.replace(/^url\(|\)$|"|'/g, "").replace(/\?size\=\d+$/, "?size=4096");
|
2019-02-18 20:35:44 +01:00
|
|
|
|
if (url.indexOf("https://images-ext-1.discordapp.net/external/") > -1) {
|
|
|
|
|
if (url.split("/https/").length != 1) url = "https://" + url.split("/https/")[url.split("/https/").length-1];
|
|
|
|
|
else if (url.split("/http/").length != 1) url = "http://" + url.split("/http/")[url.split("/http/").length-1];
|
2019-01-03 11:30:54 +01:00
|
|
|
|
}
|
2019-10-22 19:49:57 +02:00
|
|
|
|
let engines = BDFDB.DataUtils.get(this, "engines");
|
2019-09-11 12:14:43 +02:00
|
|
|
|
let items = [];
|
2019-10-22 18:55:25 +02:00
|
|
|
|
for (let key in engines) if (engines[key]) items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
|
2019-09-11 12:14:43 +02:00
|
|
|
|
label: this.defaults.engines[key].name,
|
2019-10-05 17:48:33 +02:00
|
|
|
|
danger: key == "_all",
|
2019-09-11 12:14:43 +02:00
|
|
|
|
action: e => {
|
2019-11-07 10:15:10 +01:00
|
|
|
|
if (!e.shiftKey) BDFDB.ContextMenuUtils.close(e.instance);
|
2019-09-11 12:14:43 +02:00
|
|
|
|
if (key == "_all") {
|
|
|
|
|
for (let key2 in engines) if (key2 != "_all" && engines[key2]) window.open(this.defaults.engines[key2].url.replace(this.imgUrlReplaceString, encodeURIComponent(url)), "_blank");
|
2019-02-18 20:35:44 +01:00
|
|
|
|
}
|
2019-09-11 12:14:43 +02:00
|
|
|
|
else window.open(this.defaults.engines[key].url.replace(this.imgUrlReplaceString, encodeURIComponent(url)), "_blank");
|
|
|
|
|
}
|
|
|
|
|
}));
|
2019-10-22 18:55:25 +02:00
|
|
|
|
if (!items.length) items.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItem, {
|
2019-09-11 12:14:43 +02:00
|
|
|
|
label: this.labels.submenu_disabled_text,
|
|
|
|
|
disabled: true
|
|
|
|
|
}));
|
2019-11-07 10:15:10 +01:00
|
|
|
|
let [children, index] = BDFDB.ReactUtils.findChildren(e.returnvalue, {name:["FluxContainer(MessageDeveloperModeGroup)", "DeveloperModeGroup"]});
|
2019-10-22 18:55:25 +02:00
|
|
|
|
const itemgroup = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuItemGroup, {
|
2019-09-11 12:14:43 +02:00
|
|
|
|
children: [
|
2019-10-22 18:55:25 +02:00
|
|
|
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.ContextMenuSubItem, {
|
2019-09-11 12:14:43 +02:00
|
|
|
|
label: "Reverse Image Search",
|
|
|
|
|
render: items
|
|
|
|
|
})
|
|
|
|
|
]
|
2019-02-18 20:35:44 +01:00
|
|
|
|
});
|
2019-09-11 12:14:43 +02:00
|
|
|
|
if (index > -1) children.splice(index, 0, itemgroup);
|
|
|
|
|
else children.push(itemgroup);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
|
setLabelsByLanguage () {
|
2019-10-22 23:04:35 +02:00
|
|
|
|
switch (BDFDB.LanguageUtils.getLanguage().id) {
|
2018-10-11 10:21:26 +02:00
|
|
|
|
case "hr": //croatian
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Svi su onemogućeni"
|
|
|
|
|
};
|
|
|
|
|
case "da": //danish
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Alle deaktiveret"
|
|
|
|
|
};
|
|
|
|
|
case "de": //german
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Alle deaktiviert"
|
|
|
|
|
};
|
|
|
|
|
case "es": //spanish
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Todo desactivado"
|
|
|
|
|
};
|
|
|
|
|
case "fr": //french
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Tous désactivés"
|
|
|
|
|
};
|
|
|
|
|
case "it": //italian
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Tutto disattivato"
|
|
|
|
|
};
|
|
|
|
|
case "nl": //dutch
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Alles gedeactiveerd"
|
|
|
|
|
};
|
|
|
|
|
case "no": //norwegian
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Alle deaktivert"
|
|
|
|
|
};
|
|
|
|
|
case "pl": //polish
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Wszystkie wyłączone"
|
|
|
|
|
};
|
|
|
|
|
case "pt-BR": //portuguese (brazil)
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Todos desativados"
|
|
|
|
|
};
|
|
|
|
|
case "fi": //finnish
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Kaikki on poistettu käytöstä"
|
|
|
|
|
};
|
|
|
|
|
case "sv": //swedish
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Alla avaktiverade"
|
|
|
|
|
};
|
|
|
|
|
case "tr": //turkish
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Hepsi deaktive"
|
|
|
|
|
};
|
|
|
|
|
case "cs": //czech
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Všechny deaktivované"
|
|
|
|
|
};
|
|
|
|
|
case "bg": //bulgarian
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Всички са деактивирани"
|
|
|
|
|
};
|
|
|
|
|
case "ru": //russian
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Все деактивированные"
|
|
|
|
|
};
|
|
|
|
|
case "uk": //ukrainian
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "Всі вимкнені"
|
|
|
|
|
};
|
|
|
|
|
case "ja": //japanese
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "すべて非アクティブ化"
|
|
|
|
|
};
|
|
|
|
|
case "zh-TW": //chinese (traditional)
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "全部停用"
|
|
|
|
|
};
|
|
|
|
|
case "ko": //korean
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "모두 비활성화 됨"
|
|
|
|
|
};
|
|
|
|
|
default: //default: english
|
|
|
|
|
return {
|
|
|
|
|
submenu_disabled_text: "All disabled"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|