Skip to content

Commit 02a757c

Browse files
SEO enhance
1 parent 37afe13 commit 02a757c

File tree

4 files changed

+305
-134
lines changed

4 files changed

+305
-134
lines changed

service/httpd/onion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (h *Httpd) startOnionService(server *http.Server) error {
6565
LocalListener: listener,
6666
RemotePorts: h.opts.OnionRemotePorts(),
6767
Version3: true,
68-
NoWait: true,
68+
NoWait: verbose,
6969
Key: pvk,
7070
})
7171
if err != nil {

service/httpd/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (web *web) handle() http.Handler {
9494

9595
web.router.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
9696
w.Header().Set("Content-Type", "text/plain")
97-
w.Write(helper.String2Byte("User-agent: *\nDisallow: /")) // nolint:errcheck
97+
w.Write(helper.String2Byte("User-agent: *\nDisallow:")) // nolint:errcheck
9898
})
9999

100100
return web.router

template/assets/js/index.js

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
1+
let policy;
2+
if (typeof window.trustedTypes !== "undefined") {
3+
try {
4+
policy = window.trustedTypes.createPolicy('tt-policy', {
5+
createScriptURL: (url) => url
6+
});
7+
} catch (e) {
8+
console.warn('Failed to create Trusted Types policy: ', e);
9+
policy = null;
10+
}
11+
} else {
12+
policy = {
13+
createScriptURL: (url) => url
14+
};
15+
}
16+
117
if ("serviceWorker" in navigator) {
2-
navigator.serviceWorker.register('/service-worker.js');
18+
const scriptURL = policy.createScriptURL('/service-worker.js');
19+
20+
try {
21+
navigator.serviceWorker.register(scriptURL).catch(error => {
22+
console.error('Service Worker registration failed: ', error);
23+
if (error.name === 'SecurityError') {
24+
console.warn('Service Worker registration failed due to security restrictions');
25+
}
26+
});
27+
} catch (error) {
28+
console.error('Failed to register Service Worker: ', error);
29+
}
330
}
431

532
window.addEventListener('beforeinstallprompt', (e) => {
@@ -27,45 +54,75 @@ window.addEventListener('beforeinstallprompt', (e) => {
2754
}
2855
});
2956

30-
var unblock = function (collects) {
57+
const unblock = () => {
3158
document.querySelector('div.form').style.backgroundColor = '';
3259
document.querySelector('#wayback').disabled = false;
3360
document.querySelector('#playback').disabled = false;
3461
document.getElementById('text').disabled = false;
3562
document.getElementById('text').value = '';
3663
};
3764

38-
var render = function (collects) {
65+
const render = (collects) => {
3966
"use strict";
40-
if (typeof collects !== "object") {
67+
if (!collects || typeof collects !== 'object') {
4168
return;
4269
}
43-
var archived = document.getElementById('archived');
44-
var html = '';
45-
collects.forEach(function (collect, i) {
46-
html += '<ul class="row">';
47-
html += '<li class="src" title="' + collect.src + '">' + collect.src + '</li>';
48-
html += ' <li class="dst" title="' + collect.dst + '">';
70+
const archived = document.getElementById('archived');
71+
const fragment = document.createDocumentFragment();
72+
73+
// Generate a light gray color with slight variation
74+
const r = Math.floor(240 + Math.random() * 16); // 240-255
75+
const g = Math.floor(240 + Math.random() * 16); // 240-255
76+
const b = Math.floor(240 + Math.random() * 16); // 240-255
77+
const renderColor = `rgb(${r},${g},${b})`;
78+
79+
collects.forEach((collect) => {
80+
const row = document.createElement('ul');
81+
row.className = 'row';
82+
row.style.backgroundColor = renderColor;
83+
row.style.color = '#333';
84+
85+
const src = document.createElement('li');
86+
src.className = 'src';
87+
src.title = collect.src;
88+
src.textContent = collect.src;
89+
90+
const dst = document.createElement('li');
91+
dst.className = 'dst';
92+
dst.title = collect.dst;
93+
94+
let link;
4995
try {
50-
new URL(collect.dst);
51-
html += '<a href="' + collect.dst + '" target="blank">' + collect.dst + '</a>';
96+
const url = new URL(collect.dst);
97+
link = document.createElement('a');
98+
link.href = url.href;
99+
link.target = 'blank';
100+
link.textContent = collect.dst;
52101
} catch (_) {
53-
html += '<a href="javascript:;">' + collect.dst + '</a>';
102+
link = document.createElement('a');
103+
link.href = 'javascript:;';
104+
link.textContent = collect.dst;
54105
}
55-
html += '</li>';
56-
html += '</ul>';
57-
})
58-
archived.innerHTML = html + archived.innerHTML;
106+
107+
dst.appendChild(link);
108+
row.appendChild(src);
109+
row.appendChild(dst);
110+
fragment.appendChild(row);
111+
});
112+
archived.insertBefore(fragment, archived.firstChild);
59113
};
60114

61-
var post = function (url) {
115+
const post = (url) => {
62116
"use strict";
63-
var http = new XMLHttpRequest(),
117+
const http = new XMLHttpRequest(),
64118
params = new URLSearchParams(),
65119
text = document.getElementById('text').value;
66120
if (!text || text.length === 0) {
67121
return;
68122
}
123+
http.onload = () => {
124+
http.onreadystatechange = null;
125+
};
69126

70127
document.getElementById('text').disabled = true;
71128
document.querySelector('#wayback').disabled = true;
@@ -74,10 +131,10 @@ var post = function (url) {
74131

75132
http.open("POST", url, true);
76133
http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
77-
http.onreadystatechange = function () {
134+
http.onreadystatechange = () => {
78135
if (http.readyState === 4 && http.status === 200) {
79136
if (http.response !== undefined && http.response) {
80-
var collects = JSON.parse(http.response)
137+
const collects = JSON.parse(http.response)
81138
render(collects);
82139
}
83140
}

0 commit comments

Comments
 (0)