-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
130 lines (120 loc) · 3.79 KB
/
scripts.js
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
function add(element) {
var parent = element.parentNode
var cloned = $(parent.querySelector('.input-group')).clone()[0]
cloned.style.removeProperty('display');
var input = cloned.querySelector('input');
input.removeAttribute('disabled');
element.before(cloned);
var settings = {};
if (['quotes', 'texts', 'tags'].includes(input.name)) {
settings.delimiters = /[, ]/
}
if (input.name == 'tags') {
settings.maxTags = 1 // no options allowed
}
new Tagify(input, settings);
}
function del(element) {
var inputGroup = element.parentNode.parentNode
inputGroup.remove()
}
function copy(element) {
var inputGroup = element.parentNode.parentNode;
var input = inputGroup.querySelector('input');
input.select();
input.setSelectionRange(0, 99999);
document.execCommand("copy");
}
function addOneEach() {
$('#addAny').click();
$('#addQuote').click();
$('#addText').click();
$('#addTags').click();
}
function generate() {
var form = document.getElementById('input');
var query = [];
// each URI is an OR
var uris = eval(form.uris.value);
if (uris) {
for (uri of uris) {
parameter = 'uri'
if (uri.value.includes('*') || uri.value.includes('_')) {
parameter = 'wildcard_uri';
}
query.push(parameter + '=' + uri.value);
}
}
// each URI is an OR
var users = eval(form.users.value);
if (users) {
for (user of users) {
query.push('user=' + user.value);
}
}
// each group is an OR
var groups = eval(form.groups.value);
if (groups) {
for (group of groups) {
query.push('group=' + group.value);
}
}
// within an anys field, each any is an OR
// but each anys is an AND
var anys = form.querySelectorAll('input[name=anys]')
for (any of anys) {
any = eval(any.value);
if (any) {
any = any.map(item => '"' + encodeURI(item.value) + '"');
query.push('any=' + any.join('|'))
}
}
// within a quotes field, each quote is an OR
// but each quotes is an AND
var quotes = form.querySelectorAll('input[name=quotes]')
for (quote of quotes) {
quote = eval(quote.value);
if (quote) {
quote = quote.map(item => item.value);
query.push('quote=' + quote.join('|'))
}
}
// within a texts field, each text is an OR
// but each texts is an AND
var texts = form.querySelectorAll('input[name=texts]')
for (text of texts) {
text = eval(text.value);
if (text) {
text = text.map(item => item.value);
query.push('text=' + text.join('|'))
}
}
// within a tags field, each tag is an OR
// but each tags is an AND
var tags = form.querySelectorAll('input[name=tags]')
for (tag of tags) {
tag = eval(tag.value);
if (tag) {
tag = tag.map(item => item.value);
query.push('tag=' + tag.join('|'))
}
}
query = query.join('&');
var output = document.getElementById('output')
output.rss.value = 'https://hypothes.is/stream.rss?' + query
output.atom.value = 'https://hypothes.is/stream.atom?' + query
}
function getFeed(url) {
// https://github.com/hongkiat/js-rss-reader/
fetch(url).then((res) => {
res.text().then((xmlTxt) => {
var domParser = new DOMParser()
let doc = domParser.parseFromString(xmlTxt, 'text/xml')
doc.querySelectorAll('item').forEach((item) => {
let h1 = document.createElement('h1')
h1.textContent = item.querySelector('title').textContent
document.getElementById('feed').appendChild(h1)
})
})
})
}