Skip to content
This repository was archived by the owner on Nov 15, 2017. It is now read-only.

Commit 62202fd

Browse files
committed
this fixes #352
1 parent 49f1a7b commit 62202fd

File tree

1 file changed

+125
-120
lines changed

1 file changed

+125
-120
lines changed

js/traffic.js

Lines changed: 125 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
Home: https://github.com/gorhill/httpswitchboard
2020
*/
2121

22-
/*jshint multistr: true */
2322
/* global chrome, HTTPSB */
2423

2524
/******************************************************************************/
@@ -33,119 +32,124 @@ HTTPSB.webRequest = (function() {
3332
// The `id='httpsb'` is important, it allows HTTPSB to detect whether a
3433
// specific data URI originates from itself.
3534

36-
var rootFrameReplacement = "<!DOCTYPE html><html id='httpsb'> \
37-
<head> \
38-
<style> \
39-
@font-face { \
40-
font-family: 'httpsb'; \
41-
font-style: normal; \
42-
font-weight: 400; \
43-
src: local('httpsb'), url('{{fontUrl}}') format('truetype'); \
44-
} \
45-
body { \
46-
margin: 0; \
47-
border: 0; \
48-
padding: 0; \
49-
font: 15px httpsb,sans-serif; \
50-
width: 100%; \
51-
height: 100%; \
52-
background-color:transparent;\
53-
background-size:10px 10px;\
54-
background-image:\
55-
repeating-linear-gradient(\
56-
-45deg,\
57-
rgba(204,0,0,0.5),rgba(204,0,0,0.5) 24%,\
58-
transparent 26%,transparent 49%,\
59-
rgba(204,0,0,0.5) 51%,rgba(204,0,0,0.5) 74%,\
60-
transparent 76%,transparent\
61-
);\
62-
text-align: center; \
63-
} \
64-
#p { \
65-
margin: 8px; \
66-
padding: 4px; \
67-
display: inline-block; \
68-
background-color: white; \
69-
} \
70-
#t { \
71-
margin: 2px; \
72-
border: 0; \
73-
padding: 0 2px; \
74-
display: inline-block; \
75-
} \
76-
#t b { \
77-
padding: 0 4px; \
78-
background-color: #eee; \
79-
font-weight: normal; \
80-
} \
81-
</style> \
82-
<link href='{{cssURL}}?url={{originalURL}}&hostname={{hostname}}&t={{now}}' rel='stylesheet' type='text/css'> \
83-
<title>Blocked by HTTPSB</title> \
84-
</head> \
85-
<body> \
86-
<div id='p'> \
87-
<div id='t'><b>{{hostname}}</b> blocked by HTTP Switchboard</div> \
88-
<div> \
89-
hpHosts: <a href='http://hosts-file.net/?s={{hostname}}' target='_blank'>{{hostname}}</a><br> \
90-
WOT: <a href='https://www.mywot.com/en/scorecard/{{hostname}}' target='_blank'>{{hostname}}</a> \
91-
</div> \
92-
</div> \
93-
</body> \
94-
</html>";
95-
96-
var subFrameReplacement = "<!DOCTYPE html>\
97-
<html>\
98-
<head>\
99-
<style>\
100-
@font-face{\
101-
font-family:'httpsb';\
102-
font-style:normal;\
103-
font-weight:400;\
104-
src:local('httpsb'), url('{{fontUrl}}') format('truetype');\
105-
}\
106-
body{\
107-
margin:0;\
108-
border:0;\
109-
padding:0;\
110-
font:13px httpsb,sans-serif;\
111-
}\
112-
#bg{\
113-
border:1px dotted {{subframeColor}};\
114-
position:absolute;\
115-
top:0;\
116-
right:0;\
117-
bottom:0;\
118-
left:0;\
119-
background-color:transparent;\
120-
background-size:10px 10px;\
121-
background-image:\
122-
repeating-linear-gradient(\
123-
-45deg,\
124-
{{subframeColor}},{{subframeColor}} 24%,\
125-
transparent 25%,transparent 49%,\
126-
{{subframeColor}} 50%,{{subframeColor}} 74%,\
127-
transparent 75%,transparent\
128-
);\
129-
opacity:{{subframeOpacity}};\
130-
text-align:center;\
131-
}\
132-
#bg > div{\
133-
display:inline-block;\
134-
background-color:rgba(255,255,255,1);\
135-
}\
136-
#bg > div > div {\
137-
padding:0 2px;\
138-
display:inline-block;\
139-
color:white;\
140-
background-color:{{subframeColor}};\
141-
}\
142-
</style>\
143-
<title>Blocked by HTTPSB</title>\
144-
</head>\
145-
<body title='&ldquo;{{hostname}}&rdquo; frame\nblocked by HTTP Switchboard'>\
146-
<div id='bg'><div><div>{{hostname}}</div></div></div>\
147-
</body>\
148-
</html>";
35+
var rootFrameReplacement = [
36+
'<!DOCTYPE html><html id="httpsb">',
37+
'<head>',
38+
'<style>',
39+
'@font-face {',
40+
'font-family:httpsb;',
41+
'font-style:normal;',
42+
'font-weight:400;',
43+
'src: local("httpsb"),url("{{fontUrl}}") format("truetype");',
44+
'}',
45+
'body {',
46+
'margin:0;',
47+
'border:0;',
48+
'padding:0;',
49+
'font:15px httpsb,sans-serif;',
50+
'width:100%;',
51+
'height:100%;',
52+
'background-color:transparent;',
53+
'background-size:10px 10px;',
54+
'background-image:',
55+
'repeating-linear-gradient(',
56+
'-45deg,',
57+
'rgba(204,0,0,0.5),rgba(204,0,0,0.5) 24%,',
58+
'transparent 26%,transparent 49%,',
59+
'rgba(204,0,0,0.5) 51%,rgba(204,0,0,0.5) 74%,',
60+
'transparent 76%,transparent',
61+
');',
62+
'text-align: center;',
63+
'}',
64+
'#p {',
65+
'margin:8px;',
66+
'padding:4px;',
67+
'display:inline-block;',
68+
'background-color:white;',
69+
'}',
70+
'#t {',
71+
'margin:2px;',
72+
'border:0;',
73+
'padding:0 2px;',
74+
'display:inline-block;',
75+
'}',
76+
'#t b {',
77+
'padding:0 4px;',
78+
'background-color:#eee;',
79+
'font-weight:normal;',
80+
'}',
81+
'</style>',
82+
'<link href="{{cssURL}}?url={{originalURL}}&hostname={{hostname}}&t={{now}}" rel="stylesheet" type="text/css">',
83+
'<title>Blocked by HTTPSB</title>',
84+
'</head>',
85+
'<body>',
86+
'<div id="p">',
87+
'<div id="t"><b>{{hostname}}</b> blocked by HTTP Switchboard</div>',
88+
'<div>',
89+
'hpHosts: <a href="http://hosts-file.net/?s={{hostname}}" target="_blank">{{hostname}}</a><br>',
90+
'WOT: <a href="https://www.mywot.com/en/scorecard/{{hostname}}" target="_blank">{{hostname}}</a>',
91+
'</div>',
92+
'</div>',
93+
'</body>',
94+
'</html>'
95+
].join('');
96+
97+
var subFrameReplacement = [
98+
'<!DOCTYPE html>',
99+
'<html>',
100+
'<head>',
101+
'<style>',
102+
'@font-face{',
103+
'font-family:httpsb;',
104+
'font-style:normal;',
105+
'font-weight:400;',
106+
'src:local("httpsb"),url("{{fontUrl}}") format("truetype");',
107+
'}',
108+
'body{',
109+
'margin:0;',
110+
'border:0;',
111+
'padding:0;',
112+
'font:13px httpsb,sans-serif;',
113+
'}',
114+
'#bg{',
115+
'border:1px dotted {{subframeColor}};',
116+
'position:absolute;',
117+
'top:0;',
118+
'right:0;',
119+
'bottom:0;',
120+
'left:0;',
121+
'background-color:transparent;',
122+
'background-size:10px 10px;',
123+
'background-image:',
124+
'repeating-linear-gradient(',
125+
'-45deg,',
126+
'{{subframeColor}},{{subframeColor}} 24%,',
127+
'transparent 25%,transparent 49%,',
128+
'{{subframeColor}} 50%,{{subframeColor}} 74%,',
129+
'transparent 75%,transparent',
130+
');',
131+
'opacity:{{subframeOpacity}};',
132+
'text-align:center;',
133+
'}',
134+
'#bg > div{',
135+
'display:inline-block;',
136+
'background-color:rgba(255,255,255,1);',
137+
'}',
138+
'#bg > div > a {',
139+
'padding:0 2px;',
140+
'display:inline-block;',
141+
'color:white;',
142+
'background-color:{{subframeColor}};',
143+
'text-decoration:none;',
144+
'}',
145+
'</style>',
146+
'<title>Blocked by HTTPSB</title>',
147+
'</head>',
148+
'<body title="&ldquo;{{hostname}}&rdquo; frame\nblocked by HTTP Switchboard">',
149+
'<div id="bg"><div><a href="{{frameSrc}}" target="_blank">{{hostname}}</a></div></div>',
150+
'</body>',
151+
'</html>'
152+
].join('');
149153

