Giter Site home page Giter Site logo

kazenoyumex / rss-web-player Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 67.74 MB

以原生JavaScript做WEB簡易播放器,內含各式簡易播放方法以及RSS跑馬燈,具ES6、ES5雙版本。

License: MIT License

CSS 0.84% HTML 18.97% JavaScript 80.19%

rss-web-player's Introduction

RSS-Web-Player-

以原生JavaScript做WEB簡易播放器,內含各式簡易播放方法以及RSS跑馬燈,具ES6、ES5雙版本。

Sample

Note

以原生JavaScript做WEB簡易播放器,內含各式簡易播放方法以及RSS跑馬燈,具ES6、ES5雙版本。

Features

  • 原生 JavaScript (no jQuery)
  • 為符合相異環境,同時具備ES5和ES6雙版本
  • 使用 CSS animations

ES6 Version

Quick Usage

use the rss-ES6.js script file and declare the RSSMarquee Class

<body>
    <div class=""></div>

    <script src="rss-ES6.js"></script>

    <script>
        document.addEventListener('DOMContentLoaded', () => {

            const feedUrl = ['https://www.dnoticias.pt/rss/home.xml', 'https://cors-anywhere.herokuapp.com/https://www.buzzfeed.com/world.xml'];

            const elementSelector = document.getElementById('marquee');

            new RSSMarquee(feedUrl, elementSelector);
        });
    </script>
</body>

RSSMarquee(feedURLs, elementContainer, options)

Class options

Property Type Required Description
feedURLs string[] yes List of RSS Feed URLs
elementContainer HTMLelement yes the selector of the marquee container
options.speed number no Duration in ms per character. Bigger values = slow speed. Value between 50-300. Default value: 110
options.maxItems number no specify max number of titles to show (useful to debug: not wait for all titles before goes to the next feed)
options.hostnameSelector HTMLelement no The selector of the element where you want to show the URL of the news feed source (usefull for copyright atttribution)

Motivation and history

I've created this code because I needed a news feed scrolling text on a client project. After a quick search, I found some solutions, but none completely satisfies me. I didn't want to use jQuery and many libraries depend on it. Also, I want to make it at lean as possible and to take advantage of recent browser technologies with graphic acceleration, so I ditched all alternatives who use the setInterval function to set the animation time.

How it works

  1. The XML feed is fetched using the native fetch API
  2. The XML is parsed to extract all the titles
  3. The titles are processed (remove HTML tags and invalid characters)
  4. The container element is animated with the translateX CSS function
  5. After the animation ends (with the onfinish event), the library fetches the next feed

ES5 Version

Quick Usage

use the rss-ES5.js script file and declare the RSSMarquee function

<body>
    <div id="rss"></div>

    <script src="rss-ES5.js"></script>

    <script>
         var feedUrl = ['https://ithelp.ithome.com.tw/rss/series/1227']
         var rss = document.querySelector('.RSS-ES5');

         RSSMarquee = {
             feedURLs: null, elementContainer: null
             , options: {speed: null, maxItems: null, hostnameSelector: null}
         }
        RSSMarqueeSetting()
    </script>
</body>

RSSMarquee(feedURLs, elementContainer, options)

Class options

Property Type Required Description
feedURLs string[] yes List of RSS Feed URLs
elementContainer HTMLelement yes the selector of the marquee container
options.speed number no Duration in ms per character. Bigger values = slow speed. Value between 50-300. Default value: 110
options.maxItems number no specify max number of titles to show (useful to debug: not wait for all titles before goes to the next feed)
options.hostnameSelector HTMLelement no The selector of the element where you want to show the URL of the news feed source (usefull for copyright atttribution)

Motivation and history

I've created this code because I needed a news feed scrolling text on a client project. After a quick search, I found some solutions, but none completely satisfies me. I didn't want to use jQuery and many libraries depend on it. Also, I want to make it at lean as possible and to take advantage of recent browser technologies with graphic acceleration, so I ditched all alternatives who use the setInterval function to set the animation time.

How it works

  1. The XML feed is fetched using the native fetch API
  2. The XML is parsed to extract all the titles
  3. The titles are processed (remove HTML tags and invalid characters)
  4. The container element is animated with the translateX CSS function
  5. After the animation ends (with the onfinish event), the library fetches the next feed

rss-web-player's People

Contributors

kazenoyumex avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.