aboutsummaryrefslogtreecommitdiff
path: root/src/main/assets/embed.js
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 /src/main/assets/embed.js
parent6ff3ceb4268a9285bfc6cc987b01132bfd85de83 (diff)
Scripts indentation and cleanup
Diffstat (limited to 'src/main/assets/embed.js')
-rw-r--r--src/main/assets/embed.js60
1 files changed, 30 insertions, 30 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;