User:Eleanorg/Thematic1.1/traceroute plugin v1: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "==contentscript.js== Currently returning Chrome error: Uncaught SyntaxError: Unexpected token , What's the problem with the comma? <source lang=javascript> // ascertains curren...")
 
Line 2: Line 2:


Currently returning Chrome error: Uncaught SyntaxError: Unexpected token ,
Currently returning Chrome error: Uncaught SyntaxError: Unexpected token ,
<br />
What's the problem with the comma?
What's the problem with the comma?
<source lang=javascript>
<source lang=javascript>

Revision as of 14:46, 13 December 2011

contentscript.js

Currently returning Chrome error: Uncaught SyntaxError: Unexpected token ,
What's the problem with the comma?

// ascertains current page url
var currentUrl = window.location.href;

// sends the current page url to script, and gets back number of hops as an opacity value
$.ajax({ 
  type: "POST",
  url : "http://pzwart3.wdka.hro.nl/~egreenhalgh/hopsToPercent2.py",
  data : {url : currentUrl},
  success: function(data) {
    $(body).css({"opacity", data});
  }
});

manifest.json

Gives extension permission to use python script on PZI server.

{
  "name": "traceroute1",
  "version": "1.0",
  "description": "changes the opacity of web pages",
  "browser_action": {
    "default_icon": "icon.png"
  },
  "permissions": ["history", "http://pzwart3.wdka.hro.nl/~egreenhalgh/hopsToPercent2.py"],
  "content_scripts": [
    {
      "matches": ["*://*/*"],
      "js": ["jquery.js", "contentscript2.js"],
      "run_at": "document_end"
    }
  ]
}

hopsToPercent2.py

Lives on the PZI server.

#!/usr/bin/python
#-*- coding:utf-8 -*-

import os					# lets you use system commands inside the python script

###---------- GET URL FROM EXTENSION---------

form = cgi.FieldStorage()
site = form["url"].value			# url grabbed from the plugin's javascript

###---------- GET NO. OF HOPS--------------


command = "traceroute " + site + " | wc -l"   	# concatenates your site variable inside command to be sent to system
traceroute = os.popen(command,'r')            	# popen function opens system command with argument 'r' for 'read'
hopcount = float(traceroute.read()) - 1


###--------- CONVERT TO %------------------

def makePercent():
  percent = hopcount / 40               
  return(percent)