[wiki] [sites] Update surf feeds detection script || Charles E. Lehner

From: <git_AT_suckless.org>
Date: Fri, 17 Jul 2020 03:18:36 +0200

commit 1842ab48e290c62b0fbb58c1c89fff784d7527e6
Author: Charles E. Lehner <cel_AT_celehner.com>
Date: Thu Jul 16 20:30:46 2020 -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

diff --git a/surf.suckless.org/files/feeds/index.md b/surf.suckless.org/files/feeds/index.md
index 5e2780b8..9c2cf598 100644
--- a/surf.suckless.org/files/feeds/index.md
+++ b/surf.suckless.org/files/feeds/index.md
_AT_@ -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]"))
_AT_@ -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;
 
_AT_@ -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);
+ })();
Received on Fri Jul 17 2020 - 03:18:36 CEST

This archive was generated by hypermail 2.3.0 : Fri Jul 17 2020 - 03:24:43 CEST