diff --git a/content_scripts/complete.js b/content_scripts/complete.js index 15ab283a..f83ab9ac 100644 --- a/content_scripts/complete.js +++ b/content_scripts/complete.js @@ -518,4 +518,42 @@ Complete.engines = { }); } }, + + startpage: { + baseUrl: 'https://www.startpage.com', + requestUrl: 'https://www.startpage.com/do/asearch?query=', + apiUrl: 'https://www.startpage.com/do/suggest?query=%s', + queryApi: function(query, callback) { + httpRequest({ + url: this.apiUrl.embedString(encodeURIComponent(query)), + json: false + }, function(response) { + callback(response.split(/\r?\n/)); + }); + } + }, + + linguee: { + baseUrl: 'https://www.linguee.de/', + requestUrl: 'https://www.linguee.de/deutsch-englisch/search?source=auto&query=', + apiUrl: 'https://www.linguee.de/deutsch-englisch/search?qe=%s&source=auto"', + queryApi: function(query, callback) { + httpRequest({ + url: this.apiUrl.embedString(encodeURIComponent(query)), + json: false + }, function(response) { + var _obj = (new DOMParser()).parseFromString(response, "text/html"); + callback([].slice.call(_obj.querySelectorAll(".autocompletion_item")).map(function(e) { + var item = e.querySelector(".main_item"), + translations = ""; + e.querySelectorAll(".translation_item").forEach( function(child) { + child.childNodes.forEach( function(data) { + if (data.nodeType == Node.TEXT_NODE && data.length > 1) translations += data.textContent.trim() + ", "; + }); + }); + return [ item.textContent + " -> " + translations.slice(0,-2), "https://www.linguee.de" + item.getAttribute('href') ]; + })); + }); + } + }, };