150154
/******************************************************************************/
151155

@@ -236,11 +240,11 @@ var onBeforeRootFrameRequestHandler = function(details) {
236240
// allows to later check whether the root frame has been unblocked by the
237241
// user, in which case we are able to force a reload using a redirect.
238242
var html = rootFrameReplacement;
239-
html = html.replace(/{{fontUrl}}/g, httpsb.fontCSSURL);
240-
html = html.replace(/{{cssURL}}/g, httpsb.noopCSSURL);
243+
html = html.replace('{{fontUrl}}', httpsb.fontCSSURL);
244+
html = html.replace('{{cssURL}}', httpsb.noopCSSURL);
241245
html = html.replace(/{{hostname}}/g, encodeURIComponent(requestHostname));
242-
html = html.replace(/{{originalURL}}/g, encodeURIComponent(requestURL));
243-
html = html.replace(/{{now}}/g, String(Date.now()));
246+
html = html.replace('{{originalURL}}', encodeURIComponent(requestURL));
247+
html = html.replace('{{now}}', String(Date.now()));
244248
var dataURI = 'data:text/html;base64,' + btoa(html);
245249

246250
// quickProfiler.stop();
@@ -323,10 +327,11 @@ var processRequest = function(httpsb, details) {
323327
// user, in which case we are able to force a reload using a redirect.
324328
if ( requestType === 'sub_frame' ) {
325329
var html = subFrameReplacement
326-
.replace(/{{fontUrl}}/g, httpsb.fontCSSURL)
330+
.replace('{{fontUrl}}', httpsb.fontCSSURL)
327331
.replace(/{{hostname}}/g, requestHostname)
332+
.replace('{{frameSrc}}', requestURL)
328333
.replace(/{{subframeColor}}/g, httpsb.userSettings.subframeColor)
329-
.replace(/{{subframeOpacity}}/g, (httpsb.userSettings.subframeOpacity / 100).toFixed(1));
334+
.replace('{{subframeOpacity}}', (httpsb.userSettings.subframeOpacity / 100).toFixed(1));
330335
return { 'redirectUrl': 'data:text/html,' + encodeURIComponent(html) };
331336
}
332337

0 commit comments

Comments
 (0)