2020-10-20 23:25:34 +02:00
/ * *
* @ name GoogleSearchReplace
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2021-03-05 13:26:41 +01:00
* @ version 1.2 . 9
* @ description Replaces the default Google Text Search with a custom Search Engine
2020-10-20 23:25:34 +02:00
* @ invite Jx3TjNS
2020-11-19 16:45:36 +01:00
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
2021-03-09 15:10:55 +01:00
* @ website https : //mwittrien.github.io/
* @ source https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/GoogleSearchReplace/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/GoogleSearchReplace/GoogleSearchReplace.plugin.js
2020-10-20 23:25:34 +02:00
* /
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
module . exports = ( _ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info" : {
"name" : "GoogleSearchReplace" ,
"author" : "DevilBro" ,
2020-12-28 19:41:31 +01:00
"version" : "1.2.9" ,
2021-03-04 12:15:46 +01:00
"description" : "Replaces the default Google Text Search with a custom Search Engine"
2020-12-28 19:41:31 +01:00
} ,
"changeLog" : {
"added" : {
"GitHub" : "Added github as search engine"
}
2020-02-13 12:25:48 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2020-12-28 19:41:31 +01:00
2020-10-09 21:09:35 +02:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2021-01-06 12:38:36 +01:00
getName ( ) { return config . info . name ; }
getAuthor ( ) { return config . info . author ; }
getVersion ( ) { return config . info . version ; }
2021-02-01 17:13:13 +01:00
getDescription ( ) { return ` The Library Plugin needed for ${ config . info . name } is missing. Open the Plugin Settings to download it. \n \n ${ config . info . description } ` ; }
downloadLibrary ( ) {
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
2021-03-05 13:14:18 +01:00
if ( ! e && b && r . statusCode == 200 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => BdApi . showToast ( "Finished downloading BDFDB Library" , { type : "success" } ) ) ;
2021-03-06 14:59:48 +01:00
else BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library" ) ;
2021-02-01 17:13:13 +01:00
} ) ;
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
load ( ) {
2020-11-19 16:51:14 +01:00
if ( ! window . BDFDB _Global || ! Array . isArray ( window . BDFDB _Global . pluginQueue ) ) window . BDFDB _Global = Object . assign ( { } , window . BDFDB _Global , { pluginQueue : [ ] } ) ;
2020-09-19 20:49:33 +02:00
if ( ! window . BDFDB _Global . downloadModal ) {
window . BDFDB _Global . downloadModal = true ;
2021-01-14 16:14:44 +01:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ config . info . name } is missing. Please click "Download Now" to install it. ` , {
2020-09-19 20:49:33 +02:00
confirmText : "Download Now" ,
cancelText : "Cancel" ,
onCancel : _ => { delete window . BDFDB _Global . downloadModal ; } ,
2020-09-20 08:15:13 +02:00
onConfirm : _ => {
delete window . BDFDB _Global . downloadModal ;
2021-02-01 17:13:13 +01:00
this . downloadLibrary ( ) ;
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
} ) ;
}
if ( ! window . BDFDB _Global . pluginQueue . includes ( config . info . name ) ) window . BDFDB _Global . pluginQueue . push ( config . info . name ) ;
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start ( ) { this . load ( ) ; }
stop ( ) { }
getSettingsPanel ( ) {
2020-11-28 23:12:09 +01:00
let template = document . createElement ( "template" ) ;
2021-01-14 16:14:44 +01:00
template . innerHTML = ` <div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${ config . info . name } is missing. \n Please click <a style="font-weight: 500;">Download Now</a> to install it.</div> ` ;
2021-02-01 17:13:13 +01:00
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , this . downloadLibrary ) ;
2020-11-28 23:12:09 +01:00
return template . content . firstElementChild ;
}
2020-10-09 21:09:35 +02:00
} : ( ( [ Plugin , BDFDB ] ) => {
2020-12-21 19:56:36 +01:00
const textUrlReplaceString = "DEVILBRO_BD_GOOGLESEARCHREPLACE_REPLACEURL" ;
2021-01-10 11:41:01 +01:00
var engines = { } , enabledEngines = { } ;
2020-09-19 20:49:33 +02:00
2020-10-09 21:09:35 +02:00
return class GoogleSearchReplace extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
this . defaults = {
engines : {
2020-11-19 16:51:14 +01:00
_all : { value : true , name : BDFDB . LanguageUtils . LanguageStrings . FORM _LABEL _ALL , url : null } ,
2020-12-28 19:41:31 +01:00
Ask : { value : true , name : "Ask" , url : "https://ask.com/web?q=" + textUrlReplaceString } ,
Bing : { value : true , name : "Bing" , url : "https://www.bing.com/search?q=" + textUrlReplaceString } ,
DogPile : { value : true , name : "DogPile" , url : "http://www.dogpile.com/search/web?q=" + textUrlReplaceString } ,
2020-11-19 16:51:14 +01:00
DuckDuckGo : { value : true , name : "DuckDuckGo" , url : "https://duckduckgo.com/?q=" + textUrlReplaceString } ,
2020-12-28 19:41:31 +01:00
GitHub : { value : true , name : "GitHub" , url : "https://github.com/search?q=" + textUrlReplaceString } ,
2020-11-19 16:51:14 +01:00
Google : { value : true , name : "Google" , url : "https://www.google.com/search?q=" + textUrlReplaceString } ,
GoogleScholar : { value : true , name : "Google Scholar" , url : "https://scholar.google.com/scholar?q=" + textUrlReplaceString } ,
2020-12-28 19:41:31 +01:00
Quora : { value : true , name : "Quora" , url : "https://www.quora.com/search?q=" + textUrlReplaceString } ,
Qwant : { value : true , name : "Qwant" , url : "https://www.qwant.com/?t=all&q=" + textUrlReplaceString } ,
UrbanDictionary : { value : true , name : "Urban Dictionary" , url : "https://www.urbandictionary.com/define.php?term=" + textUrlReplaceString } ,
Searx : { value : true , name : "Searx" , url : "https://searx.info/?q=" + textUrlReplaceString } ,
WolframAlpha : { value : true , name : "Wolfram Alpha" , url : "https://www.wolframalpha.com/input/?i=" + textUrlReplaceString } ,
2020-11-19 16:51:14 +01:00
Yandex : { value : true , name : "Yandex" , url : "https://yandex.com/search/?text=" + textUrlReplaceString } ,
2020-12-28 19:41:31 +01:00
Yahoo : { value : true , name : "Yahoo" , url : "https://search.yahoo.com/search?p=" + textUrlReplaceString } ,
YouTube : { value : true , name : "YouTube" , url : "https://www.youtube.com/results?q=" + textUrlReplaceString }
2020-09-19 20:49:33 +02:00
}
} ;
}
2021-01-06 12:38:36 +01:00
onStart ( ) {
2020-09-19 20:49:33 +02:00
this . forceUpdateAll ( ) ;
}
2020-02-13 12:25:48 +01:00
2021-01-06 12:38:36 +01:00
onStop ( ) { }
2020-09-19 20:49:33 +02:00
getSettingsPanel ( collapseStates = { } ) {
let settingsPanel , settingsItems = [ ] ;
2020-12-15 10:35:30 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
2020-11-19 16:45:36 +01:00
title : "Search Engines:" ,
2020-09-19 20:49:33 +02:00
children : Object . keys ( engines ) . filter ( n => n && n != "_all" ) . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "engines" , key ] ,
label : this . defaults . engines [ key ] . name ,
value : engines [ key ]
} ) )
} ) ) ;
2020-06-09 09:03:02 +02:00
2020-09-19 20:49:33 +02:00
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , settingsItems ) ;
2020-02-13 12:25:48 +01:00
}
2019-10-22 11:37:23 +02:00
2021-01-06 12:38:36 +01:00
onSettingsClosed ( ) {
2020-09-19 20:49:33 +02:00
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
this . forceUpdateAll ( ) ;
}
}
2021-01-06 12:38:36 +01:00
forceUpdateAll ( ) {
2020-09-19 20:49:33 +02:00
engines = BDFDB . DataUtils . get ( this , "engines" ) ;
enabledEngines = BDFDB . ObjectUtils . filter ( engines , n => n ) ;
2020-02-13 12:25:48 +01:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
onMessageContextMenu ( e ) {
this . injectItem ( e ) ;
}
2020-05-19 19:56:29 +02:00
2020-09-19 20:49:33 +02:00
onNativeContextMenu ( e ) {
this . injectItem ( e ) ;
}
injectItem ( e ) {
let [ children , index ] = BDFDB . ContextMenuUtils . findItem ( e . returnvalue , { id : "search-google" } ) ;
if ( index > - 1 ) {
let text = document . getSelection ( ) . toString ( ) ;
let enginesWithoutAll = BDFDB . ObjectUtils . filter ( enabledEngines , n => n != "_all" , true ) ;
let engineKeys = Object . keys ( enginesWithoutAll ) ;
if ( engineKeys . length == 1 ) {
children . splice ( index , 1 , BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
2020-12-21 19:56:36 +01:00
label : this . labels . context _googlesearchreplace . replace ( "..." , this . defaults . engines [ engineKeys [ 0 ] ] . name ) ,
2020-09-19 20:49:33 +02:00
id : children [ index ] . props . id ,
persisting : true ,
action : event => {
if ( ! event . shiftKey ) BDFDB . ContextMenuUtils . close ( e . instance ) ;
2021-01-10 11:41:01 +01:00
BDFDB . DiscordUtils . openLink ( this . defaults . engines [ engineKeys [ 0 ] ] . url . replace ( textUrlReplaceString , encodeURIComponent ( text ) ) , {
minimized : event . shiftKey
} ) ;
2020-02-13 12:25:48 +01:00
}
2020-09-19 20:49:33 +02:00
} ) ) ;
}
else {
let items = [ ] ;
for ( let key in enabledEngines ) items . push ( BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
label : this . defaults . engines [ key ] . name ,
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "search" , key ) ,
color : key == "_all" ? BDFDB . LibraryComponents . MenuItems . Colors . DANGER : BDFDB . LibraryComponents . MenuItems . Colors . DEFAULT ,
persisting : true ,
action : event => {
if ( ! event . shiftKey ) BDFDB . ContextMenuUtils . close ( e . instance ) ;
if ( key == "_all" ) {
2021-01-10 11:41:01 +01:00
for ( let key2 in enginesWithoutAll ) BDFDB . DiscordUtils . openLink ( this . defaults . engines [ key2 ] . url . replace ( textUrlReplaceString , encodeURIComponent ( text ) ) , {
minimized : event . shiftKey
} ) ;
2020-09-19 20:49:33 +02:00
}
2021-01-10 11:41:01 +01:00
else BDFDB . DiscordUtils . openLink ( this . defaults . engines [ key ] . url . replace ( textUrlReplaceString , encodeURIComponent ( text ) ) , {
minimized : event . shiftKey
} ) ;
2020-09-19 20:49:33 +02:00
}
} ) ) ;
if ( ! items . length ) items . push ( BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
2020-12-21 19:56:36 +01:00
label : this . labels . submenu _disabled ,
2020-09-19 20:49:33 +02:00
id : BDFDB . ContextMenuUtils . createItemId ( this . name , "disabled" ) ,
disabled : true
} ) ) ;
children . splice ( index , 1 , BDFDB . ContextMenuUtils . createItem ( BDFDB . LibraryComponents . MenuItems . MenuItem , {
2020-12-21 19:56:36 +01:00
label : this . labels . context _googlesearchreplace ,
2020-09-19 20:49:33 +02:00
id : children [ index ] . props . id ,
children : items
} ) ) ;
}
2019-01-17 23:48:29 +01:00
}
2019-09-11 12:14:43 +02:00
}
2019-01-26 22:45:19 +01:00
2021-01-06 12:38:36 +01:00
setLabelsByLanguage ( ) {
2020-09-19 20:49:33 +02:00
switch ( BDFDB . LanguageUtils . getLanguage ( ) . id ) {
2020-12-21 19:56:36 +01:00
case "bg" : // Bulgarian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Търсене с ..." ,
submenu _disabled : "Всички инвалиди"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "da" : // Danish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Søg med ..." ,
submenu _disabled : "Alle handicappede"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "de" : // German
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Suche mit ..." ,
submenu _disabled : "Alle deaktiviert"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "el" : // Greek
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Αναζήτηση με ..." ,
submenu _disabled : "Όλα τα άτομα με ειδικές ανάγκες"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "es" : // Spanish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Buscar con ..." ,
submenu _disabled : "Todos discapacitados"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "fi" : // Finnish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Hae ..." ,
submenu _disabled : "Kaikki vammaiset"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "fr" : // French
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Rechercher avec ..." ,
submenu _disabled : "Tout désactivé"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "hr" : // Croatian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Traži sa ..." ,
submenu _disabled : "Svi invalidi"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "hu" : // Hungarian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Keresés a következővel:" ,
submenu _disabled : "Minden fogyatékkal él"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "it" : // Italian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Cerca con ..." ,
submenu _disabled : "Tutti disabilitati"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "ja" : // Japanese
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "で検索 ..." ,
submenu _disabled : "すべて無効"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "ko" : // Korean
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "다음으로 검색 ..." ,
submenu _disabled : "모두 비활성화 됨"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "lt" : // Lithuanian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Ieškoti naudojant ..." ,
submenu _disabled : "Visi neįgalūs"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "nl" : // Dutch
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Zoeken met ..." ,
submenu _disabled : "Allemaal uitgeschakeld"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "no" : // Norwegian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Søk med ..." ,
submenu _disabled : "Alle funksjonshemmede"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "pl" : // Polish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Szukaj za pomocą ..." ,
submenu _disabled : "Wszystkie wyłączone"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "pt-BR" : // Portuguese (Brazil)
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Pesquise com ..." ,
submenu _disabled : "Todos desativados"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "ro" : // Romanian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Căutați cu ..." ,
submenu _disabled : "Toate sunt dezactivate"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "ru" : // Russian
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Искать с ..." ,
submenu _disabled : "В с е отключены"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "sv" : // Swedish
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "Sök med ..." ,
submenu _disabled : "Alla funktionshindrade"
2020-09-19 20:49:33 +02:00
} ;
2020-12-21 19:56:36 +01:00
case "th" : // Thai
2020-09-19 20:49:33 +02:00
return {
2020-12-21 19:56:36 +01:00
context _googlesearchreplace : "ค้นหาด้วย ..." ,
submenu _disabled : "ปิดใช้งานทั้งหมด"
} ;
case "tr" : // Turkish
return {
context _googlesearchreplace : "Şununla ara ..." ,
submenu _disabled : "Hepsi devre dı şı "
} ;
case "uk" : // Ukrainian
return {
context _googlesearchreplace : "Шукати за допомогою ..." ,
submenu _disabled : "В с і інваліди"
} ;
case "vi" : // Vietnamese
return {
context _googlesearchreplace : "Tìm kiếm với ..." ,
submenu _disabled : "Tất cả đã bị vô hiệu hóa"
} ;
2021-01-15 17:54:22 +01:00
case "zh-CN" : // Chinese (China)
2020-12-21 19:56:36 +01:00
return {
context _googlesearchreplace : "用 ... 搜索" ,
submenu _disabled : "全部禁用"
} ;
2021-01-15 17:54:22 +01:00
case "zh-TW" : // Chinese (Taiwan)
2020-12-21 19:56:36 +01:00
return {
context _googlesearchreplace : "用 ... 搜索" ,
submenu _disabled : "全部禁用"
} ;
default : // English
return {
context _googlesearchreplace : "Search with ..." ,
submenu _disabled : "All disabled"
2020-09-19 20:49:33 +02:00
} ;
}
2020-02-13 12:25:48 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2020-10-09 21:09:35 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( config ) ) ;
2020-11-13 07:06:19 +01:00
} ) ( ) ;