diff options
Diffstat (limited to 'juick-www/src/main/js')
-rw-r--r-- | juick-www/src/main/js/killy/index.js | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/juick-www/src/main/js/killy/index.js b/juick-www/src/main/js/killy/index.js index 46798c9f..c2ce20fb 100644 --- a/juick-www/src/main/js/killy/index.js +++ b/juick-www/src/main/js/killy/index.js @@ -1,10 +1,6 @@ -function intersect(a, b) { - if (b.length > a.length) { [a, b] = [b, a]; } // loop over shorter array - return a.filter(item => (b.indexOf(item) !== -1)); -} function insertAfter(newNode, referenceNode) { - referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); + referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); } function moveAll(fromNode, toNode) { @@ -153,7 +149,7 @@ function getEmbeddableLinkTypes() { ]; } -function embedLink(aNode, linkTypes, container, alwaysCts, afterNode) { +function embedLink(aNode, linkTypes, container, afterNode) { let anyEmbed = false; let linkId = (aNode.href.replace(/^https?:/i, '').replace(/\'/i,'')); let sameEmbed = container.querySelector(`*[data-linkid='${linkId}']`); // do not embed the same thing twice @@ -178,34 +174,28 @@ function embedLink(aNode, linkTypes, container, alwaysCts, afterNode) { return anyEmbed; } -function embedLinks(aNodes, container, alwaysCts, afterNode) { +function embedLinks(aNodes, container) { let anyEmbed = false; let embeddableLinkTypes = getEmbeddableLinkTypes(); Array.from(aNodes).forEach(aNode => { - let isEmbedded = embedLink(aNode, embeddableLinkTypes, container, alwaysCts, afterNode); + let isEmbedded = embedLink(aNode, embeddableLinkTypes, container); anyEmbed = anyEmbed || isEmbedded; }); return anyEmbed; } -function articleInfo(article) { - let tagNodes = article.querySelectorAll('.msg-tags > *'); - let tags = Array.from(tagNodes).map(d => d.textContent.toLowerCase()); - return { tags: tags }; -} - -function embedLinksToX(x, beforeNodeSelector, allLinksSelector, ctsUsers, ctsTags) { +function embedLinksToX(x, beforeNodeSelector, allLinksSelector) { let isCtsPost = false; let allLinks = x.querySelectorAll(allLinksSelector); let existingContainer = x.querySelector('div.embedContainer'); if (existingContainer !== null) { - embedLinks(allLinks, existingContainer, isCtsPost); + embedLinks(allLinks, existingContainer); } else { let embedContainer = document.createElement('div'); embedContainer.className = 'embedContainer'; - let anyEmbed = embedLinks(allLinks, embedContainer, isCtsPost); + let anyEmbed = embedLinks(allLinks, embedContainer); if (anyEmbed) { let beforeNode = x.querySelector(beforeNodeSelector); x.insertBefore(embedContainer, beforeNode); @@ -214,20 +204,18 @@ function embedLinksToX(x, beforeNodeSelector, allLinksSelector, ctsUsers, ctsTag } function embedLinksToArticles() { - let ctsUsers = [], ctsTags = []; // TODO click-to-show users and tags let beforeNodeSelector = 'nav.l'; let allLinksSelector = 'p:not(.ir) a, pre a'; Array.from(document.querySelectorAll('#content > article')).forEach(article => { - embedLinksToX(article, beforeNodeSelector, allLinksSelector, ctsUsers, ctsTags); + embedLinksToX(article, beforeNodeSelector, allLinksSelector); }); } function embedLinksToPost() { - let ctsUsers = [], ctsTags = []; // TODO click-to-show users and tags let beforeNodeSelector = '.msg-txt + *'; let allLinksSelector = '.msg-txt a'; Array.from(document.querySelectorAll('#content .msg-cont')).forEach(msg => { - embedLinksToX(msg, beforeNodeSelector, allLinksSelector, ctsUsers, ctsTags); + embedLinksToX(msg, beforeNodeSelector, allLinksSelector); }); } |