Skip to content

Commit

Permalink
Uploaded Wikipedia Search 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
corbindavenport committed Mar 29, 2016
1 parent c9c694c commit 038080e
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 136 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ If English isn't your main language, it's easy to change the language Wikipedia
__Wikipedia is a trademark of the Wikimedia Foundation.__

---------------------------------------------------------
__New in Wikipedia Search 8.0:__
* Updated settings page with auto-save.
* Added support for settings shortcut to Opera.
* Added support for the Urdu, Phasa Thai, and Min Nan Wikipedias.
* Cleaned up code.

__New in Wikipedia Search 7.0.2:__
* Added warning when using Wikipedia Search over HTTP connection.

Expand Down
64 changes: 43 additions & 21 deletions js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,38 @@ You should have received a copy of the GNU General Public License along with thi

chrome.runtime.onInstalled.addListener(function(details){
if(details.reason == "update" || "install"){
// Transfer data from Wikipedia Search 7.0.2 or below
// Wikipedia Search 7.1+ use booleans for localStorage
if (localStorage.getItem("shortcut") === "on") {
localStorage["shortcut"] = "true";
} else if (localStorage.getItem("shortcut") === "off") {
localStorage["shortcut"] = "false";
}
if (localStorage.getItem("contentscripts") === "on") {
localStorage["contentscripts"] = "true";
} else if (localStorage.getItem("contentscripts") === "off") {
localStorage["contentscripts"] = "false";
}
if (localStorage.getItem("hidesearch") === "on") {
localStorage["hidesearch"] = "true";
} else if (localStorage.getItem("hidesearch") === "off") {
localStorage["hidesearch"] = "false";
}

if (localStorage.getItem("language") === null) {
localStorage["language"] = "en";
}
if (localStorage.getItem("protocol") === null) {
localStorage["protocol"] = "https://";
}
if (localStorage.getItem("donation") === null) {
localStorage["donation"] = "yes";
}
if (localStorage.getItem("shortcut") === null) {
if ((window.navigator.userAgent.indexOf("OPR") > -1) === false) {
localStorage["shortcut"] = "on";
} else {
// Shortcut to options is not functional on Opera, possibly a bug
localStorage["shortcut"] = "off";
}
localStorage["shortcut"] = "true";
}
if (localStorage.getItem("contentscripts") === null) {
localStorage["contentscripts"] = "on";
localStorage["contentscripts"] = "true";
}
if (localStorage.getItem("hidesearch") === null) {
localStorage["hidesearch"] = "off";
localStorage["hidesearch"] = "false";
}
}
if(localStorage.getItem("version") != chrome.runtime.getManifest().version){
Expand Down Expand Up @@ -98,21 +108,33 @@ chrome.omnibox.onInputChanged.addListener(function(text, suggest) {
if (text.length > 0) {
currentRequest = suggests(text, function(data) {
var results = [];
if (localStorage.getItem("shortcut") === "on") {
num = 4;
// Opera only supports showing four search results at a time, while Chrome can show five
// When the settings shortcut is enabled, it takes up one of the search results slots
// If shortcut is disabled = Five search results in Chrome, four search results in Opera
// If shortcut is enabled = Four search results in Chrome, three search results in Opera
if (localStorage.getItem("shortcut") === "true") {
if (window.navigator.userAgent.indexOf("OPR") > -1) {
num = 3;
} else {
num = 4;
}
} else {
num = 5;
if (window.navigator.userAgent.indexOf("OPR") > -1) {
num = 4;
} else {
num = 5;
}
}
for(var i = 0; i < num; i++){
results.push({
content: data[1][i],
description: data[1][i]
});
}
if (localStorage.getItem("shortcut") === "on") {
if (localStorage.getItem("shortcut") === "true") {
results.push({
content: "settings",
description: "Open Wikipedia Search options"
description: "<dim>Open settings for Wikipedia Search</dim>"
});
}
suggest(results);
Expand All @@ -121,15 +143,15 @@ chrome.omnibox.onInputChanged.addListener(function(text, suggest) {

});

function resetDefaultSuggestion() {
function resetDefaultSuggestion() {
chrome.omnibox.setDefaultSuggestion({
description: ' '
});
};

resetDefaultSuggestion();
var searchLabel = chrome.i18n.getMessage('search_label');
function updateDefaultSuggestion(text) {
function updateDefaultSuggestion(text) {
chrome.omnibox.setDefaultSuggestion({
description: searchLabel + 'Search on Wikipedia: %s'
});
Expand All @@ -149,11 +171,11 @@ function suggests(query, callback) {
var language = localStorage["language"];
var protocol = localStorage["protocol"];
var req = new XMLHttpRequest();

req.open("GET", protocol + language + ".wikipedia.org/w/api.php?action=opensearch&namespace=0&suggest=&search=" + query, true);
req.onload = function(){
if(this.status == 200){
try{
try{
callback(JSON.parse(this.responseText));
}catch(e){
this.onerror();
Expand Down Expand Up @@ -181,4 +203,4 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
sendResponse({data: localStorage[request.key]});
else
sendResponse({}); // snub them.
});
});
4 changes: 2 additions & 2 deletions js/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ You should have received a copy of the GNU General Public License along with thi
// Wikipedia integration

chrome.runtime.sendMessage({method: "getLocalStorage", key: "contentscripts"}, function(response) {
if (response.data === "on") {
if (response.data === "true") {
if (window.location.href.indexOf("/wiki/") > -1) {
// Add extra button for Wikipedia Search on left panel
var wikipanel = document.createElement("div");
Expand All @@ -34,7 +34,7 @@ chrome.runtime.sendMessage({method: "getLocalStorage", key: "contentscripts"}, f
// Hide search on Wikipedia article pages

chrome.runtime.sendMessage({method: "getLocalStorage", key: "hidesearch"}, function(response) {
if (response.data === "on" && window.location.href.indexOf("/wiki/") > -1) {
if (response.data === "true" && window.location.href.indexOf("/wiki/") > -1) {
document.getElementById("searchform").style.display = "none";
document.getElementById("p-search").style.marginRight = "0";
}
Expand Down
4 changes: 4 additions & 0 deletions js/jquery-2.1.3.min.js

Large diffs are not rendered by default.

145 changes: 42 additions & 103 deletions js/wikipedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,117 +6,56 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
*/

function save_options() {
if (document.getElementById("language")) {
localStorage["language"] = document.getElementById("language").value;
localStorage["protocol"] = document.getElementById("protocol").value;
if (document.getElementById("protocol").value === "http://") {
document.getElementById("protocolalert").style.display = 'block';
}
if (document.getElementById("shortcut").checked === true) {
localStorage["shortcut"] = "on";
} else {
localStorage["shortcut"] = "off";
}
if (document.getElementById("contentscripts").checked === true) {
localStorage["contentscripts"] = "on";
$(window).load(function() {
// Settings Page
if ($("#language").length) {
$("#bitcoin").hide();
if ($("#protocol").val() === "http://") {
$("#protocolalert").show();
} else {
localStorage["contentscripts"] = "off";
$("#protocolalert").hide();
}
if (document.getElementById("hidesearch").checked === true) {
localStorage["hidesearch"] = "on";
} else {
localStorage["hidesearch"] = "off";
}
document.getElementById("save").value = "Saved!"
document.getElementById("save").style.background = "#009900";
setTimeout(function(){
document.getElementById("save").value = "Save";
document.getElementById("save").style.background = "#4d90fe";
}, 2000);
$("#language").val(localStorage["language"]);
$("#protocol").val(localStorage["protocol"]);
$("#shortcut").prop("checked", $.parseJSON(localStorage.getItem("shortcut")));
$("#contentscripts").prop("checked", $.parseJSON(localStorage.getItem("contentscripts")));
$("#hidesearch").prop("checked", $.parseJSON(localStorage.getItem("hidesearch")));
}
}

function reset_options() {
document.getElementById("language").value = "en";
localStorage["language"] = "en";
document.getElementById("protocol").value = "https://";
localStorage["protocol"] = "https://";
if ((window.navigator.userAgent.indexOf("OPR") > -1) === true) {
document.getElementById("shortcut").checked = false;
localStorage["shortcut"] = "off";
} else {
document.getElementById("shortcut").checked = true;
localStorage["shortcut"] = "on";
// Welcome Page
if ($(".version").length) {
$("#bitcoin").hide();
$(".version").html(chrome.runtime.getManifest().version);
}
document.getElementById("contentscripts").checked = true;
localStorage["contentscripts"] = "on";
document.getElementById("hidesearch").checked = false;
localStorage["hidesearch"] = "off";
document.getElementById("reset").value = "Reset!"
document.getElementById("reset").style.background = "#009900";
localStorage["language"] = document.getElementById("language").value;
localStorage["protocol"] = document.getElementById("protocol").value;
setTimeout(function(){
document.getElementById("reset").value = "Reset";
document.getElementById("reset").style.background = "#4d90fe";
}, 2000);
}
// Awesome New Tab Page Widget
if ($("#searchInput").length) {
$("#searchInput").keypress(function (e) {
if (e.which == 13) {
window.parent.location = localStorage.getItem("protocol") + localStorage.getItem("language") + ".wikipedia.org/w/index.php?search=" + encodeURI($("#searchInput").val());
return false;
}
});
}
});

window.addEventListener('load',function() {
if (document.getElementById("language")) {
document.getElementById("protocolalert").style.display = 'none';
document.getElementById("language").value = localStorage["language"];
document.getElementById("protocol").value = localStorage["protocol"];
if (localStorage.getItem("shortcut") === "on") {
document.getElementById("shortcut").checked = true;
} else {
document.getElementById("shortcut").checked = false;
}
if (localStorage.getItem("contentscripts") === "on") {
document.getElementById("contentscripts").checked = true;
} else {
document.getElementById("contentscripts").checked = false;
}
if (localStorage.getItem("hidesearch") === "on") {
document.getElementById("hidesearch").checked = true;
$(document).on('change', "input,select", function() {
if ($("#language").length) {
if ($("#protocol").val() === "http://") {
$("#protocolalert").show();
} else {
document.getElementById("hidesearch").checked = false;
}
document.getElementById("shortcut").value = localStorage["shortcut"];
document.getElementById("contentscripts").value = localStorage["contentscripts"];
if ((window.navigator.userAgent.indexOf("OPR") > -1) === true) {
document.getElementById("shortcut-label").innerHTML = "Enable settings shortcut in search results (not supported on Opera)";
document.getElementById("shortcut").disabled = true;
$("#protocolalert").hide();
}
localStorage["language"] = $("#language").val();
localStorage["protocol"] = $("#protocol").val();
localStorage.setItem("shortcut", $("#shortcut").is(":checked"));
localStorage.setItem("contentscripts", $("#contentscripts").is(":checked"));
localStorage.setItem("hidesearch", $("#hidesearch").is(":checked"));
}
});

function startSearch(event) {document.getElementById("searchform").submit();}

window.onload = function() {
var list = document.getElementsByClassName("version");
for (var i = 0; i < list.length; i++) {
list[i].innerHTML = chrome.runtime.getManifest().version;
}

if (document.getElementById("searchInput")) {
window.addEventListener('keydown', function() {
if (event.keyCode == 13) {
var text = document.getElementById("searchInput").value;
window.parent.location = localStorage["protocol"] + localStorage["language"] + ".wikipedia.org/w/index.php?search=" + text;
return false;
}
}, false);
}

if (document.getElementById("language")) {
document.querySelector('input[value="Save"]').onclick=save_options;
document.querySelector('input[value="Reset"]').onclick=reset_options;
}
$(document).on('click', "input[value='Donate via Bitcoin']", function() {
$("#bitcoin").show();
});

if (document.getElementById("settings-buttons")) {
document.querySelector('input[value="Donate via PayPal"]').onclick=function(){chrome.tabs.create({ 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_donate_LG%2egif%3aNonHosted" });};
document.querySelector('input[value="Donate via Bitcoin"]').onclick=function(){document.getElementById("bitcoin").style.display = "block";};
}
}
$(document).on('click', "input[value='Donate via PayPal']", function() {
window.open('https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=4SZVSMJKDS35J&lc=US&item_name=Peek%20Donation&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted', '_blank');
});
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": "7.0.2",
"version": "8.0",
"author": "Corbin Davenport",
"homepage_url": "https://github.com/corbindavenport/wikipedia-search",
"description": "Search Wikipedia in every language from the address bar.",
Expand Down
10 changes: 5 additions & 5 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Wikipedia Search</title>
<link rel="icon" type="image/png" href="img/icon16.png">
<script src="js/jquery-2.1.3.min.js"></script>
<script src="js/wikipedia.js"></script>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
Expand All @@ -26,7 +27,7 @@ <h2>How to use</h2>
<section class="settings-card">
<h2>Settings</h2>
<p>
<div id="protocolalert"><b>Using HTTP is not recommended.</b><br /><br /></div>
<div id="protocolalert"><b>Using HTTP is not recommended. Please only use it if the HTTPS search does not work.</b><br /><br /></div>
<table>
<tr>
<td>
Expand All @@ -38,6 +39,7 @@ <h2>Settings</h2>
<option value="ar" lang="ar">العربية</option><!-- Al-ʿArabīyah -->
<option value="az" lang="az">Azərbaycanca</option>
<option value="bg" lang="bg">Български</option><!-- Bǎlgarski -->
<option value="zh-min-nan" lang="nan">Bân-lâm-gú / Hō-ló-oē</option>
<option value="be" lang="be">Беларуская (Акадэмічная)</option><!-- Belaruskaya (Akademichnaya) -->
<option value="ca" lang="ca">Català</option>
<option value="cs" lang="cs">Čeština</option>
Expand Down Expand Up @@ -84,8 +86,10 @@ <h2>Settings</h2>
<option value="sh" lang="sh">Srpskohrvatski / Српскохрватски</option>
<option value="fi" lang="fi">Suomi</option>
<option value="sv" lang="sv">Svenska</option>
<option value="th" lang="th">ภาษาไทย</option><!-- Phasa Thai -->
<option value="tr" lang="tr">Türkçe</option>
<option value="uk" lang="uk">Українська</option><!-- Ukrayins’ka -->
<option value="ur" lang="ur">اردو</option><!-- Urdu -->
<option value="vi" lang="vi">Tiếng Việt</option>
<option value="vo" lang="vo">Volapük</option>
<option value="war" lang="war">Winaray</option>
Expand All @@ -110,10 +114,6 @@ <h2>Settings</h2>
<p><i>This provides quick access to Wikipedia Search settings and other features while on Wikipedia. The panel appears underneath the Wikipedia logo on any article page.</i></p>
<p><input type="checkbox" id="hidesearch"><label for="hidesearch">Hide search bar on Wikipedia home page and article pages (in favor of address bar search)</label></p>
</p>
<div id="saved">Saved!</div>
</section>
<section id="settings-buttons" class="buttons" style="display: block;">
<input class="g-button g-button-submit" type="button" id="reset" value="Reset"> <input class="g-button g-button-submit" type="button" id="save" value="Save">
</section>
</article>
<article>
Expand Down
9 changes: 5 additions & 4 deletions welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Wikipedia Search</title>
<link rel="icon" type="image/png" href="img/icon16.png">
<script src="js/jquery-2.1.3.min.js"></script>
<script src="js/wikipedia.js"></script>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
Expand All @@ -18,11 +19,11 @@
<h1>Welcome to Wikipedia Search <span class="version"></span>!</h1>
<article>
<h2>What's New?</h2>
<p><b>Panel improvements:</b> The Wikipedia Search panel (on the left side when browsing Wikipedia) has been improved and now correctly matches Wikipedia's design.</p>
<p><b>New language:</b> Added support for the Estonian, Georgian, Chechen, and Bulgarian Wikipedias.</p>
<p><b>Code cleanup:</b> Wikipedia Search 7.0's codebase has been improved, especially with content scripts being adjusted to work much better.</p>
<p><b>Settings:</b> Updated settings page with auto-save.</p>
<p><b>Opera Fixes:</b> The 'Open settings for Wikipedia Search' option while searching Wikipedia now works in Opera. If you are using Opera, you can now go to the Settings page and turn that feature on.</p>
<p><b>New languages:</b> Added support for the Urdu, Phasa Thai, and Min Nan Wikipedias.</p>
<p><b>Code cleanup:</b> Wikipedia Search 8.0 has moved much of the JavaScript code to JQuery, as well as other improvements.</p>
<p><i>And lots of minor bug fixes!</i></p>
<p><b>New in Wikipedia Search 7.0.2:</b> Added warning when using Wikipedia Search over HTTP connection.</p>
</article>
<article>
<h2>Getting Started</h2>
Expand Down
Loading

0 comments on commit 038080e

Please sign in to comment.