From 93ccb6802bdca173f69a317496942cfc1a803292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 12 Oct 2013 11:16:07 +0200 Subject: [PATCH] Change way of getting domain, use more efficient parseuri.js --- firefox_addon/README.md | 2 +- firefox_addon/lib/main.js | 4 +++- firefox_addon/lib/parseuri.js | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 firefox_addon/lib/parseuri.js diff --git a/firefox_addon/README.md b/firefox_addon/README.md index 27b163e..dec9e9d 100644 --- a/firefox_addon/README.md +++ b/firefox_addon/README.md @@ -1,4 +1,4 @@ -gPass : global password +gPass : global Password ======================= Introduction diff --git a/firefox_addon/lib/main.js b/firefox_addon/lib/main.js index f755ca1..2f9b8fd 100644 --- a/firefox_addon/lib/main.js +++ b/firefox_addon/lib/main.js @@ -25,6 +25,7 @@ var Hashtable = require("jshashtable-3.0").Hashtable; // http://code.google.com/p/crypto-js/ var sha256 = require("jssha256").sha256; var aes = require("jsaes").aes; +var parseURI = require("parseuri").parseURI; var prefSet = require("simple-prefs"); // Global document var doc; @@ -62,7 +63,8 @@ function on_sumbit() var fields = form.getElementsByTagName("input"); var my_map = new Hashtable(); - domain = form.ownerDocument.domain; + domain = parseURI.parseUri(form.ownerDocument.baseURI); + domain = domain["host"]; // Get all for (i=0; i +// MIT License + +exports.parseURI = { + + parseUri : function (str) { + var o = { + strictMode: false, + key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], + q: { + name: "queryKey", + parser: /(?:^|&)([^&=]*)=?([^&]*)/g + }, + parser: { + strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, + loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ + }}, + m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), + uri = {}, + i = 14; + + while (i--) uri[o.key[i]] = m[i] || ""; + + uri[o.q.name] = {}; + uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { + if ($1) uri[o.q.name][$1] = $2; + }); + + return uri; + } +};