summaryrefslogtreecommitdiff
path: root/data/extensions/gnuzilla-ext-workarounds@gnu.org/workaround/paygov_main.js
blob: bb60b772c4aa0d1178cd5bc3ac10c3cf5561d2c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*

 Copyright (C) 2017-2019 Nathan Nichols
 Copyright (C) 2019 Free Software Foundation, Inc.

 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/>.

*/

if(document.location.href.indexOf("copyright.gov")!= -1){
    console.log("paygov_main.js");

    var content;
    function replace_regex(){
	content = document.documentElement.innerHTML;
	content = content.replace(/type\s*\=\s*("|')\s*hidden\s*\1\s*;/g,"");
	content = content.replace(/display\s*:\s*none/g,"");
	content = content.replace(/visibility\s*:\s*hidden/g,"");
	document.documentElement.innerHTML = "<html>"+content+"</html>";
    }

    if(window.getComputedStyle(document.body)["display"] == "none"){
	replace_regex();
    }
    function parseURL(a){
	let url = new URL(a);
	var result = Object.create(null);
	for(let i of url.searchParams) {
            result[i[0]] = i[1];
	}
	return JSON.stringify(result, undefined, 4); 
    }
    function get_domain(url){
	var domain = url.replace('http://','').replace('https://','').split(/[/?#]/)[0];
	if(url.indexOf("http://") == 0){
	    domain = "http://" + domain;
	}
	else if(url.indexOf("https://") == 0){
	    domain = "https://" + domain;
	}
	domain = domain + "/";
	domain = domain.replace(/ /g,"");
	return domain;
    }

    if(document.location.href.indexOf("pay.gov/tcsonline/") != -1){
	document.getElementsByClassName("text")[0].remove();
	console.log("detected payment page.");

	if(	document.getElementsByClassName("redbuttontext") !== null){
	    document.getElementsByClassName("redbuttontext")[0].remove();
	}


	document.getElementById("hiddenContinueButton").style.display = "";
	document.getElementById("statesCAN").remove();
	document.getElementById("statesUSA").remove();
	document.getElementById("stateText").value = "2 letter code";
    }

    if(get_domain(document.location.href) == "https://dmca.copyright.gov/"){

	document.body.style.display = true;
	var csrf = document.getElementsByName("_csrf")[0].content;
	console.log("csrf:"+csrf);
	var form = document.getElementById("file");
	if(form !== null){
	    console.log("upload page detected");
	    document.getElementById("btnUpload").disabled = false;
	    var xml = new XMLHttpRequest();
	    //xml.open("POST","https://dmca.copyright.gov/osp/home/alternatename/edit/alternatename.html",true);
	    var url = "https://dmca.copyright.gov/home/alternatename/edit/alternatenameajaxdisplay.html"		
	    console.log("OPENING "+url);		
	    xml.open("POST",url,true);
	    console.log("DONE");		
	    var spid = JSON.parse(parseURL(document.location.href))["spid"];
	    console.log("spid:"+spid);
	    var payload = {  
		"draw":1,
		"columns":[  
		    {  
			"data":"name",
			"name":"",
			"searchable":true,
			"orderable":true,
			"search":{  
			    "value":"",
			    "regex":false
			}
		    },
		    {  
			"data":null,
			"name":"",
			"searchable":true,
			"orderable":false,
			"search":{  
			    "value":"",
			    "regex":false
			}
		    }
		],
		"order":[  
		    {  
			"column":0,
			"dir":"asc"
		    }
		],
		"start":0,
		"length":10,
		"search":{  
		    "value":"",
		    "regex":false
		},
		"spid": spid
	    };

	    xml.onload = function(){
		console.log(this);
		var parser = new DOMParser();
		var doc = parser.parseFromString(this.responseText, "text/html");
		var error = doc.getElementsByClassName("page-head")[0];
		if(error != undefined){
		    console.log(error.innerText.replace(/\t/g,""));
		} else{
		    console.log(this.responseText);
		}
	    }
	    console.log("retrieving data...");
	    xml.setRequestHeader('Accept', 'application/json');
	    xml.setRequestHeader('Content-Type', 'application/json');
	    xml.setRequestHeader("csrfHeader", csrf);

	    xml.send(payload);
	    
	}
    }


}