Skip to content

Commit

Permalink
uploaded wikipedia search 6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
corbindavenport committed Apr 9, 2015
1 parent 58ed775 commit b2357d5
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 31 deletions.
20 changes: 6 additions & 14 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. Wikipedia icon from the [Faenza](http://tiheum.deviantart.com/art/Faenza-Icons-173323228) icon pack.__

---------------------------------------------------------
__New in Wikipedia Search 6.3:__
* __Wikipedia Integration:__ Wikipedia Search now integrates more deeply with Wikipedia, with options to show a panel of options on Wikipedia article pages for quick access to settings, and even hiding the search bar.
* __Reset options:__ There is now a reset button in the settings, to...well...reset the settings.
* __Under-the-hood improvements:__ Wikipedia Search 6.3 continues a clean-up of the overall codebase.
* And a secret easter egg hidden in the code ;)

__New in Wikipedia Search 6.2:__
* __Opera support:__ Opera browser is now officially supported by Wikipedia Search!
* __Context menu:__ Minor tweaks to the right-click context menu.
Expand Down Expand Up @@ -60,20 +66,6 @@ __New in Wikipedia Search 4.0:__
* Code now available on Github
* One-time alert that it is open source

__New in Wikipedia Search 3.3.1:__
* Fixed (very) small bug on extension options page

__New in Wikipedia Search 3.3:__
* Fixed bug where language selection would not save
* Rewrite to work with Chrome manifest 2

__New in Wikipedia Search 3.2.1:__
* Fixed bug where the search icon would not show up

__New in Wikipedia Search 3.2:__
* Updated to Manifest 2
* Requires Chrome 18 or newer

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

