Comments (5)
[deleted comment]
from goosh.
Currently the calc command appears to only evaluate commands as straight
javascript
on the client's machine.
Using google calc would allow for units and imaginary numbers...
But unfortunately there's no api provided by google to do this. The easiest way
I can
imagine is to grab a whole google search page, then take out the right table
(I'd
look for the table with the calc picture in it myself).
This guy's done a similar thing in perl
http://johnbokma.com/perl/google-calculator.html ha
Original comment by [email protected]
on 16 Apr 2009 at 4:42
from goosh.
<table class=std><tr><td><img src=/images/calc_img.gif width=40 height=30
alt=""><td> <td nowrap ><h2 class=r style="font-size:138%">16.18 * 15 =
242.7</h2><tr><td> <td> <td><a
href="/intl/fr/help/features.html#calculator">Plus d'infos sur la fonction
calculatrice.</a></table>
There you go.
Starts on line 7 column 50.
Hope to help.
Original comment by [email protected]
on 25 Apr 2009 at 8:56
from goosh.
I haven't tested this, but if you substitute this for calc.js I think it should
work....
goosh.module.calculate = function(){
this.name = "calculate";
this.aliases = new Array("calculate","calc");
this.help = "evaluate a mathematical expression";
this.parameters = "[mathematical expression]";
this.search = function(params) {
var myurl = 'http://www.google.com/search?q=' + escape(params.replace(/\+/g,'\+')).replace(/\+/g,
'%2B');
var onloadHandler = function() { this.load(xmlRequest); };
var xmlRequest = new XMLHttpRequest();
xmlRequest.onload = onloadHandler;
xmlRequest.open("GET", myurl);
xmlRequest.setRequestHeader("Cache-Control", "no-cache");
xmlRequest.setRequestHeader('User-Agent',navigator.userAgent);
xmlRequest.send(null);
}
this.load = function(xmlRequest) {
if (xmlRequest.status == 200) {
var response = xmlRequest.responseText;
if(response.match(/calc_img.gif/)) {
var result = response.match(/calc_img.gif.*?(.*?)<\/b>/)[1];
goosh.gui.outln(result);
} else {
goosh.gui.error("could not calculate that.");
}
}
else {
goosh.gui.error("could not calculate that.");
}
}
this.call = function(args){
var out ="";
var exp = args.join(" ");
this.search(exp);
return false;
}
}
goosh.modules.register("calculate");
Original comment by [email protected]
on 12 Jun 2009 at 7:09
from goosh.
The only part that is probably helpful to you guys is the regular expression
(should be fairly flexible): /calc_img.gif.*?(.*?)<\/b>/
I'm sure you are all much more comfortable with AJAX and javascript than I am.
A much more robust way of doing it would be to turn the XMLHttpRequest
responseText into a new DOM
object, but that's a bit tricky to do in a browser compatible way, so I'll
leave that to you guys.
For that method, something like this should work...
//load responseText into response_dom somehow...
var images = response_dom.getElementsByTagName('img');
var node;
for(var i = 0; i < images.length; i++) {
if(x[i].src.match(/calc_img.gif/)) {
// The calc image is contained in a table cell in the same row as
the answer, which can be found in the
last cell. That is, it looks like
"<tr><td><img/></td>(<td></td>)*<td>result</td></tr>". The HTML is a
bit ugly... last child of the parent of the parent of the image should work for
now though.
node = x[i].parentNode.parentNode.lastChild;
}
}
if(node) {
goosh.gui.outln(node.textContent);
} else {
//error
}
Original comment by [email protected]
on 12 Jun 2009 at 7:22
from goosh.
Related Issues (20)
- Why it shows only four results against my search query? HOT 2
- Can not see gmail inbox HOT 5
- Image results
- Language setting not used ?
- 'place' command is not working HOT 5
- gmail comand not working
- login not working HOT 11
- calc does not know Pi
- A command to open a web should open a website on new page
- Back button does not work if we try to come back on shell interface from a web page
- Feature request: alias customisation (specific: want 'c' to expand to 'calculate', not clear)
- Can I get more than 64 results when searching into Google.
- New Request: Gooshified websites HOT 1
- i can't login my account!? HOT 1
- starting search with c always clears
- login error: 'X-Frame-Options' to 'DENY'
- News, Blog, etc Searches no longer work
- Changing number of displayed results from the default (4) no longer works. HOT 2
- To get access to someone else's mail
- Encoding problems with the “more results at google” link (Chrome/Win)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from goosh.