2019-01-31 17:06:48 +01: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-02-18 09:27:40 +01:00
|
|
|
|
getVersion () {return "3.4.2";}
|
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
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
|
initConstructor () {
|
2019-02-18 09:27:40 +01:00
|
|
|
|
this.changelog = {
|
|
|
|
|
"fixed":[["Image Modal","Option is now also added to a contextmenu when you right click the image in the image modal"]]
|
|
|
|
|
};
|
|
|
|
|
|
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 = {
|
|
|
|
|
engines: {
|
2018-10-21 11:28:29 +02:00
|
|
|
|
_all: {value:true, name:BDFDB.getLibraryStrings().btn_all_text, 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"}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.messageContextEntryMarkup =
|
|
|
|
|
`<div class="${BDFDB.disCN.contextmenuitemgroup}">
|
|
|
|
|
<div class="${BDFDB.disCN.contextmenuitem} reverseimagesearch-item ${BDFDB.disCN.contextmenuitemsubmenu}">
|
|
|
|
|
<span>Reverse Image Search</span>
|
|
|
|
|
<div class="${BDFDB.disCN.contextmenuhint}"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
|
this.messageContextSubMenuMarkup =
|
2019-01-03 11:30:54 +01:00
|
|
|
|
`<div class="${BDFDB.disCN.contextmenu} reverseimagesearch-submenu">
|
2018-10-11 10:21:26 +02:00
|
|
|
|
<div class="${BDFDB.disCN.contextmenuitemgroup}">
|
|
|
|
|
<div class="${BDFDB.disCN.contextmenuitem} alldisabled-item ${BDFDB.disCN.contextmenuitemdisabled}">
|
2019-04-18 09:28:20 +02:00
|
|
|
|
<span class="BDFDB-textscrollwrapper" speed=3><div class="BDFDB-textscroll">REPLACE_submenu_disabled_text</div></span>
|
2018-10-11 10:21:26 +02:00
|
|
|
|
<div class="${BDFDB.disCN.contextmenuhint}"></div>
|
|
|
|
|
</div>
|
2019-04-18 09:28:20 +02:00
|
|
|
|
${Object.keys(this.defaults.engines).map((key, i) => `<div engine="${key}" class="${BDFDB.disCN.contextmenuitem} RIS-item"><span class="BDFDB-textscrollwrapper" speed=3><div class="BDFDB-textscroll">${this.defaults.engines[key].name}</div></span><div class="${BDFDB.disCN.contextmenuhint}"></div></div>`).join("")}
|
2018-10-11 10:21:26 +02:00
|
|
|
|
</div>
|
|
|
|
|
</div>`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getSettingsPanel () {
|
2019-01-22 11:28:32 +01:00
|
|
|
|
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
2019-01-03 11:30:54 +01:00
|
|
|
|
let engines = BDFDB.getAllData(this, "engines");
|
2019-04-18 09:28:20 +02:00
|
|
|
|
let settingshtml = `<div class="${this.name}-settings BDFDB-settings"><div class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.size18 + BDFDB.disCNS.height24 + BDFDB.disCNS.weightnormal + BDFDB.disCN.marginbottom8}">${this.name}</div><div class="BDFDB-settings-inner">`;
|
|
|
|
|
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 0 0 auto;">Search Engines:</h3></div><div class="BDFDB-settings-inner-list">`;
|
2018-10-11 10:21:26 +02:00
|
|
|
|
for (let key in engines) {
|
2019-01-17 23:48:29 +01:00
|
|
|
|
settingshtml += `<div class="${BDFDB.disCNS.flex + BDFDB.disCNS.flex2 + BDFDB.disCNS.horizontal + BDFDB.disCNS.horizontal2 + BDFDB.disCNS.directionrow + BDFDB.disCNS.justifystart + BDFDB.disCNS.aligncenter + BDFDB.disCNS.nowrap + BDFDB.disCN.marginbottom8}" style="flex: 1 1 auto;"><h3 class="${BDFDB.disCNS.titledefault + BDFDB.disCNS.title + BDFDB.disCNS.marginreset + BDFDB.disCNS.weightmedium + BDFDB.disCNS.size16 + BDFDB.disCNS.height24 + BDFDB.disCN.flexchild}" style="flex: 1 1 auto;">${this.defaults.engines[key].name}</h3><div class="${BDFDB.disCNS.flexchild + BDFDB.disCNS.switchenabled + BDFDB.disCNS.switch + BDFDB.disCNS.switchvalue + BDFDB.disCNS.switchsizedefault + BDFDB.disCNS.switchsize + BDFDB.disCN.switchthemedefault}" style="flex: 0 0 auto;"><input type="checkbox" value="engines ${key}" class="${BDFDB.disCNS.switchinnerenabled + BDFDB.disCN.switchinner} settings-switch"${engines[key] ? " checked" : ""}></div></div>`;
|
2018-10-11 10:21:26 +02:00
|
|
|
|
}
|
|
|
|
|
settingshtml += `</div>`;
|
|
|
|
|
settingshtml += `</div></div>`;
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2019-01-17 23:48:29 +01:00
|
|
|
|
let settingspanel = BDFDB.htmlToElement(settingshtml);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
|
2019-01-17 23:48:29 +01:00
|
|
|
|
BDFDB.initElements(settingspanel, this);
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
|
return settingspanel;
|
|
|
|
|
}
|
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-01-17 23:48:29 +01:00
|
|
|
|
var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]');
|
|
|
|
|
if (!libraryScript || performance.now() - libraryScript.getAttribute("date") > 600000) {
|
2018-10-11 10:21:26 +02:00
|
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
|
libraryScript = document.createElement("script");
|
|
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
|
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js");
|
2019-01-17 23:48:29 +01:00
|
|
|
|
libraryScript.setAttribute("date", performance.now());
|
2019-01-30 21:23:49 +01:00
|
|
|
|
libraryScript.addEventListener("load", () => {if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();});
|
2018-10-11 10:21:26 +02:00
|
|
|
|
document.head.appendChild(libraryScript);
|
|
|
|
|
}
|
2019-01-17 23:48:29 +01:00
|
|
|
|
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
2018-10-11 10:21:26 +02:00
|
|
|
|
this.startTimeout = setTimeout(() => {this.initialize();}, 30000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2018-10-11 10:21:26 +02:00
|
|
|
|
BDFDB.loadMessage(this);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2019-02-12 21:56:34 +01:00
|
|
|
|
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) {
|
2018-10-11 10:21:26 +02:00
|
|
|
|
BDFDB.unloadMessage(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
|
changeLanguageStrings () {
|
|
|
|
|
this.messageContextSubMenuMarkup = this.messageContextSubMenuMarkup.replace("REPLACE_submenu_disabled_text", this.labels.submenu_disabled_text);
|
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2019-01-03 11:30:54 +01:00
|
|
|
|
onNativeContextMenu (instance, menu) {
|
2019-02-18 09:27:40 +01:00
|
|
|
|
if (instance.props && instance.props.type == "NATIVE_IMAGE" && (instance.props.href || instance.props.src) && !menu.querySelector(".reverseimagesearch-item")) {
|
2019-02-28 22:56:56 +01:00
|
|
|
|
this.appendItem(menu, instance.props.href || instance.props.src);
|
2019-01-03 11:30:54 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2019-01-03 11:30:54 +01:00
|
|
|
|
onMessageContextMenu (instance, menu) {
|
|
|
|
|
if (instance.props && instance.props.message && instance.props.channel && instance.props.target && !menu.querySelector(".reverseimagesearch-item")) {
|
|
|
|
|
if (instance.props.attachment) {
|
2019-02-28 22:56:56 +01:00
|
|
|
|
this.appendItem(menu, instance.props.attachment.url);
|
2019-01-03 11:30:54 +01:00
|
|
|
|
}
|
2019-02-28 22:56:56 +01:00
|
|
|
|
if (instance.props.target.tagName == "A" && instance.props.message.embeds && instance.props.message.embeds[0] && instance.props.message.embeds[0].type == "image") {
|
|
|
|
|
this.appendItem(menu, instance.props.target.href);
|
|
|
|
|
BDFDB.updateContextPosition(menu);
|
2018-10-11 10:21:26 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
2019-02-28 22:56:56 +01:00
|
|
|
|
appendItem (menu, url) {
|
|
|
|
|
if (url && url.indexOf("discordapp.com/assets/") == -1 && !url.endsWith(".mp4")) {
|
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-02-18 20:35:44 +01:00
|
|
|
|
let messageContextEntry = BDFDB.htmlToElement(this.messageContextEntryMarkup);
|
|
|
|
|
menu.appendChild(messageContextEntry);
|
|
|
|
|
let searchitem = messageContextEntry.querySelector(".reverseimagesearch-item");
|
|
|
|
|
searchitem.addEventListener("mouseenter", () => {
|
|
|
|
|
let messageContextSubMenu = BDFDB.htmlToElement(this.messageContextSubMenuMarkup);
|
|
|
|
|
let engines = BDFDB.getAllData(this, "engines");
|
|
|
|
|
for (let key in engines) if (!engines[key]) BDFDB.removeEles(messageContextSubMenu.querySelector("[engine='" + key + "']"));
|
|
|
|
|
if (messageContextSubMenu.querySelector(".RIS-item")) BDFDB.removeEles(messageContextSubMenu.querySelector(".alldisabled-item"));
|
|
|
|
|
BDFDB.addChildEventListener(messageContextSubMenu, "click", ".RIS-item", e => {
|
2019-02-28 22:56:56 +01:00
|
|
|
|
BDFDB.closeContextMenu(menu);
|
2019-02-18 20:35:44 +01:00
|
|
|
|
let engine = e.currentTarget.getAttribute("engine");
|
|
|
|
|
if (engine == "_all") {
|
|
|
|
|
for (let key in engines) if (key != "_all" && engines[key]) window.open(this.defaults.engines[key].url.replace(this.imgUrlReplaceString, encodeURIComponent(url)), "_blank");
|
|
|
|
|
}
|
|
|
|
|
else window.open(this.defaults.engines[engine].url.replace(this.imgUrlReplaceString, encodeURIComponent(url)), "_blank");
|
|
|
|
|
});
|
|
|
|
|
BDFDB.appendSubMenu(searchitem, messageContextSubMenu);
|
|
|
|
|
});
|
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 () {
|
|
|
|
|
switch (BDFDB.getDiscordLanguage().id) {
|
|
|
|
|
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"
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|