-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetch-source.js
More file actions
87 lines (72 loc) · 2.35 KB
/
fetch-source.js
File metadata and controls
87 lines (72 loc) · 2.35 KB
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
const CC = Components.classes;
const CI = Components.interfaces;
VERB=1;
DBUG=2;
INFO=3;
NOTE=4;
WARN=5;
https_everywhere = CC["@eff.org/https-everywhere;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
o_httpsprefs = https_everywhere.get_prefs();
const id_prefix = "he_enable";
const pref_prefix = "extensions.https_everywhere.";
const baseSite = "https://gitweb.torproject.org/https-everywhere.git/blob_plain/";
const directory = "/src/chrome/content/rules/";
const headString = "HEAD";
window.onresize = function() {
var textBox = document.getElementById("source-text");
textBox.width = window.innerWidth - 50;
textBox.height = window.innerHeight - 100;
}
function sourceViewInit() {
if("arguments" in window && window.arguments.length > 0) {
var filename = window.arguments[0].xmlName;
var id = window.arguments[0].GITCommitID; //GIT commit ID
var URL = getURL(filename, id);
var source = getSource(URL, filename, false);
} else {
alert("Invalid window arguments."); //This should never happen
}
}
function getURL(filename, GITCommitID) {
return baseSite + GITCommitID + ":" + directory + filename;
}
function getSource(URL, filename, useHEAD) {
setFilenameText(filename);
setPathText(URL);
var req = CC["@mozilla.org/xmlextras/xmlhttprequest;1"]
.createInstance(CI.nsIXMLHttpRequest);
req.open("GET", URL);
//Clear User-Agent
req.setRequestHeader("User-Agent", "");
req.onreadystatechange = function(params) {
if (req.readyState == 4) {
if (req.status == 200) {
setSourceText(req.responseText);
} else if (!useHEAD) {
//Since we pull the git commit id from .git/refs/HEAD, this project's id might be newer
//than the latest commit in the remote git repository. Therefore, use the HEAD version.
var URL = getURL(filename, headString);
getSource(URL, filename, true);
} else {
downloadFailed();
}
}
}
req.send();
}
function downloadFailed() {
document.getElementById("source-text").hidden = true;
document.getElementById("failure-label").hidden = false;
}
function setSourceText(text) {
var textBox = document.getElementById("source-text");
textBox.value = text;
}
function setFilenameText(text) {
var textLabel = document.getElementById("filename-text");
textLabel.value = text;
}
function setPathText(text) {
var textLabel = document.getElementById("path-text");
textLabel.value = text;
}