Skip to content

Commit

Permalink
Bump version to 10.1, update welcome and settings pages
Browse files Browse the repository at this point in the history
  • Loading branch information
corbindavenport committed May 16, 2021
1 parent 5898e77 commit 717bbfc
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 258 deletions.
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
Wikipedia Search
================

This extension adds Wikipedia searching capabilities to web browsers. To perform a search, just type 'wiki' in your browser's address bar, then a space, then the name of the article you want. Live suggestions from Wikipedia are displayed as you type. You can also highlight any word or phrase on the web, and an option to search in Wikipedia will appear in the context menu.
This extension adds Wikipedia searching capabilities to web browsers. To perform a search, just type 'wiki' in your browser's address bar, then press the Tab key, then type the name of the article you want. Live suggestions from Wikipedia are displayed as you type. You can also highlight any word or phrase on the web, and an option to search in Wikipedia will appear in the context menu.

Your device's language is used as the default for searches, but you can also change it to any of the 300+ languages supported by Wikipedia.

[![Download for Chrome](https://corbin.io/img/chrome-button.png)](https://chrome.google.com/webstore/detail/wikipedia-search/lipakennkogpodadpikgipnogamhklmk) [![Download for Opera](https://corbin.io/img/opera-button.png)](https://addons.opera.com/en/extensions/details/wikipedia-search/)
[![Download for Chrome](https://corbin.io/img/chrome-button.png)](https://chrome.google.com/webstore/detail/wikipedia-search/lipakennkogpodadpikgipnogamhklmk)

__Wikipedia is a trademark of the Wikimedia Foundation. Wikipedia Search is in no way affiliated with Wikipedia or the Wikimedia Foundation.__

---------------------------------------------------------

__New in Wikipedia Search 10:__

* Rewritten codebase
* Over 300+ languages now included by default, and the list is automatically updated
* The default language can be overriden by typing the language prefix before a search (example: "fr google" will search "Google" in the French Wikipedia)
* Firefox is now supported (#15)
* Fixed bug where searches with special characters would fail (#16)
* Fixed bug where search box on Wikipedia.org wouldn't focus automatically with extension installed (#10)

---------------------------------------------------------

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand Down
19 changes: 19 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.jumbotron .container {
background-image: url('chrome-extension://__MSG_@@extension_id__/img/icon128.png');
background-size: 80px;
background-repeat: no-repeat;
background-position: 0 center;
padding-left: 120px;
min-height: 80px;
}

/* Fix for Firefox's different URL scheme */
@supports (-moz-appearance:none) {
.jumbotron .container {
background-image: url('moz-extension://__MSG_@@extension_id__/img/icon128.png');
}
}

#supporters {
margin-bottom: 0;
}
Binary file removed img/screen1.png
Binary file not shown.
Binary file removed img/screen2.png
Binary file not shown.
Binary file removed img/screen3.png
Binary file not shown.
Binary file removed img/screen4.png
Binary file not shown.
2 changes: 1 addition & 1 deletion js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ if (window.location.href.includes("www.wikipedia.org") && document.body.querySel
var searchContainer = document.body.querySelector(".search-container")
// Create message
var message = document.createElement('div')
message.innerText = "You can search Wikipedia from your browser's search bar. Just type 'wiki' in the search bar, then a space, then the name of the article you want."
message.innerText = "You can search Wikipedia from your browser's search bar. Just type 'wiki' in the search bar, then press the Tab key, then type the name of the article."
searchContainer.appendChild(message)
}
2 changes: 0 additions & 2 deletions js/jquery-3.4.1.min.js

This file was deleted.

50 changes: 26 additions & 24 deletions js/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Function for populating language select
async function insertLanguages() {
async function loadSettings() {
// Update list of Wikipedias using API
const select = document.getElementById('wikipedia-search-language-select')
const resetButton = document.getElementById('wikipedia-search-reset-language')
Expand All @@ -20,22 +20,23 @@ async function insertLanguages() {
// Finally, allow interaction on language select
select.remove(0)
select.removeAttribute('disabled')
resetButton.removeAttribute('disabled')
//resetButton.removeAttribute('disabled')
// Save language changes to chrome.storage
document.getElementById('wikipedia-search-language-select').addEventListener('change', function() {
saveLanguage(this.value)
})
})
}

// Function for saving language select changes
function saveLanguage(language) {
chrome.storage.local.set({
userLanguage: language
}, function() {
console.log('Language changed to:', language)
// Save settings after any input change
document.querySelectorAll('input,select').forEach(function (el) {
el.addEventListener('change', function () {
chrome.storage.sync.set({
// Default language
userLanguage: document.querySelector('#wikipedia-search-language-select').value
})
})
}
})

// Button links
document.querySelectorAll('.link-btn').forEach(function (el) {
Expand All @@ -44,27 +45,28 @@ document.querySelectorAll('.link-btn').forEach(function (el) {
})
})

// Show instructions for leaving a review based on the browser being used
const useragent = navigator.userAgent
const review = document.querySelector('.review-info')
// Opera has to be checked before Chrome, because Opera has both "Chrome" and "OPR" in the user agent string
if (useragent.includes("OPR")) {
review.innerHTML = 'Leaving a review on the <a href="https://addons.opera.com/en/extensions/details/wikipedia-search/" target="_blank">Opera add-ons site</a> is also greatly appreciated!'
} else if (useragent.includes("Chrome")) {
review.innerHTML = 'Leaving a review on the <a href="https://chrome.google.com/webstore/detail/wikipedia-search/lipakennkogpodadpikgipnogamhklmk" target="_blank">Chrome Web Store</a> is also greatly appreciated!'
}

// Reset language button
/*
document.getElementById('wikipedia-search-reset-language').addEventListener('click', function() {
var lang = resetToSystemLanguage()
// resetToSystemLanguage updates the storage, so here we only need to change the select value
document.getElementById('wikipedia-search-language-select').value = lang
})
*/

// Apply settings button
document.getElementById('wikipedia-search-apply-settings').addEventListener('click', function() {
chrome.runtime.reload()
// Show credits
fetch('https://corbin.io/supporters.json').then(function (response) {
response.json().then(function (data) {
var creditsList = 'Diamond supporters: '
for (var i = 0; i < data['supporters'].length; i++) {
creditsList += data['supporters'][i] + ', '
}
creditsList = creditsList.substring(0, creditsList.length - 2)
document.getElementById('supporters').innerText = creditsList
})
})
.catch(function (err) {
document.getElementById('supporters').innerText = 'There was an error fetching Peek supporters.'
})

// Enable language select
insertLanguages()
loadSettings()
45 changes: 16 additions & 29 deletions js/welcome.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,24 @@
// Function for retrieving parameters from URLs
// Credit: https://stackoverflow.com/a/901144/2255592
function getParameterByName(name, url) {
if (!url) {
url = window.location.href
}
name = name.replace(/[\[\]]/g, '\\$&')
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url)
if (!results) return null
if (!results[2]) return ''
return decodeURIComponent(results[2].replace(/\+/g, ' '))
}

// Add version number to welcome page
document.querySelector('.version').innerHTML = chrome.runtime.getManifest().version

// Add language to welcome page
var lang = decodeURIComponent(getParameterByName('lang'))
document.querySelector(".wikipedia-search-language").innerHTML = 'The search language is currently set to <b>' + lang + '</b>.'
document.querySelector(".version").innerHTML = chrome.runtime.getManifest().version

// Button links
// Link buttons
document.querySelectorAll('.link-btn').forEach(function (el) {
el.addEventListener('click', function () {
chrome.tabs.create({ url: el.getAttribute('data-url') })
})
})

// Show instructions for leaving a review based on the browser being used
const useragent = navigator.userAgent
const review = document.querySelector('.review-info')
// Opera has to be checked before Chrome, because Opera has both "Chrome" and "OPR" in the user agent string
if (useragent.includes("OPR")) {
review.innerHTML = 'Leaving a review on the <a href="https://addons.opera.com/en/extensions/details/wikipedia-search/" target="_blank">Opera add-ons site</a> is also greatly appreciated!'
} else if (useragent.includes("Chrome")) {
review.innerHTML = 'Leaving a review on the <a href="https://chrome.google.com/webstore/detail/wikipedia-search/lipakennkogpodadpikgipnogamhklmk" target="_blank">Chrome Web Store</a> is also greatly appreciated!'
}
// Show credits
fetch('https://corbin.io/supporters.json').then(function (response) {
response.json().then(function (data) {
var creditsList = 'Diamond supporters: '
for (var i = 0; i < data['supporters'].length; i++) {
creditsList += data['supporters'][i] + ', '
}
creditsList = creditsList.substring(0, creditsList.length - 2)
document.getElementById('supporters').innerText = creditsList
})
})
.catch(function (err) {
document.getElementById('supporters').innerText = 'There was an error fetching Wikipedia Search supporters.'
})
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Wikipedia Search",
"version": "10",
"version": "10.1",
"author": "Corbin Davenport",
"homepage_url": "https://github.com/corbindavenport/wikipedia-search",
"description": "Search Wikipedia in every language from the address bar and context menu.",
Expand Down
149 changes: 41 additions & 108 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,135 +6,68 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="img/icon16.png">
<title>Wikipedia Search</title>
<title>Wikipedia Search Settings</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<style>
body {
padding-top: 60px;
}
</style>
<link href="css/styles.css" rel="stylesheet">
</head>

<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<body class="settings">
<div class="jumbotron">
<div class="container">
<span class="navbar-brand">
<img src="img/icon48.png" width="30" height="30" class="d-inline-block align-top" alt="">
Wikipedia Search
</span>
<h1>Wikipedia Search settings</h1>
<p>Here you can change all the options for Wikipedia Search. Your changes are automatically saved.</p>
</div>
</nav>
</div>

<div class="container">

<div class="row">
<div class="col-md-12">
<p>
<h2>Language</h2>
</p>
<p>Here you can change the language that Wikipedia Search uses. The language list is automatically updated every time you open this settings page, using the <a href="https://www.mediawiki.org/wiki/API:Query" target="_blank">Wikipedia Query API</a>.</p>
<p>
<div class="row">
<div class="col-md-6">
<select id="wikipedia-search-language-select" class="custom-select" disabled>
<option value="loading" selected>Loading languages...</option>
</select>
</div>
<div class="col-md-6">
<button type="button" class="btn btn-primary btn-block" id="wikipedia-search-reset-language" disabled>Reset to system language</button>
</div>
</div>
</p>
<hr />
<p>You must restart your browser or click the button below for some changes to take effect. Clicking the button will close this settings page.</p>
<p>
<button type="button" class="btn btn-primary btn-block" id="wikipedia-search-apply-settings">Apply settings</button>
</p>
<div class="col-12">
<b>Having issues?</b> If you find a bug, or have a suggestion for a new feature, <a href="https://discord.com/invite/59wfy5cNHw" target="_blank">join the Discord server</a> or <a href="https://github.com/corbindavenport/wikipedia-search/issues" target="_blank">create an issue on the GitHub repository</a>.
</div>
</div>
<hr />

<hr>

<div class="row">
<div class="col-md-6">
<h2>Basic searches</h2>
<p>To perform a search, just type 'wiki' in your browser's address bar, then a space, then the name of the article you want. Live suggestions from Wikipedia are displayed as you type.</p>
</div>
<div class="col-md-6">
<h2>Right-click search</h2>
<p>You can also highlight any word or phrase on the web, and an option to search in Wikipedia will appear in the context menu. Results open in a new tab, so your current page is not lost.</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<p>
<img src="img/screen1.png" style="width: 100%; max-width:764px;">
</p>
</div>
<div class="col-md-6">
<p>
<img src="img/screen4.png" style="width: 100%; max-width:764px;">
</p>
</div>
</div>
<br>
<div class="row">
<div class="col-md-6">
<h2>Settings page</h2>
<p>Type in "wiki settings" into the address bar and press the Enter key to open the extension settings. You can change the default search language to any of the 300+ languages supported by Wikipedia.</p>
</div>
<div class="col-md-6">
<h2>Multi-language</h2>
<p>You can override the default language by typing a Wikipedia language prefix before your search. For example, to search for Google in the French Wikipedia, you would type "fr Google".</p>
</div>
</div>
<div class="row">
<div class="col-md-6">
<p>
<img src="img/screen3.png" style="width: 100%; max-width:764px;">
</p>
</div>
<div class="col-md-6">
<p>
<img src="img/screen2.png" style="width: 100%; max-width:764px;">
</p>
</div>
</div>
<br>
<div class="row">
<div class="col-md-12">
<h2>Having issues?</h2>
<p>If you find a bug, or have a suggestion for a new feature, please <a href="https://github.com/corbindavenport/noplugin/issues" target="_blank">create an issue on the NoPlugin GitHub repository</a> or <a href="mailto:[email protected]?subject=Wikipedia%20Search%20Bug%20Report">submit an issue via email</a>.</p>
<div class="col-md-12">
<!-- Language -->
<div class="form-group row">
<label for="wikipedia-search-language-select" class="col-sm-2 col-form-label">Language</label>
<div class="col-sm-10">
<select id="wikipedia-search-language-select" class="custom-select" disabled>
<option value="loading" selected>Loading languages...</option>
</select>
<small class="form-text text-muted">This is the language used for searches. The language list is automatically updated every time you open this settings page, using the <a href="https://www.mediawiki.org/wiki/API:Query" target="_blank">Wikipedia Query API</a>.</small>
</div>
</div>
</div>
<br>
<div class="row">
<div class="col-md-12">
<h2>Donate</h2>
</div>
<div class="col-md-6">
</div>

<div class="row">
<div class="col-12">
<div class="alert alert-info" role="alert">
<p>If you find Wikipedia Search useful, please donate to support continued development. It would mean a lot!</p>
<p><b>Note:</b> Wikipedia Search is not affliated with Wikipedia or the Wikimedia Foundation. If you wish to donate to the Wikimedia Foundation, you can do so <a href="https://donate.wikimedia.org" target="_blank">here</a>.</p>
<p class="review-info"></p>
</div>
<div class="col-md-6">
<p>
<button type="button" class="btn btn-success btn-block link-btn" data-url="https://www.patreon.com/corbindavenport">Donate via Patreon</button>
</p>
<p>
<button type="button" class="btn btn-success btn-block link-btn" data-url="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=4SZVSMJKDS35J&lc=US&item_name=Wikipedia%20Search%20Donation&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">Donate via PayPal</button>
<div class="row">
<div class="col-6">
<button type="button" class="btn btn-block btn-primary link-btn" data-url='https://www.patreon.com/corbindavenport'>Donate via Patreon</button>
</div>
<div class="col-6">
<button type="button" class="btn btn-block btn-primary link-btn" data-url="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=4SZVSMJKDS35J&lc=US&item_name=Wikipedia%20Search%20Donation&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted">Donate via PayPal</button>
</div>
</div>
</p>
<p id="supporters">Loading supporters...</p>
</div>
</div>
</div>

</div>

<hr>

<footer>
<p>Wikipedia Search uses code from <a href="https://jquery.com/" target="_blank">jQuery</a>, <a href="https://getbootstrap.com/" target="_blank">Bootstrap</a>, and <a href="https://github.com/hamczu/OmniWiki" target="_blank">OmniWiki</a>. You can find Wikipedia Search's source code <a href="https://github.com/corbindavenport/wikipedia-search" target="_blank">on GitHub</a>.</p>
</footer>
</div> <!-- /container -->

<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/shared.js"></script>
<script src="js/settings.js"></script>
<script src="js/bootstrap.min.js"></script>

</body>

</html>
Loading

0 comments on commit 717bbfc

Please sign in to comment.