module.exports = (Plugin, Api, Vendor) => { if (typeof BDFDB !== "object") global.BDFDB = {$: Vendor.$, BDv2Api: Api}; const {$} = Vendor; 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}, 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 () { var libraryScript = null; if (typeof BDFDB !== "object" || typeof BDFDB.isLibraryOutdated !== "function" || BDFDB.isLibraryOutdated()) { libraryScript = document.querySelector('head script[src="https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"]'); if (libraryScript) libraryScript.remove(); libraryScript = document.createElement("script"); libraryScript.setAttribute("type", "text/javascript"); libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.js"); document.head.appendChild(libraryScript); } this.startTimeout = setTimeout(() => {this.initialize();}, 30000); if (typeof BDFDB === "object" && typeof BDFDB.isLibraryOutdated === "function") this.initialize(); else libraryScript.addEventListener("load", () => {this.initialize();}); return true; } initialize () { if (typeof BDFDB === "object") { BDFDB.loadMessage(this); var observer = null; observer = new MutationObserver((changes, _) => { changes.forEach( (change, i) => { if (change.addedNodes) { change.addedNodes.forEach((node) => { if (node.nodeType == 1 && node.className.includes(BDFDB.disCN.contextmenu)) { this.onContextMenu(node); } }); } } ); }); BDFDB.addObserver(this, BDFDB.dotCN.appmount, {name:"messageContextObserver",instance:observer}, {childList: true}); 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 (typeof BDFDB === "object") { BDFDB.unloadMessage(this); return true; } else { return false; } } // begin of own functions updateSettings (settingspanel) { var settings = {}; for (var input of settingspanel.querySelectorAll(BDFDB.dotCN.switchinner)) { settings[input.value] = input.checked; } BDFDB.saveAllData(settings, this, "engines"); } 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); } onContextMenu (context) { if (!context || !context.tagName || !context.parentElement || context.querySelector(".googlereplacesearch-item")) return; for (let group of context.querySelectorAll(BDFDB.dotCN.contextmenuitemgroup)) { if (BDFDB.getKeyInformation({"node":group, "key":"handleSearchWithGoogle"})) { var text = BDFDB.getKeyInformation({"node":group, "key":"value"}); if (text) { $(group).find(BDFDB.dotCN.contextmenuitem).hide(); $(group).append(this.messageContextEntryMarkup) .on("mouseenter", ".googlereplacesearch-item", (e) => { this.createContextSubMenu(text, e, context); }); BDFDB.updateContextPosition(context); } break; } } } createContextSubMenu (text, e, context) { var messageContextSubMenu = $(this.messageContextSubMenuMarkup); messageContextSubMenu .on("click", ".GRS-item", (e2) => { $(context).hide(); var engine = e2.currentTarget.getAttribute("engine"); if (engine == "_all") { var engines = BDFDB.getAllData(this, "engines"); 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"); } }); var engines = BDFDB.getAllData(this, "engines"); for (let key in engines) { if (!engines[key]) messageContextSubMenu.find("[engine='" + key + "']").remove(); } if (messageContextSubMenu.find(".GRS-item").length > 0) { messageContextSubMenu.find(".alldisabled-item").remove(); } BDFDB.appendSubMenu(e.currentTarget, messageContextSubMenu); } getSettingsPanel () { var engines = BDFDB.getAllData(this, "engines"); var settingshtml = `