module.exports = (Plugin, Api, Vendor) => { if (!global.BDFDB || typeof BDFDB != "object") global.BDFDB = {myPlugins:{}, BDv2Api: Api}; return class extends Plugin { initConstructor () { this.labels = {}; this.textUrlReplaceString = "DEVILBRO_BD_GOOGLESEARCHREPLACE_REPLACE_TEXTURL"; this.defaults = { engines: { _all: {value:true, name:BDFDB.getLibraryStrings().btn_all_text, url:null}, Ask: {value:true, name:"Ask", url:"https://ask.com/web?q=" + this.textUrlReplaceString}, Bing: {value:true, name:"Bing", url:"https://www.bing.com/search?q=" + this.textUrlReplaceString}, DogPile: {value:true, name:"DogPile", url:"http://www.dogpile.com/search/web?q=" + this.textUrlReplaceString}, DuckDuckGo: {value:true, name:"DuckDuckGo", url:"https://duckduckgo.com/?q=" + this.textUrlReplaceString}, Google: {value:true, name:"Google", url:"https://www.google.com/search?q=" + this.textUrlReplaceString}, GoogleScholar: {value:true, name:"Google Scholar", url:"https://scholar.google.com/scholar?q=" + this.textUrlReplaceString}, Quora: {value:true, name:"Quora", url:"https://www.quora.com/search?q=" + this.textUrlReplaceString}, Qwant: {value:true, name:"Qwant", url:"https://www.qwant.com/?t=all&q=" + this.textUrlReplaceString}, UrbanDictionary: {value:true, name:"Urban Dictionary", url:"https://www.urbandictionary.com/define.php?term=" + this.textUrlReplaceString}, Searx: {value:true, name:"Searx", url:"https://searx.me/?q=" + this.textUrlReplaceString}, WolframAlpha: {value:true, name:"Wolfram Alpha", url:"https://www.wolframalpha.com/input/?i=" + this.textUrlReplaceString}, Yandex: {value:true, name:"Yandex", url:"https://yandex.com/search/?text=" + this.textUrlReplaceString}, Yahoo: {value:true, name:"Yahoo", url:"https://search.yahoo.com/search?p=" + this.textUrlReplaceString}, YouTube: {value:true, name:"YouTube", url:"https://www.youtube.com/results?q=" + this.textUrlReplaceString} } }; this.messageContextEntryMarkup = `
`; this.messageContextSubMenuMarkup = ` `; } onStart () { if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.name] = this; var libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]'); if (!global.BDFDB || typeof BDFDB != "object" || performance.now() - BDFDB.creationTime > 600000) { if (libraryScript) libraryScript.remove(); libraryScript = document.createElement("script"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"); libraryScript.setAttribute("date", performance.now()); libraryScript.addEventListener("load", () => {if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();}); document.head.appendChild(libraryScript); } else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize(); this.startTimeout = setTimeout(() => {this.initialize();}, 30000); } initialize () { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { if (this.started) return true; BDFDB.loadMessage(this); return true; } else { console.error(`%c[${this.name}]%c`, 'color: #3a71c1; font-weight: 700;', '', 'Fatal Error: Could not load BD functions!'); return false; } } onStop () { if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) { BDFDB.unloadMessage(this); return true; } else { return false; } } // begin of own functions changeLanguageStrings () { this.messageContextEntryMarkup = this.messageContextEntryMarkup.replace("REPLACE_context_googlesearchreplace_text", this.labels.context_googlesearchreplace_text); this.messageContextSubMenuMarkup = this.messageContextSubMenuMarkup.replace("REPLACE_submenu_disabled_text", this.labels.submenu_disabled_text); } onNativeContextMenu (instance, menu) { if (instance.props && instance.props.type == "NATIVE_TEXT" && instance.props.value && !menu.querySelector(".reverseimagesearch-item")) { let searchentry = BDFDB.React.findDOMNodeSafe(BDFDB.getOwnerInstance({node:menu,props:["handleSearchWithGoogle"]})); if (searchentry) this.appendItem(instance, searchentry, instance.props.value); } } onMessageContextMenu (instance, menu) { if (instance.props && instance.props.message && instance.props.channel && instance.props.target && !menu.querySelector(".googlereplacesearch-item")) { let text = document.getSelection().toString(); if (text) { let searchentry = BDFDB.React.findDOMNodeSafe(BDFDB.getOwnerInstance({node:menu,props:["handleSearchWithGoogle"]})); if (searchentry) this.appendItem(instance, searchentry, text); } } } appendItem (instance, target, text) { let messageContextEntry = BDFDB.htmlToElement(this.messageContextEntryMarkup); target.parentElement.insertBefore(messageContextEntry, target.nextElementSibling); messageContextEntry.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(".GRS-item")) BDFDB.removeEles(messageContextSubMenu.querySelector(".alldisabled-item")); BDFDB.addChildEventListener(messageContextSubMenu, "click", ".GRS-item", e => { instance._reactInternalFiber.return.memoizedProps.closeContextMenu(); 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.textUrlReplaceString, encodeURIComponent(text)), "_blank"); } else window.open(this.defaults.engines[engine].url.replace(this.textUrlReplaceString, encodeURIComponent(text)), "_blank"); }); BDFDB.appendSubMenu(messageContextEntry, messageContextSubMenu); }); BDFDB.toggleEles(target, false); } getSettingsPanel () { if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return; let engines = BDFDB.getAllData(this, "engines"); let settingshtml = `