sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

commit 1842ab48e290c62b0fbb58c1c89fff784d7527e6
parent bf7b5036d478b1277d8a7888471a91478089ee53
Author: Charles E. Lehner <cel@celehner.com>
Date:   Thu, 16 Jul 2020 20:30:46 -0400

Update surf feeds detection script

- Don't wait for DOMContentLoaded.  Scripts now run after DOM content is
  already loaded.
- Remove duplicate feed links
- Hide feed count if there is only one
- Note installation procedure
- Update author name and link

Diffstat:
Msurf.suckless.org/files/feeds/index.md | 18++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/surf.suckless.org/files/feeds/index.md b/surf.suckless.org/files/feeds/index.md @@ -8,17 +8,18 @@ This script looks for links to RSS or Atom feeds in the current web page. If it finds feeds, it places an icon in the corner of the page which toggles showing a list of the feeds. +To install, put the code in `~/.surf/script.js` + Author ------ -Charles Lehner <http://celehner.com> +Charles E. Lehner <https://celehner.com/> Code ---- - document.addEventListener('DOMContentLoaded', function fn() { - document.removeEventListener('DOMContentLoaded', fn, true); - + (function () { + var urls = {} var feeds = [].slice.call(document.querySelectorAll( "link[href][rel~=alternate][type$=xml]," + " a[href][rel~=alternate][type$=xml]")) @@ -28,6 +29,9 @@ Code title: el.title || document.title, type: /atom/i.test(el.type) ? 'Atom' : 'RSS' }; + }).filter(function (feed) { + if (urls[feed.href]) return false + return urls[feed.href] = true }); if (!feeds.length) return; @@ -80,11 +84,13 @@ Code 'BDQKRhAOsbICNEEAOw=='; toggleLink.appendChild(img); - toggleLink.appendChild(document.createTextNode(feeds.length)); + if (feeds.length > 1) { + toggleLink.appendChild(document.createTextNode(feeds.length)); + } function toggleFeedList(e) { e.preventDefault(); feedList.style.display = (feedList.style.display == 'none') ? 'inline-block' : 'none'; } - }, true); + })();