diff options
author | Vitaly Takmazov | 2023-01-14 10:18:26 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-14 10:18:26 +0300 |
commit | 43cc6b7041fad8d99e4c4d4d4076c2a6e865f6d7 (patch) | |
tree | 6b5a80ceea8d6317c8672df007bf5768adaaa445 /vnext/src | |
parent | 116024102e93f2444f4f566bea83b5f3d98ccb25 (diff) |
vnext: cleanup minor warnings
Diffstat (limited to 'vnext/src')
-rw-r--r-- | vnext/src/utils/embed.js | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/vnext/src/utils/embed.js b/vnext/src/utils/embed.js index 7db46866..8fde80d0 100644 --- a/vnext/src/utils/embed.js +++ b/vnext/src/utils/embed.js @@ -126,7 +126,7 @@ function messageReplyReplace(messageId) { * @returns {string} formatted message */ function juickFormat(txt, messageId, isCode) { - const urlRe = /(?:\[([^\]\[]+)\](?:\[([^\]]+)\]|\(((?:[a-z]+:\/\/|www\.|ftp\.)(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[-\S+*&@#/%=~|$?!:;,.])*(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[\S+*&@#/%=~|$]))\))|\b(?:[a-z]+:\/\/|www\.|ftp\.)(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[-\S+*&@#/%=~|$?!:;,.])*(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[\S+*&@#/%=~|$]))/gi; + const urlRe = /(?:\[([^\][]+)\](?:\[([^\]]+)\]|\(((?:[a-z]+:\/\/|www\.|ftp\.)(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[-\S+*&@#/%=~|$?!:;,.])*(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[\S+*&@#/%=~|$]))\))|\b(?:[a-z]+:\/\/|www\.|ftp\.)(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[-\S+*&@#/%=~|$?!:;,.])*(?:\([-\S+*&@#/%=~|$?!:;,.]*\)|[\S+*&@#/%=~|$]))/gi; const bqReplace = m => m.replace(/^(?:>|>)\s?/gmi, ''); return (isCode) ? formatText(txt, [ @@ -139,9 +139,9 @@ function juickFormat(txt, messageId, isCode) { { pr: 1, re: urlRe, with: urlReplace }, { pr: 1, re: /\B(?:#(\d+))?(?:\/(\d+))?\b/g, with: messageReplyReplace(messageId) }, { pr: 1, re: /\B@([\w-]+)\b/gi, with: '<a href="/$1">@$1</a>' }, - { pr: 2, re: /\B\*([^\n]+?)\*((?=\s)|(?=$)|(?=[!\"#$%&'*+,\-./:;<=>?@[\]^_`{|}~()]+))/g, brackets: true, with: ['<b>', '</b>'] }, - { pr: 2, re: /\B\/([^\n]+?)\/((?=\s)|(?=$)|(?=[!\"#$%&'*+,\-./:;<=>?@[\]^_`{|}~()]+))/g, brackets: true, with: ['<i>', '</i>'] }, - { pr: 2, re: /\b\_([^\n]+?)\_((?=\s)|(?=$)|(?=[!\"#$%&'*+,\-./:;<=>?@[\]^_`{|}~()]+))/g, brackets: true, with: ['<u>', '</u>'] }, + { pr: 2, re: /\B\*([^\n]+?)\*((?=\s)|(?=$)|(?=[!"#$%&'*+,\-./:;<=>?@[\]^_`{|}~()]+))/g, brackets: true, with: ['<b>', '</b>'] }, + { pr: 2, re: /\B\/([^\n]+?)\/((?=\s)|(?=$)|(?=[!"#$%&'*+,\-./:;<=>?@[\]^_`{|}~()]+))/g, brackets: true, with: ['<i>', '</i>'] }, + { pr: 2, re: /\b_([^\n]+?)_((?=\s)|(?=$)|(?=[!"#$%&'*+,\-./:;<=>?@[\]^_`{|}~()]+))/g, brackets: true, with: ['<u>', '</u>'] }, { pr: 3, re: /\n/g, with: '<br/>' }, ]); } @@ -178,7 +178,7 @@ function getEmbeddableLinkTypes() { name: 'Jpeg and png images', id: 'embed_jpeg_and_png_images', className: 'picture compact', - re: /\.(jpe?g|png|svg)(:[a-zA-Z]+)?(?:\?[\w&;\?=]*)?$/i, + re: /\.(jpe?g|png|svg)(:[a-zA-Z]+)?(?:\?[\w&;?=]*)?$/i, makeNode: function(aNode, reResult, div) { // dirty fix for dropbox urls let url = aNode.href.endsWith('dl=0') ? aNode.href.replace('dl=0', 'raw=1') : aNode.href; @@ -190,7 +190,7 @@ function getEmbeddableLinkTypes() { name: 'Gif images', id: 'embed_gif_images', className: 'picture compact', - re: /\.gif(:[a-zA-Z]+)?(?:\?[\w&;\?=]*)?$/i, + re: /\.gif(:[a-zA-Z]+)?(?:\?[\w&;?=]*)?$/i, makeNode: function(aNode, reResult, div) { div.innerHTML = `<a href="${aNode.href}"><img src="${aNode.href}"></a>`; return div; @@ -200,7 +200,7 @@ function getEmbeddableLinkTypes() { name: 'Video (webm, mp4, ogv)', id: 'embed_webm_and_mp4_videos', className: 'video compact', - re: /\.(webm|mp4|m4v|ogv)(?:\?[\w&;\?=]*)?$/i, + re: /\.(webm|mp4|m4v|ogv)(?:\?[\w&;?=]*)?$/i, makeNode: function(aNode, reResult, div) { div.innerHTML = `<video src="${aNode.href}" title="${aNode.href}" controls></video>`; return div; @@ -210,7 +210,7 @@ function getEmbeddableLinkTypes() { name: 'Audio (mp3, ogg, weba, opus, m4a, oga, wav)', id: 'embed_sound_files', className: 'audio singleColumn', - re: /\.(mp3|ogg|weba|opus|m4a|oga|wav)(?:\?[\w&;\?=]*)?$/i, + re: /\.(mp3|ogg|weba|opus|m4a|oga|wav)(?:\?[\w&;?=]*)?$/i, makeNode: function(aNode, reResult, div) { div.innerHTML = `<audio src="${aNode.href}" title="${aNode.href}" controls></audio>`; return div; @@ -220,9 +220,9 @@ function getEmbeddableLinkTypes() { name: 'YouTube videos (and playlists)', id: 'embed_youtube_videos', className: 'youtube resizableV singleColumn', - re: /^(?:https?:)?\/\/(?:www\.|m\.|gaming\.)?(?:youtu(?:(?:\.be\/|be\.com\/(?:v|embed)\/)([-\w]+)|be\.com\/watch)((?:(?:\?|&(?:amp;)?)(?:\w+=[-\.\w]*[-\w]))*)|youtube\.com\/playlist\?list=([-\w]*)(&(amp;)?[-\w\?=]*)?)/i, + re: /^(?:https?:)?\/\/(?:www\.|m\.|gaming\.)?(?:youtu(?:(?:\.be\/|be\.com\/(?:v|embed)\/)([-\w]+)|be\.com\/watch)((?:(?:\?|&(?:amp;)?)(?:\w+=[-.\w]*[-\w]))*)|youtube\.com\/playlist\?list=([-\w]*)(&(amp;)?[-\w?=]*)?)/i, makeNode: function(aNode, reResult, div) { - let [url, v, args, plist] = reResult; + let [, v, args, plist] = reResult; let iframeUrl; if (plist) { iframeUrl = '//www.youtube-nocookie.com/embed/videoseries?list=' + plist; @@ -276,7 +276,7 @@ function getEmbeddableLinkTypes() { .then(response => response.json()) .then(json => { div.innerHTML = json.html; - }); + }).catch(console.log); return div; } }, @@ -286,7 +286,7 @@ function getEmbeddableLinkTypes() { className: 'picture compact', re: /https?:\/\/www\.?instagram\.com(\/p\/\w+)\/?/i, makeNode: function(aNode, reResult, div) { - let [url, postId] = reResult; + let [, postId] = reResult; let mediaUrl = `https://instagr.am${postId}/media`; div.innerHTML = `<a href="${aNode.href}"><img src="${mediaUrl}"></a>`; return div; @@ -298,7 +298,7 @@ function getEmbeddableLinkTypes() { className: 'tg compact', re: /https?:\/\/t\.me\/(\S+)/i, makeNode: function(aNode, reResult, div) { - let [url, post] = reResult; + let [, post] = reResult; // innerHTML cannot insert scripts, so... let script = document.createElement('script'); script.src = 'https://telegram.org/js/telegram-widget.js?18'; @@ -324,7 +324,7 @@ function getEmbeddableLinkTypes() { */ function embedLink(aNode, linkTypes, container, afterNode = false) { 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) { anyEmbed = linkTypes.some((linkType) => { @@ -368,7 +368,6 @@ function embedLinks(aNodes, container) { * @param {string} allLinksSelector */ export function embedLinksToX(x, beforeNodeSelector, allLinksSelector) { - let isCtsPost = false; let allLinks = x.querySelectorAll(allLinksSelector); let existingContainer = x.querySelector('div.embedContainer'); |