This program is free software: you can redistribute it and/or modify
Expand Down
13 changes: 13 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ chrome.runtime.onInstalled.addListener(function(details){
localStorage["shortcut"] = "off";
}
}
if (localStorage.getItem("contentscripts") === null) {
localStorage["contentscripts"] = "on";
}
if (localStorage.getItem("hidesearch") === null) {
localStorage["hidesearch"] = "off";
}
}
if(localStorage.getItem("version") != chrome.runtime.getManifest().version){
chrome.tabs.create({'url': chrome.extension.getURL('welcome.html')});
Expand Down Expand Up @@ -171,4 +177,11 @@ chrome.omnibox.onInputEntered.addListener(function(text) {
} else {
chrome.tabs.update(null, {url: protocol + language + ".wikipedia.org/w/index.php?search=" + text});
}
});

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.method == "getLocalStorage")
sendResponse({data: localStorage[request.key]});
else
sendResponse({}); // snub them.
});
56 changes: 56 additions & 0 deletions content_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
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 (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
*/

// Wikipedia integration

chrome.runtime.sendMessage({method: "getLocalStorage", key: "contentscripts"}, function(response) {
if (response.data === "on") {
if (window.location.href.indexOf("/wiki/") > -1) {
// Add extra button for Wikipedia Search on left panel
document.getElementById("p-navigation").innerHTML = document.getElementById("p-navigation").innerHTML + '<h3 style="display: block; padding-top: 5px; background-position: top left; background-repeat: no-repeat; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIwAAAABCAAAAAAphRnkAAAAJ0lEQVQIW7XFsQEAIAyAMPD/b7uLWz8wS5youFW1UREfiIpH1Q2VBz7fGPS1dOGeAAAAAElFTkSuQmCC); background-image: url(//bits.wikimedia.org/static-1.25wmf24/skins/Vector/images/portal-break.png?2015-04-01T19:10:00Z)!ie;">Wikipedia Search ' + chrome.runtime.getManifest().version + '</h3><div class="body"><ul><li><a href="' + chrome.extension.getURL('settings.html') + '" title="Open Wikipedia Search extension settings in new tab" target="_blank">Extension Settings</a></li><li><a href="http://github.com/corbindavenport/wikipedia-search" title="Open Wikipedia Search extenion project on GitHub in a new tab" target="_blank">GitHub Project</a></li><li><a href="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" title="Donate to the Wikipedia Search extension developer via PayPal in a new tab" target="_blank">Donate via PayPal</a></li><li><a title="Donate to the Wikipedia Search extension developer via Bitcoin" target="_blank">Donate via Bitcoin</a></li><li><a href="http://github.com/corbindavenport/wikipedia-search/issues/new" title="Submit bug report through GitHub" target="_blank">Report bug</a></li></ul></div>';

// Add information about wikipedia search to top header
header = document.getElementById("p-personal").children[1];
header.innerHTML = header.innerHTML + '<li>Wikipedia Search ' + chrome.runtime.getManifest().version + '</li>';

// Add Wikipedia Search info to footer
document.getElementById("footer-info-copyright").innerHTML = document.getElementById("footer-info-copyright").innerHTML + '<br /><br />Wikipedia Search ' + chrome.runtime.getManifest().version + ' is developed by ' + chrome.runtime.getManifest().author + ' and licensed under the GPLv3 license. The source code for Wikipedia Search is freely available on its <a href="' + chrome.runtime.getManifest().homepage_url + '" target="blank_">GitHub repository</a>.';

// Bitcoin Donation
document.body.innerHTML = '<div id="bitcoin" style="display: none; background-color: #FFF; color: #333; font: 14px arial, sans-serif; border-bottom: 1px solid #A9A8A6; padding: 5px; width: 100%; position: fixed; z-index:500;"><b>Please send bitcoin to the following address:</b> <span style="font-family:Monaco,Menlo,Consolas,monospace;">1GSbhaUp8JSRepqQceHzrGhV1bPk9hcPuS</span></div>' + document.body.innerHTML;
document.querySelector('a[title="Donate to the Wikipedia Search extension developer via Bitcoin"]').onclick=function(){document.getElementById("bitcoin").style.display = "block"};
}
} else {
if (window.location.href.indexOf("/wiki/") > -1) {
var header = document.getElementById("p-personal").children[1];
header.innerHTML = header.innerHTML + '<li>Wikipedia Search ' + chrome.runtime.getManifest().version + '</li>';
}
}
});

// Hide search on Wikipedia home page and article pages

chrome.runtime.sendMessage({method: "getLocalStorage", key: "hidesearch"}, function(response) {
if (response.data === "on" && window.location.href.indexOf("/wiki/") > -1) {
document.getElementById("searchInput").setAttribute("disabled","disabled");
document.getElementById("searchInput").setAttribute("placeholder","Address Bar search enabled");
} else if (response.data === "on" && document.body.querySelector(".search-form")) {
document.body.querySelector(".search-form").innerHTML = '<div style="background-color: #f9f9f9; border: 1px solid #aaa; margin-top: 0.5em; padding: 0.7em; width: auto;">Inline search disabled, use your browser address bar.</div>';
}
});

// The easter egg can be enabled by running this command in the JavaScript console, with the Wikipedia Search settings open:
// localStorage['easteregg'] = "on";
// and turned off with:
// localStorage['easteregg'] = "off";

chrome.runtime.sendMessage({method: "getLocalStorage", key: "easteregg"}, function(response) {
if (response.data === "on" && window.location.href.indexOf("/wiki/") > -1) {
document.querySelector(".mw-wiki-logo").style.backgroundImage = "url('http://upload.wikimedia.org/wikipedia/commons/5/5f/Wiki_logo_The_Cunctator.png')";
}
});
11 changes: 10 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"manifest_version": 2,
"name": "Wikipedia Search",
"version": "6.2",
"version": "6.3",
"author": "Corbin Davenport",
"homepage_url": "https://github.com/corbindavenport/wikipedia-search",
"description": "Search Wikipedia in every language from the address bar.",
"options_page": "settings.html",
"omnibox": {
Expand All @@ -19,6 +21,13 @@
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["http://*.wikipedia.org/*", "https://*.wikipedia.org/*"],
"js": ["content_script.js"],
"run_at": "document_end"
}
],
"icons":{
"16":"icon16.png",
"32":"icon32.png",
Expand Down
9 changes: 6 additions & 3 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,20 @@ <h2>Settings</h2>
</td>
</tr>
</table>
<input type="checkbox" id="shortcut"><label for="shortcut" id="shortcut-label">Enable settings shortcut in search results</label>
<p><input type="checkbox" id="shortcut"><label for="shortcut" id="shortcut-label">Enable settings shortcut in search results</label></p>
<p><input type="checkbox" id="contentscripts"><label for="contentscripts">Show Wikipedia Search panel on Wikipedia</label></p>
<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="save" value="Save">
<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>
<h2>Donate</h2>
<p>If you find Wikipedia Search useful, please donate to support continued development. It would mean a lot!</p>
<p>Just like Wikipedia itself, Wikipedia Search is completely free and open for anyone to use or contribute to. If you find Wikipedia Search useful, please donate to support continued development. It would mean a lot!</p>
<div id="bitcoin">
<p><b>Please send bitcoin to the following address:</b></p>
<p style="background:#ebebeb; padding:10px; font-family:Monaco,Menlo,Consolas,'Courier New',monospace; text-align:center; overflow-wrap:break-word !important;">1GSbhaUp8JSRepqQceHzrGhV1bPk9hcPuS</p>
Expand Down
10 changes: 5 additions & 5 deletions welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
</head>
<body>
<section id="wrapper" class="wrapper enabled">
<h1>Welcome to Wikipedia Search 6.2!</h1>
<h1>Welcome to Wikipedia Search 6.3!</h1>
<article>
<h2>What's New?</h2>
<p><b>Opera support:</b> Opera browser is now officially supported by Wikipedia Search!</p>
<p><b>Context menu:</b> Minor tweaks to the right-click context menu.</p>
<p><b>Settings:</b> You can now turn the settings shortcut in search results on or off.</p>
<p><b>Under-the-hood improvements:</b> Most of Wikipedia Search 6.2 has been re-written to clean up the overall codebase. There's also less bugs!</p>
<p><b>Wikipedia Integration:</b> Wikipedia Search now integrates more deeply with Wikipedia, with options to show a panel of options on Wikipedia article pages for quick access to settings, and even hiding the search bar.</p>
<p><b>Reset options:</b> There is now a reset button in the settings, to...well...reset the settings.</p>
<p><b>Under-the-hood improvements:</b> Wikipedia Search 6.3 continues a clean-up of the overall codebase.</p>
<p><i>And a secret easter egg hidden in the code ;)</i></p>
</article>
<article>
<h2>Getting Started</h2>
Expand Down
Binary file removed wikipedia-search.zip
Binary file not shown.
51 changes: 43 additions & 8 deletions wikipedia.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ function save_options() {
} else {
localStorage["shortcut"] = "off";
}
if (document.getElementById("contentscripts").checked === true) {
localStorage["contentscripts"] = "on";
} else {
localStorage["contentscripts"] = "off";
}
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(){
Expand All @@ -24,12 +34,25 @@ function save_options() {
}
}

function doPayPalDonation() {
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" });
}

function doBitcoinDonation() {
document.getElementById("bitcoin").style.display = "block";
function reset_options() {
document.getElementById("language").value = "en";
localStorage["language"] = "en";
document.getElementById("protocol").value = "https://";
localStorage["protocol"] = "https://";
document.getElementById("shortcut").checked = true;
localStorage["shortcut"] = "on";
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);
}

window.addEventListener('load',function() {
Expand All @@ -41,7 +64,18 @@ window.addEventListener('load',function() {
} 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;
} 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;
Expand All @@ -64,10 +98,11 @@ window.onload = function() {

if (document.getElementById("language")) {
document.querySelector('input[value="Save"]').onclick=save_options;
document.querySelector('input[value="Reset"]').onclick=reset_options;
}

if (document.getElementById("settings-buttons")) {
document.querySelector('input[value="Donate via PayPal"]').onclick=doPayPalDonation;
document.querySelector('input[value="Donate via Bitcoin"]').onclick=doBitcoinDonation;
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";};
}
}

0 comments on commit b2357d5

Please sign in to comment.