Skip to content

Commit

Permalink
added mojeek support
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiuipath committed Dec 11, 2020
1 parent 66f7aeb commit 73f2698
Show file tree
Hide file tree
Showing 8 changed files with 2,271 additions and 5,576 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Privacy Labrador

You can now use DuckDuckGo as your default search engine and when DDG misses the results, a handy google link is presented in the page.
You can now use Mojeek, Qwant or DuckDuckGo as your default search engine and when it misses the results, a handy Google link is presented in the page. Check the FEATURES section bellow.

FEATURES:
- shows the tab that points to Google results in the Duck Duck Go results page;
- it jump to the Google results with Shift+Alt+G if you are on Duck Duck Go results page;
- shows the tab that points to Google results in the Mojeek, Qwant or DuckDuckGo results page;
- it jump to the Google results with Shift+Alt+G if you are on one of these search engine's results page;
- If you type "g some search term" in the awesome bar it will go directly to Google's "some search term" results page.
- it can temporarily reset your current search engine and always redirect to google when you tap Shift+Alt+A. This is useful when you pair program with people that don't like DDG or QWant.
- it can temporarily reset your current search engine and always redirect to google when you tap Shift+Alt+A. This is useful when you pair program with people that don't like your alternative search engine of choice.
- Configure the two extension shortcuts from about:addons > settings icon > Manage extension shortcuts

I'm currently working on rudimentary qwant.com support. It's still buggy in Qwant.
Expand Down
4 changes: 3 additions & 1 deletion app/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"content_scripts": [{
"matches": [
"https://duckduckgo.com/*",
"https://www.qwant.com/*"
"https://www.qwant.com/*",
"https://www.mojeek.com/*"
],
"js": [
"scripts/contentscript.js"
Expand All @@ -31,6 +32,7 @@
"activeTab",
"https://duckduckgo.com/*",
"https://www.qwant.com/*",
"https://www.mojeek.com/*",
"webRequest",
"webRequestBlocking"
],
Expand Down
14 changes: 14 additions & 0 deletions app/scripts/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ function decorateQwantLink(googleLink) {
addInputFieldListener(document.querySelector('input[type=search]'));
}

function decorateMojeekLink(googleLink) {
googleLink.className = 'sidebar__item__link';

var googleLinkItem = document.createElement('li');
googleLinkItem.className = 'sidebar__item sidebar__item--google';
googleLinkItem.appendChild(googleLink);
var resultItems = document.querySelectorAll('.opts-bar .left ul')[0];
resultItems.insertBefore(googleLinkItem, resultItems.childNodes[0]);

addInputFieldListener(document.querySelector('input[type="text"]'));
}

function injectGoogleLink() {
var hostName = getWindowLocation().hostname;
var queryParam = new URLSearchParams(getWindowLocation().search).get('q');
Expand All @@ -72,6 +84,8 @@ function injectGoogleLink() {
decorageDuckDuckGoLink(googleLink);
} else if (hostName.indexOf('qwant.com') > -1) {
decorateQwantLink(googleLink);
} else if (hostName.indexOf('mojeek.com') > -1) {
decorateMojeekLink(googleLink);
}
}
}
Expand Down
7,676 changes: 2,107 additions & 5,569 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "privacy-labrador",
"version": "0.0.1",
"description": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
"version": "1.0.0",
"description": "You can now use Mojeek, Qwant or DuckDuckGo as your default search engine and when it misses the results, a handy Google link is presented in the page. Check the FEATURES section bellow.",
"scripts": {
"dev": "webextension-toolbox dev firefox",
"build": "webextension-toolbox build firefox --no-minimize ",
Expand Down
4 changes: 4 additions & 0 deletions test/BackgroundSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
expect(toGoogle(new URL('https://www.qwant.com/?q=test'))).toBe('https://www.google.com/search?q=test');
});

it('should redirect mojeek to google', function () {
expect(toGoogle(new URL('https://www.mojeek.com/search?q=firefox%20fenix'))).toBe('https://www.google.com/search?q=firefox%20fenix');
});

it('should not redirect google to google', function () {
expect(toGoogle(new URL('https://www.google.com/search?q=test'))).toBe('');
});
Expand Down
11 changes: 11 additions & 0 deletions test/ContentScriptSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
if (isHostPrefixedWith(url, 'https://www.qwant.com')) {
document.body.innerHTML = window.__html__['test/data/qwant_desktop.html'];
}
if (isHostPrefixedWith(url, 'https://www.mojeek.com')) {
document.body.innerHTML = window.__html__['test/data/mojeek.html'];
}
}

function typeTextInSearchField(textToType) {
Expand Down Expand Up @@ -71,5 +74,13 @@

expectLinkWithTextAndSelector("eff");
});

