-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
136 lines (126 loc) · 3.01 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test cleaning links with CleanLinks defaults rules</title>
<link rel="icon" href="favicon.png" />
<!-- Mock browser object so cleanLink can be loaded -->
<script>
var browser =
{
runtime:
{
getURL: url => ('../addon/' + url.replace(/^\/+/, '')),
},
i18n:
{
getMessage: () => null
},
storage: {}
}
</script>
<script src="../tests/setup.js"></script>
<!-- Embed the actual clean_link script -->
<script src="../addon/modules/common.js"></script>
<script src="../addon/modules/punycode.js"></script>
<script src="../addon/modules/publicsuffixlist.js"></script>
<script src="../addon/modules/rules.js"></script>
<script src="../addon/modules/cleanlink.js"></script>
<script src="../addon/modules/display_cleaned_link.js"></script>
<!-- Inner workings of this page -->
<script>
function test_cleaning()
{
let link = document.querySelector('#paste_link input').value;
if (link)
Rules.loaded.then(() =>
{
const url = new URL(link);
const clean = (clean_link(url).cleaned_link || url).href;
const li = cleaned_link_item(document.createElement('li'), link, clean, []);
document.querySelector('ul#clean_history').prepend(li);
document.querySelector('#paste_link input').value = '';
})
.catch(console.error)
}
window.addEventListener('load', () =>
{
document.querySelector('#paste_link button').addEventListener('click', test_cleaning);
document.querySelector('#paste_link input').addEventListener('keyup', e =>
{
if (e.key === 'Enter')
{
e.stopPropagation();
e.preventDefault();
test_cleaning();
}
});
fetch(browser.runtime.getURL('manifest.json')).then(async json =>
{
const manifest = JSON.parse(await json.text());
const h1 = document.getElementsByTagName('h1')[0];
h1.textContent = h1.textContent + ' v' + manifest.version;
});
document.querySelector('#paste_link input').focus();
});
</script>
<!-- Styling for the page -->
<style>
h1{
text-align: center;
}
p#paste_link {
width: 100%;
display: inline-flex;
align-items: baseline;
}
p#paste_link input {
width: 5em;
margin: 0 1em;
flex-grow: 1;
}
ul#clean_history {
list-style: none;
padding: 0;
overflow-wrap: break-word;
word-break: break-all;
}
ul#clean_history li {
margin: 10px 0;
padding: 0 10px;
border: black thin solid;
border-radius: 10px;
}
ul#clean_history li > span {
display: block;
padding: 5px 0;
}
ul#clean_history li span.cleaned::before {
content: '→';
position: relative;
left: -5px;
padding-bottom: 10px;
}
.del {
text-decoration: line-through;
color: red;
}
.ins {
text-decoration: underline;
color: green;
}
.keep {
background-color: rgba(230, 230, 230, 0.5);
}
.url {
text-decoration: underline overline;
color: #339;
}
</style>
</head>
<body>
<h1>Test cleaning with default rules of CleanLinks</h1>
<p id="paste_link">Link: <input type="text" /> <button>Clean it!</button></p>
<ul id="clean_history"></ul>
</body>
</html>