-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmute-filter.html
More file actions
265 lines (230 loc) · 7.44 KB
/
Copy pathmute-filter.html
File metadata and controls
265 lines (230 loc) · 7.44 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!doctype HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>mute filter generator</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!--<link rel="stylesheet" href="/assets/reset.css">
<link rel="stylesheet" href="/assets/app.css">-->
<style type="text/css">
/* Din will shoot me for that inline CSS */
* {
margin: 0;
padding: 0;
border: 0;
outline: 0;
box-sizing: border-box;
}
body {
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #222;
}
h1 {
color: #000;
}
.regexView {
padding: 20px;
background: #888;
display: block;
color: #FFF;
font-family: Source Code Pro, monospace, Helvetica, Arial, sans-serif;
}
.linkView {
display: block;
}
.b-muteList {
list-style: none;
width: 550px;
margin: 20px auto 0;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.b-m-item {
margin: 8px;
padding: 10px;
border: 1px solid #eee;
background: #f6f6f6;
cursor: pointer;
text-align: center;
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.b-m-item:hover {
background: #eee;
}
.b-m-item.active {
background: #eee;
border: 1px solid #aaa;
}
</style>
</head>
<body>
<span class="regexView"></span>
<span class="regexLink"></span>
<ul class="b-muteList">
</ul>
<script>
var $ = function(callback){
return function(params) {
if(typeof params !== 'undefined') {
var res = callback.call(document, params);
if(res.length === 0) return {error: true};
if(res.length === 1) return res[0];
return res;
}
}
}(document.querySelectorAll);// oh wow lovely - cassie ainsworth #skinsUK
window.$ = $;
var runApp = function runApp() {
var app = {};
var $list, $regexView, $regexLink;
app.currentRegex = '';
app.currentPos = 0;
app.oldPos = 0;
app.lastClickWasSelect = false;
app.activeWords = [];
app.config = {
jsonFile: './muteFilters.json',
filtersList: '.b-muteList',
item: '.b-m-item',
activeClass: 'active',
regexView: '.regexView',
regexLink: '.regexLink',
tweetBotLink: 'tweetbot:///mute/keyword?regex=1&text='
};
app.events = {
create: function(name, value) {
var event = new CustomEvent(name, {
detail: {
data: value,
time: new Date()
},
bubbles: true,
cancelable: true
});
document.dispatchEvent(event);
return event;
},
listen: function(name, cb) {
document.addEventListener(name, cb, false);
}
};
app.createList = function(d) {
console.log('create list');
var arr = d.detail.data;
console.log($list);
var el;
for(var i = 0; arr.length > i; i++) {
console.log(arr[i], i);
el = document.createElement('li');
el.setAttribute('class', 'b-m-item tp-' + i);
el.setAttribute('data-pos', i); // yup
el.innerHTML = arr[i];
el.addEventListener('click', app.toggleSelect);
$list.appendChild(el);
}
};
app.updateRegex = function() {
app.currentRegex = '(?i)(' + app.activeWords.join('|') + ')';
$regexView.innerText = app.currentRegex;
var uri = app.config.tweetBotLink + encodeURIComponent(app.currentRegex);
$regexLink.innerHTML = '<a href="' + uri + '">' + uri + '</a>';
};
app.addClass = function(el) {
return function(className) {
el.setAttribute('class', el.getAttribute('class') + ' ' + className);
app.activeWords.push(el.innerHTML);
app.updateRegex();
};
};
app.removeClass = function(el) {
return function(className) {
var currentClass = el.getAttribute('class');
el.setAttribute('class', currentClass.replace(className, ''));
app.activeWords.splice(app.activeWords.indexOf(el.innerHTML), 1);
app.updateRegex();
};
};
app.toggleSelect = function(e) {
//var isSelected = e.target.classList.indexOf(app.config.activeClass);
var isSelected = (e.target.className.split(/ /).indexOf('active') !== -1);
var shiftHolded = e.shiftKey;
//var ctrlHolded = e.ctrlKey; // we dont use it since toggeling
var itemPos = e.target.dataset.pos;
app.currentPos = itemPos;
console.log(itemPos, isSelected);
if(!isSelected) {
app.addClass(e.target)('active');
if(shiftHolded && app.lastClickWasSelect) {
console.log('shifted and last action was select', itemPos, app.oldPos);
var start = (itemPos > app.oldPos) ? app.oldPos : itemPos;
var end = (itemPos > app.oldPos) ? itemPos : app.oldPos;
console.log('start, end: ', start, end);
for (var i = start; end > i; i++) {
console.log('hi ',i, start, end);
app.addClass($('.tp-' + i))('active');
}
}
app.lastClickWasSelect = true;
} else {
app.removeClass(e.target)('active');
app.lastClickWasSelect = false;
}
app.oldPos = itemPos;
}
app.initEvents = function() {
app.events.listen('listDataLoaded', app.createList);
};
app.helpers = {
getJSON: function(uri, cb, method) {
if(typeof method === 'undefined') method = 'GET'
if(typeof uri === 'undefined') return alert('ENTER A URL!!!'); // everyone hates alerts <3
request = new XMLHttpRequest(); // FUCK OLD BROWSERS
request.open(method, uri, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400){
var jason = JSON.parse(request.responseText); // who is jason?
if(typeof cb === 'function') cb(JSON.parse(request.responseText));
//return json; // some people would really do this #async
} else {
console.error('getJSON failed: ', request);
}
};
request.onerror = function() {
console.error('request error: ', request);
};
request.send();
return false;
}
};
app.initialize = function initialize() {
// cache elements
$list = $(app.config.filtersList);
$regexView = $(app.config.regexView);
$regexLink = $(app.config.regexLink);
app.initEvents();
app.helpers.getJSON(app.config.jsonFile, function(data) {
app.events.create('listDataLoaded', data.keywords);
});
return app;
}(); // :o
return app.initialize;
};
document.addEventListener("DOMContentLoaded", function(event) {
window.app = runApp();
});
// not the best code, just quickly hacked
</script>
</body>
</html>