it('should work for Mojeek', function () {
setWindowLocation('https://www.mojeek.com/search?q=firefox%20fenix');

injectGoogleLink();

expectLinkWithTextAndSelector("firefox fenix", "li.sidebar__item--google a");
});
});
})();
126 changes: 126 additions & 0 deletions test/data/mojeek.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<div class="page-wrap large-footer">
<div class="header nb">
<div class="header-container">
<div class="header-logo"><a href="https://www.mojeek.com"><img src="/logos/logo_cc.svg" alt="Mojeek"
width="120" height="36"></a></div>
<div class="header-form">
<div class="sf1">
<form method="get" action="/search" name="sf1"><input type="text" class="js-search-input"
autofocus="" maxlength="256" name="q" value="test"
placeholder="Search The Web using Mojeek..." tabindex="0"><a href="#"
class="js-clear-search-btn" tabindex="0" role="button"
style="visibility: visible;"></a><button type="submit" tabindex="0"><span
class="svg-icon search"></span></button><a class="js-modal-open" data-modal="talk-to-us"
data-id="113d6064261bd1bf4db51763419d0a04"
href="/about/contact?subject=talk+to+us&amp;message=I'd+like+to+talk+to+Mojeek">Talk to
Us</a></form>
</div>
</div>
<input class="hamburger-check js-hamburger" id="hamburger-check" type="checkbox"><label aria-label="Menu"
data-tooltip="down" for="hamburger-check"
class="hamburger"><span></span><span></span><span></span></label>
<nav class="main-nav">
<ul>
<li><span class="svg-icon nav-icon-search"></span><a href="/">Web Search</a></li>
<li><span class="svg-icon nav-icon-image"></span><a href="/images">Image Search</a></li>
<li><span class="svg-icon nav-icon-news"></span><a href="/news">News Search</a></li>
</ul>
<hr>
<ul>
<li><span class="svg-icon nav-icon-m"></span><input class="hide" type="checkbox"
id="check-about"><label for="check-about">About<span
class="svg-icon chevron-down"></span></label>
<ul>
<li><a href="/about">About Us</a></li>
<li><a href="/about/contact">Contact</a></li>
<li><a href="/about/privacy">Privacy Policy</a></li>
<li><a href="/about/careers">Careers</a></li>
</ul>
</li>
<li><span class="svg-icon nav-icon-settings"></span><input class="hide" type="checkbox"
id="check-preferences"><label for="check-preferences">Preferences<span
class="svg-icon chevron-down"></span></label>
<ul>
<li><a href="/preferences">Site Settings</a></li>
<li><a href="/preferences?tab=search">Search Settings</a></li>
<li><a href="/preferences?tab=location">Location Settings</a></li>
</ul>
</li>
<li><span class="svg-icon nav-icon-briefcase"></span><input class="hide" type="checkbox"
id="check-business solutions"><label for="check-business solutions">Business Solutions<span
class="svg-icon chevron-down"></span></label>
<ul>
<li><a href="/services/">Services</a></li>
<li><a href="/services/api.html">Search API</a></li>
<li><a href="/services/sitesearch/">Site Search</a></li>
</ul>
</li>
<li><span class="svg-icon nav-icon-help"></span><input class="hide" type="checkbox"
id="check-help &amp; support"><label for="check-help &amp; support">Help &amp; Support<span
class="svg-icon chevron-down"></span></label>
<ul>
<li><a href="/support/">Support</a></li>
<li><a href="/support/browsers/">Add Mojeek to your Browser</a></li>
<li><a href="/support/smartphones/">Add Mojeek to your Smartphone</a></li>
</ul>
</li>
<li><span class="svg-icon nav-icon-blog"></span><a href="https://blog.mojeek.com">Blog</a></li>
</ul>
<hr>
<div class="social"><a href="https://twitter.com/mojeek"><span class="svg-icon nav-soc-t"></span></a><a
href="https://mastodon.social/@Mojeek"><span class="svg-icon nav-soc-m"></span></a><a
href="https://www.reddit.com/r/mojeek/"><span class="svg-icon nav-soc-r"></span></a><a
href="https://www.linkedin.com/company/mojeek/"><span class="svg-icon nav-soc-l"></span></a><a
href="https://www.facebook.com/Mojeek/"><span class="svg-icon nav-soc-f"></span></a></div>
</nav>
</div>
</div>
<div class="opts-bar">
<div class="container">
<div class="inner">
<div class="left">
<ul>
<li class="selected"><a href="/search?q=test">Web</a></li>
<li><a href="https://www.mojeek.com/search?q=test&amp;fmt=images">Images</a></li>
</ul>
</div>
<div class="right">
<ul>
<li><label class="popover-label" for="reg"><span
class="svg-icon nav-icon-reg"></span></label><input class="popover-trigger"
type="checkbox" id="reg">
<div class="popover">
<ul>
<li><a href="/search?q=test&amp;reg=uk">United Kingdom</a></li>
<li><a href="/search?q=test&amp;reg=de">Germany</a></li>
<li><a href="/search?q=test&amp;reg=fr">France</a></li>
<li><a href="/search?q=test&amp;reg=eu">European Union</a></li>
<li><a href="/search?q=test&amp;reg=">All Regions</a></li>
</ul>
</div>
</li>
<li><label class="popover-label" for="settings"><span
class="svg-icon nav-icon-settings"></span></label><input class="popover-trigger"
type="checkbox" id="settings">
<div class="popover">
<ul>
<li><a href="/advanced.html">Advanced Search</a></li>
<li><a href="/preferences">Preferences</a></li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<div class="top-info">
<div class="js-results-cnt-bar">
<p>Results <strong>1</strong> to <strong>10</strong> from <strong>104,736,956</strong> in 2.13s</p>
</div>
</div>


</div>
</div>

0 comments on commit 73f2698

Please sign in to comment.