summaryrefslogtreecommitdiff
path: root/data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.js~
diff options
context:
space:
mode:
authorAmin Bandali <bandali@gnu.org>2020-01-03 01:12:39 -0500
committerAmin Bandali <bandali@gnu.org>2020-01-03 02:23:25 -0500
commit123962d4320bfe827e90aa031aa9964946cbc238 (patch)
treee3c1dba4350df2d9de8999ca6e19a8e1a25fd0e9 /data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.js~
parentd1be83a59f1a123401d50f5bdd393a4de102e421 (diff)
General clean-ups for the new workarounds extension
* data/extensions/gnuzilla-ext-workarounds@gnu.org/jquery-3.4.1.min.js: Remove, since it's a duplicate and not needed. * data/extensions/gnuzilla-ext-workarounds@gnu.org/manifest.json: Re-indent, remove "jquery-3.4.1.min.js" from content_scripts js files: as far as I see, it's not used in any of the workaround files, and is only used in html/domestic.html; but html/ already has a copy of it. So there's no point in keeping a second copy around and injecting it to the matched urls along with the other workaround scripts. * data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.html: Update the extension name here to match the manifest. * data/extensions/gnuzilla-ext-workarounds@gnu.org/README~, data/extensions/gnuzilla-ext-workarounds@gnu.org/background.js~, data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.html~, data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.js~, data/extensions/gnuzilla-ext-workarounds@gnu.org/html/usps_postage.js~, data/extensions/gnuzilla-ext-workarounds@gnu.org/jquery-3.4.1.min.js, data/extensions/gnuzilla-ext-workarounds@gnu.org/manifest.json~, data/extensions/gnuzilla-ext-workarounds@gnu.org/workaround/googledocs_main.js~, data/extensions/gnuzilla-ext-workarounds@gnu.org/workaround/goteo_main.js~, data/extensions/gnuzilla-ext-workarounds@gnu.org/workaround/mcdonalds_wifi.js~, data/extensions/gnuzilla-ext-workarounds@gnu.org/workaround/paygov_main.js~, data/extensions/gnuzilla-ext-workarounds@gnu.org/workaround/rsf_main.js~, data/extensions/gnuzilla-ext-workarounds@gnu.org/workaround/sumofus_main.js~: Remove auto-created backup files.
Diffstat (limited to 'data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.js~')
-rw-r--r--data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.js~375
1 files changed, 0 insertions, 375 deletions
diff --git a/data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.js~ b/data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.js~
deleted file mode 100644
index 693a831..0000000
--- a/data/extensions/gnuzilla-ext-workarounds@gnu.org/html/domestic.js~
+++ /dev/null
@@ -1,375 +0,0 @@
-
-/*
- Copyright (C) 2019 Nathan Nichols
-
- 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/>.
-*/
-
-
-console.log("main.js");
-
-
-function is_in(a, arr){
- for(var i = 0; i < arr.length; i++){
- if(a == arr[i]){
- return true;
- }
- }
-
- return false;
-
-}
-function disable(name){
- off = document.getElementsByName(name);
- for(var i = 0; i < off.length; i++){
- off[i].style = "display:none;"
- }
-}
-function enable(name){
- on = document.getElementsByName(name);
- for(var i = 0; i < on.length; i++){
- on[i].style = ""
- }
-}
-
-
-
-function tag(name){
- return "<"+name+">";
-}
-function etag(name){
- return "</"+name+">";
-
-}
-function surround(name,content){
- return tag(name) + content + etag(name);
-}
-function visible(name){
- if(document.getElementsByName(name)[0].style.display == "none"){
- return false;
- }else{
- return true;
- }
-}
-
-function gen_package(data){
- var res = '<Package ID="0">';
- res = res + surround("Service", data["Service"]);
-
- if(visible("FirstClassMailType")){
- res=res+surround("FirstClassMailType", data["FirstClassMailType"]);
- }
- res = res + surround("ZipOrigination", data["ZipOrigination"]);
- res = res + surround("ZipDestination", data["ZipDestination"]);
- res = res + surround("Pounds", data["Pounds"]);
- res = res + surround("Ounces", "0");
-
- res = res + surround("Container", data["Container"]);
- res = res + surround("Machinable", data["Machinable"]);
-
- res = res + etag("Package");
-
- return res;
-}
-
-function build_xml_domestic(data){
- var res = '<RateV4Request USERID="' +data["USERID"] +'">';
- res = res + "<Revision>2</Revision>";
- res = res + gen_package(data);
- res = res + etag("RateV4Request");
- return res;
-}
-
-function check_domestic(req){
- console.log("Form changed.");
-
- serv = req["Service"];
- // "Machinable" required for:
- mach=["FIRST CLASS","LETTER","FLAT","RETAIL GROUND","ALL","ONLINE"];
- if(is_in(serv, mach) == true){
- enable("Machinable");
- }else{
- disable("Machinable")
- }
-
- if(serv == "Retail Ground"){
- enable("GroundOnly");
- }else{
- disable("GroundOnly");
- }
-
- fcmt=["FIRST CLASS","FIRST CLASS COMMERCIAL","FIRST CLASS HFP COMMERCIAL"];
- if(is_in(serv, fcmt)){
- enable("FirstClassMailType");
- }else{
- disable("FirstClassMailType");
- }
-
- if(resp["ContentType"] == "LIVES"){
- enable("ContentDescription");
- }else{
- disable("ContentDescription");
- }
-};
-function check_intl(req){
- console.log("Form changed.");
-
-};
-
-
-function byname(name){
- return document.getElementsByName(name)[0].value;
-}
-
-// Return an array of the selected opion values
-function select_values(name) {
- var opts = document.getElementsByName(name)[0].options
- var res = [];
- for(var i = 0; i < opts.length; i++){
- if(opts[i].selected){
- res.push(opts[i].value);
- }
- }
- return res;
-}
-
-// reads the form and returns a dictionary
-function read_domestic(){
- resp = {};
- resp["USERID"] = byname("USERID");
- resp["Service"] = byname("Service");
- resp["FirstClassMailType"] = byname("FirstClassMailType");
- resp["Machinable"] = byname("Machinable");
- resp["ZipOrigination"] = byname("ZipOrigination");
- resp["ZipDestination"] = byname("ZipDestination");
- resp["Pounds"] = byname("Pounds");
- resp["Container"] = byname("Container");
- //resp["Size"] = byname("Size");
- resp["Width"] = byname("Width");
- resp["Length"] = byname("Length");
- resp["Height"] = byname("Height");
- resp["Girth"] = byname("Girth");
- resp["Value"] = byname("Value");
- resp["AmountToCollect"] = byname("AmountToCollect");
- resp["SpecialServices"] = select_values("SpecialService");
- resp["ContentType"] = byname("ContentType");
-
- if(resp["ContentType"] == "DEFAULT"){
- resp["ContentType"] = "";
- }
- return resp;
-}
-
-
-// reads the form and returns a dictionary
-function read_intl(){
- resp = {};
- resp["USERID"] = byname("USERID2");
- resp["Machinable"] = byname("Machinable2");
- resp["MailType"] = byname("MailType");
- //resp["POBoxFlag"] = byname("POBoxFlag");
- //resp["GiftFlag"] = byname("GiftFlag");
- resp["ValueOfContents"] = byname("ValueOfContents");
- resp["Country"] = byname("Country");
- resp["Pounds"] = byname("Pounds2");
- resp["GiftFlag"] = byname("GiftFlag");
- resp["POBoxFlag"] = byname("POBoxFlag");
- resp["OriginZip"] = byname("OriginZip");
- resp["Width"] = byname("Width2");
- resp["Length"] = byname("Length2");
- resp["Height"] = byname("Height2");
- resp["Girth"] = byname("Girth2");
- resp["Container"] = byname("Container2");
- resp["CommercialFlag"] = byname("CommercialFlag");
- resp["CommercialPlusFlag"] = byname("CommercialPlusFlag");
- resp["Size"] = byname("Size2");
-
-
- return resp;
-}
-
-function decode_html(input){
- var e = document.createElement('div');
- e.innerHTML = input;
- return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
-}
-
-
-function make_row(name, avail, price){
- res = "<tr>";
- res = res+"<td>"+name+"</td>";
- res = res+"<td>"+avail+"</td>";
- res = res+"<td>"+price+"</td>";
- res = res+"</tr>\n";
- return res;
-
-}
-
-function parse_response(resp){
- console.log(resp.documentElement.outerHTML);
- xml_doc = $.parseXML(resp.documentElement.outerHTML);
- $xml = $(xml_doc);
- errs = $xml.find("Error");
- console.log(errs);
-
- var res = "";
-
- if(errs.length > 0){
- for(var i = 0; i < errs.length; i++){
- res = res+i.toString()+": "+$(errs[i]).find("Description")[0].innerHTML;
- res = res +"<br>";
- }
- $("#errors").html(res)
- $("#mainrate").html("");
- $("#results").html("");
-
- return "";
- }
-
- $pack = $($xml.find("Package")[0]);
-
- // Get Parse the main result
- mailserv = decode_html($pack.find("MailService")[0].innerHTML);
- rate = $pack.find("Rate")[0].innerHTML;
-
- var res = "";
- res = "<b>Mail Service:</b>"+mailserv+"<br>";
- res = res+"<b>Rate:</b>"+rate+"<br>\n"
-
- // Generate a table of the services available
- servs = $pack.find("SpecialService");
- table = make_row("<b> Service name </b>", "<b>Available</b>", "<b>Price</b>");
- for(var i = 0; i < servs.length; i++){
- serv = $(servs[i]);
- name = decode_html(serv.find("ServiceName")[0].innerHTML);
- avail = serv.find("Available")[0].innerHTML;
- price = serv.find("Price")[0].innerHTML;
- table = table + make_row(name,avail,price);
- }
-
- table = "<tbody>"+table+"</tbody>";
- $("#mainrate").html(res);
- $("#results").html(table);
- return table;
-}
-
-
-function make_api_call(url){
- $.ajax({
- url: url,
- cache: false,
- type: 'post',
- }).done(function(d){
- console.log("Success");
- var res = parse_response(d);
- //$("#results").html(res);
- }).always(function(){
-
- }).fail(function(d){
- console.log("Failed");
- console.log(d);
- });
-}
-
-function gen_package_intl(data){
- var res = "";
- res = res + '<Package ID="0">';
- res = res + surround("Pounds",data["Pounds"])
- res = res + surround("Ounces","0");
- res = res + surround("Machinable",data["Machinable"]);
- res = res + surround("MailType",data["MailType"]);
- /*
- res = res + "<GXG>"
- res = res + surround("POBoxFlag",data["POBoxFlag"]);
- res = res + surround("GiftFlag",data["GiftFlag"]);
- res = res + "</GXG>"
- */
- res = res + surround("ValueOfContents", data["ValueOfContents"]);
- res = res + surround("Country",data["Country"]);
- //res = res + surround("Size",data["Size"]);
- //res = res + surround("Container",data["Container"]);
- //res = res + surround("Width",data["Width"]);
- //res = res + surround("Length",data["Length"]);
- //res = res + surround("Height",data["Height"]);
- //res = res + surround("Girth",data["Girth"]);
- res = res + surround("OriginZip",data["OriginZip"]);
-
- res = res + '</Package>';
-
- return res;
-}
-
-
-function build_xml_intl(data){
- res = "";
- res = res + '<IntlRateV2Request USERID="'+data["USERID"]+'">';
- res = res + gen_package_intl(data);
-
- res = res + "</IntlRateV2Request>";
- console.log(res);
- return res;
-};
-
-
-
-window.addEventListener('load', (event) => {
-
- $("#button_domestic").bind("click",function(){
- console.log("Making request");
- r = read_domestic();
- check_domestic(r);
- url = "http://production.shippingapis.com/ShippingAPI.dll?API=RateV4&XML=";
- url = url + build_xml_domestic(r);
- console.log(url);
- make_api_call(url);
- });
-
- console.log("Window loaded.")
- disable("Machinable");
- disable("FirstClassMailType");
- disable("ContentDescription");
- disable("GroundOnly");
-
- document.getElementById("button_intl").style = "display:none;";
- document.forms[1].style = "display:none;";
-
- document.forms[0].addEventListener("change", function(){
- r = read_domestic();
- check_domestic(r);
- url = "http://production.shippingapis.com/ShippingAPI.dll?API=RateV4&XML=";
- url = url + build_xml_domestic(r);
- console.log(url);
- });
-
- $("#button_intl").bind("click",function(){
- console.log("Making request");
- r = read_intl();
- check_intl(r);
- url = "http://production.shippingapis.com/ShippingAPI.dll?API=IntlRateV2&XML=";
- url = url + build_xml_intl(r);
- console.log(url);
- make_api_call(url);
- });
-
- document.forms[1].addEventListener("change", function(){
- r = read_intl();
- url = "http://production.shippingapis.com/ShippingAPI.dll?API=IntlRateV2&XML=";
- url = url + build_xml_intl(r);
- console.log(url);
- });
-
-});
-
-
-