aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2020-02-02 12:40:22 +0300
committerGravatar Vitaly Takmazov2020-02-02 12:40:22 +0300
commit496cb3eb32cc20dbb8e77f81067162db61e20312 (patch)
tree414b38643b2f9543f7265dbd702772502b07c063
parent6ff3ceb4268a9285bfc6cc987b01132bfd85de83 (diff)
Scripts indentation and cleanup
-rw-r--r--src/main/assets/embed.js60
-rw-r--r--src/main/assets/scripts.js52
2 files changed, 53 insertions, 59 deletions
diff --git a/src/main/assets/embed.js b/src/main/assets/embed.js
index 4c7828a3..6cb02110 100644
--- a/src/main/assets/embed.js
+++ b/src/main/assets/embed.js
@@ -10,7 +10,7 @@ function setContent(containerNode, ...newNodes) {
}
function removeAllFrom(fromNode) {
- for (let c; c = fromNode.lastChild; ) { fromNode.removeChild(c); }
+ for (let c; c = fromNode.lastChild;) { fromNode.removeChild(c); }
}
function htmlEscape(html) {
@@ -28,15 +28,15 @@ function formatText(txt, rules) {
function nextId() { return idCounter++; }
function ft(txt, rules) {
let matches = rules.map(r => { r.re.lastIndex = 0; return [r, r.re.exec(txt)]; })
- .filter(([,m]) => m !== null)
- .sort(([r1,m1],[r2,m2]) => (r1.pr - r2.pr) || (m1.index - m2.index));
+ .filter(([, m]) => m !== null)
+ .sort(([r1, m1], [r2, m2]) => (r1.pr - r2.pr) || (m1.index - m2.index));
if (matches && matches.length > 0) {
let [rule, match] = matches[0];
let subsequentRules = rules.filter(r => r.pr >= rule.pr);
let idStr = `<>(${nextId()})<>`;
let outerStr = txt.substring(0, match.index) + idStr + txt.substring(rule.re.lastIndex);
let innerStr = (rule.brackets)
- ? (() => { let [l ,r ,f] = rule.with; return l + ft((f ? f(match[1]) : match[1]), subsequentRules) + r; })()
+ ? (() => { let [l, r, f] = rule.with; return l + ft((f ? f(match[1]) : match[1]), subsequentRules) + r; })()
: match[0].replace(rule.re, rule.with);
return ft(outerStr, subsequentRules).replace(idStr, innerStr);
}
@@ -59,7 +59,7 @@ function makeNewNode(embedType, aNode, reResult) {
return embedType.makeNode(aNode, reResult, withClasses(document.createElement('div')));
}
-function makeIframe(src, w, h, scrolling='no') {
+function makeIframe(src, w, h, scrolling = 'no') {
let iframe = document.createElement('iframe');
iframe.style.width = w;
iframe.style.height = h;
@@ -202,9 +202,9 @@ function getEmbeddableLinkTypes() {
iframeUrl = '//www.youtube-nocookie.com/embed/videoseries?list=' + plist;
} else {
let pp = {}; args.replace(/^\?/, '')
- .split('&')
- .map(s => s.split('='))
- .forEach(z => pp[z[0]] = z[1]);
+ .split('&')
+ .map(s => s.split('='))
+ .forEach(z => pp[z[0]] = z[1]);
let embedArgs = {
rel: '0',
enablejsapi: '1',
@@ -213,15 +213,15 @@ function getEmbeddableLinkTypes() {
if (pp.t) {
const tre = /^(?:(\d+)|(?:(\d+)h)?(?:(\d+)m)?(\d+)s|(?:(\d+)h)?(\d+)m|(\d+)h)$/i;
let [, t, h, m, s, h1, m1, h2] = tre.exec(pp.t);
- embedArgs['start'] = (+t) || ((+(h || h1 || h2 || 0))*60*60 + (+(m || m1 || 0))*60 + (+(s || 0)));
+ embedArgs['start'] = (+t) || ((+(h || h1 || h2 || 0)) * 60 * 60 + (+(m || m1 || 0)) * 60 + (+(s || 0)));
}
if (pp.list) {
embedArgs['list'] = pp.list;
}
v = v || pp.v;
let argsStr = Object.keys(embedArgs)
- .map(k => `${k}=${embedArgs[k]}`)
- .join('&');
+ .map(k => `${k}=${embedArgs[k]}`)
+ .join('&');
iframeUrl = `//www.youtube-nocookie.com/embed/${v}?${argsStr}`;
}
let iframe = makeIframe(iframeUrl, '100%', '360px');
@@ -249,7 +249,7 @@ function getEmbeddableLinkTypes() {
re: /^(?:https?:)?\/\/(?:www\.)?(?:mobile\.)?twitter\.com\/([\w-]+)\/status(?:es)?\/([\d]+)/i,
makeNode: function(aNode, reResult, div) {
let [url, userId, postId] = reResult;
- url = url.replace('mobile.','');
+ url = url.replace('mobile.', '');
div.innerHTML = `<blockquote class="twitter-tweet" data-lang="en"><a href="${url}"></a></blockquote>`;
@@ -272,24 +272,24 @@ function getEmbeddableLinkTypes() {
function embedLink(aNode, linkTypes, container, afterNode) {
let anyEmbed = false;
- let linkId = (aNode.href.replace(/^https?:/i, '').replace(/\'/gi,''));
+ let linkId = (aNode.href.replace(/^https?:/i, '').replace(/\'/gi, ''));
let sameEmbed = container.querySelector(`*[data-linkid='${linkId}']`); // do not embed the same thing twice
if (sameEmbed === null) {
anyEmbed = [].some.call(linkTypes, function(linkType) {
- let reResult = linkType.re.exec(aNode.href);
- if (reResult) {
- if (linkType.match && (linkType.match(aNode, reResult) === false)) { return false; }
- let newNode = makeNewNode(linkType, aNode, reResult);
- if (!newNode) { return false; }
- newNode.setAttribute('data-linkid', linkId);
- if (afterNode) {
- insertAfter(newNode, afterNode);
- } else {
- container.appendChild(newNode);
- }
- aNode.classList.add('embedLink');
- return true;
+ let reResult = linkType.re.exec(aNode.href);
+ if (reResult) {
+ if (linkType.match && (linkType.match(aNode, reResult) === false)) { return false; }
+ let newNode = makeNewNode(linkType, aNode, reResult);
+ if (!newNode) { return false; }
+ newNode.setAttribute('data-linkid', linkId);
+ if (afterNode) {
+ insertAfter(newNode, afterNode);
+ } else {
+ container.appendChild(newNode);
}
+ aNode.classList.add('embedLink');
+ return true;
+ }
});
}
return anyEmbed;
@@ -339,10 +339,10 @@ export function embedLinksToX(x, beforeNodeSelector, allLinksSelector) {
*/
export function embedAll() {
let beforeNodeSelector = '.msg-txt + *';
- let allLinksSelector = '.msg-txt a';
- Array.from(document.querySelectorAll('#content .msg-cont')).forEach(msg => {
- embedLinksToX(msg, beforeNodeSelector, allLinksSelector);
- });
+ let allLinksSelector = '.msg-txt a';
+ Array.from(document.querySelectorAll('#content .msg-cont')).forEach(msg => {
+ embedLinksToX(msg, beforeNodeSelector, allLinksSelector);
+ });
}
export const format = juickFormat;
diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js
index 677efeac..2c56fe7f 100644
--- a/src/main/assets/scripts.js
+++ b/src/main/assets/scripts.js
@@ -14,12 +14,6 @@ if (!('remove' in Element.prototype)) { // Firefox <23
};
}
-NodeList.prototype.forEach = Array.prototype.forEach;
-HTMLCollection.prototype.forEach = Array.prototype.forEach;
-
-NodeList.prototype.filter = Array.prototype.filter;
-HTMLCollection.prototype.filter = Array.prototype.filter;
-
Element.prototype.selectText = function() {
let d = document;
if (d.body.createTextRange) {
@@ -227,7 +221,7 @@ function nextReply() {
}
function updateRepliesCounter() {
- var replies = document.querySelectorAll('#replies>li.reply-new').length;
+ var replies = Array.from(document.querySelectorAll('#replies>li.reply-new')).length;
var wsthread = document.getElementById('wsthread');
if (replies) {
wsthread.textContent = replies;
@@ -259,7 +253,7 @@ function closeDialogListener(ev) {
}
function newMessage(evt) {
- document.querySelectorAll('#newmessage .dialogtxt').forEach(t => {
+ Array.from(document.querySelectorAll('#newmessage .dialogtxt')).forEach(t => {
t.remove();
});
if (document.querySelector('#newmessage textarea').value.length == 0
@@ -642,7 +636,7 @@ function ready(fn) {
}
ready(function() {
- document.querySelectorAll('textarea').forEach((ta) => {
+ Array.from(document.querySelectorAll('textarea')).forEach((ta) => {
autosize(ta);
});
svg4everybody();
@@ -653,13 +647,13 @@ ready(function() {
e.target.removeEventListener('click', insertPMButtons);
e.preventDefault();
};
- document.querySelectorAll('textarea.replypm').forEach(function(e) {
+ Array.from(document.querySelectorAll('textarea.replypm')).forEach(function(e) {
e.addEventListener('click', insertPMButtons);
e.addEventListener('keypress', function(e) {
postformListener(e.target, e);
});
});
- document.querySelectorAll('#postmsg textarea').forEach(function(e) {
+ Array.from(document.querySelectorAll('#postmsg textarea')).forEach(function(e) {
e.addEventListener('keypress', function(e) {
postformListener(e.target, e);
});
@@ -669,7 +663,7 @@ ready(function() {
if (content) {
var pageMID = content.getAttribute('data-mid');
if (pageMID > 0) {
- document.querySelectorAll('li.msg').forEach(li => {
+ Array.from(document.querySelectorAll('li.msg')).forEach(li => {
let showReplyFormBtn = li.querySelector('.a-thread-comment');
if (showReplyFormBtn) {
showReplyFormBtn.addEventListener('click', function(e) {
@@ -694,7 +688,7 @@ ready(function() {
var postmsg = document.getElementById('postmsg');
if (postmsg) {
- document.querySelectorAll('a').filter(t => t.href.indexOf('?') >= 0).forEach(t => {
+ Array.from(document.querySelectorAll('a')).filter(t => t.href.indexOf('?') >= 0).forEach(t => {
t.addEventListener('click', e => {
let params = new URLSearchParams(t.href.slice(t.href.indexOf('?') + 1));
if (params.has('tag')) {
@@ -728,7 +722,7 @@ ready(function() {
e.preventDefault();
});
}
- document.querySelectorAll('.pmmsg').forEach(pmmsg => {
+ Array.from(document.querySelectorAll('.pmmsg')).forEach(pmmsg => {
pmmsg.addEventListener('submit', e => {
let formData = new FormData(pmmsg);
fetch('/api/pm' + '?hash=' + document.getElementById('body').getAttribute('data-hash'), {
@@ -755,7 +749,7 @@ ready(function() {
});
});
- document.querySelectorAll('.msg-menu').forEach(function(el) {
+ Array.from(document.querySelectorAll('.msg-menu')).forEach(function(el) {
el.addEventListener('click', function(e) {
var reply = e.target.closest('li');
var rid = reply ? parseInt(reply.id) : 0;
@@ -765,7 +759,7 @@ ready(function() {
e.preventDefault();
});
});
- document.querySelectorAll('.l .a-privacy').forEach(function(e) {
+ Array.from(document.querySelectorAll('.l .a-privacy')).forEach(function(e) {
e.addEventListener('click', function(e) {
setPrivacy(
e.target,
@@ -773,7 +767,7 @@ ready(function() {
e.preventDefault();
});
});
- document.querySelectorAll('.ir a[data-fname], .msg-media a[data-fname]').forEach(function(el) {
+ Array.from(document.querySelectorAll('.ir a[data-fname], .msg-media a[data-fname]')).forEach(function(el) {
el.addEventListener('click', function(e) {
let fname = e.target.closest('[data-fname]').getAttribute('data-fname');
if (!showPhotoDialog(fname)) {
@@ -781,7 +775,7 @@ ready(function() {
}
});
});
- document.querySelectorAll('.social a').forEach(function(e) {
+ Array.from(document.querySelectorAll('.social a')).forEach(function(e) {
e.addEventListener('click', function(e) {
openSocialWindow(e.target);
e.preventDefault();
@@ -794,7 +788,7 @@ ready(function() {
});
}
- document.querySelectorAll('.l .a-like').forEach(function(e) {
+ Array.from(document.querySelectorAll('.l .a-like')).forEach(function(e) {
e.addEventListener('click', function(e) {
likeMessage(
e.target,
@@ -802,7 +796,7 @@ ready(function() {
e.preventDefault();
});
});
- document.querySelectorAll('.l .a-sub').forEach(function(e) {
+ Array.from(document.querySelectorAll('.l .a-sub')).forEach(function(e) {
e.addEventListener('click', function(e) {
subscribeMessage(
e.target,
@@ -810,7 +804,7 @@ ready(function() {
e.preventDefault();
});
});
- document.querySelectorAll('.a-login').forEach(function(el) {
+ Array.from(document.querySelectorAll('.a-login')).forEach(function(el) {
el.addEventListener('click', function(e) {
openDialogLogin();
e.preventDefault();
@@ -819,18 +813,18 @@ ready(function() {
var unfoldall = document.getElementById('unfoldall');
if (unfoldall) {
unfoldall.addEventListener('click', function(e) {
- document.querySelectorAll('#replies>li').forEach(function(e) {
+ Array.from(document.querySelectorAll('#replies>li')).forEach(function(e) {
e.style.display = 'block';
});
- document.querySelectorAll('#replies .msg-comments').forEach(function(e) {
+ Array.from(document.querySelectorAll('#replies .msg-comments')).forEach(function(e) {
e.style.display = 'none';
});
e.preventDefault();
});
}
- document.querySelectorAll('article').forEach(function(article) {
+ Array.from(document.querySelectorAll('article')).forEach(function(article) {
if (Array.prototype.some.call(
- article.querySelectorAll('.msg-tags a'),
+ Array.from(article.querySelectorAll('.msg-tags a')),
function(a) {
return a.textContent === 'NSFW';
}
@@ -838,12 +832,12 @@ ready(function() {
article.classList.add('nsfw');
}
});
- document.querySelectorAll('[data-uri]').forEach(el => {
+ Array.from(document.querySelectorAll('[data-uri]')).forEach(el => {
let dataUri = el.getAttribute('data-uri');
if (dataUri) {
setTimeout(() => fetchUserUri(dataUri, user => {
let header = el.closest('.msg-header');
- header.querySelectorAll('.a-username').forEach(a => {
+ Array.from(header.querySelectorAll('.a-username')).forEach(a => {
a.setAttribute('href', user.uri);
let img = a.querySelector('img');
if (img && user.avatar) {
@@ -859,7 +853,7 @@ ready(function() {
}), 100);
}
});
- document.querySelectorAll('[data-user-uri]').forEach(el => {
+ Array.from(document.querySelectorAll('[data-user-uri]')).forEach(el => {
let dataUri = el.getAttribute('href');
if (dataUri) {
setTimeout(() => fetchUserUri(dataUri, user => {
@@ -872,7 +866,7 @@ ready(function() {
}
});
let location = window.location.href;
- document.querySelectorAll('#header_wrapper a').forEach(el => {
+ Array.from(document.querySelectorAll('#header_wrapper a')).forEach(el => {
if (el.href === location) {
el.classList.add('active');
el.setAttribute('disabled', 'disabled');