项目作者: CaptainFact

项目描述 :
🔎 CaptainFact - Inject facts overlays on videos
高级语言: JavaScript
项目地址: git://github.com/CaptainFact/captain-fact-overlay-injector.git
创建时间: 2018-01-09T03:11:33Z
项目社区:https://github.com/CaptainFact/captain-fact-overlay-injector

开源协议:GNU Affero General Public License v3.0

下载



CaptainFact.io
















Community Code

Discord


AGPL3
GitHub release

Build Status
Coverage Status










This repo holds the overlay injector script, that basically add facts onto videos.
It is used by the browser extension,
and can be integrated on any website freely.

You can check the live demo with various integrations or the production version
used by the French channel Thinkerview on thinkerview.com

TODO

  • Basic injection
  • Dynamic configuration
  • Autosizing
  • Multiple videos on a single page

Usage

Declarative approach

Just specify a config object in window.CaptainFactOverlayConfig global key and import script. This is the way
you usually want to go as it is simple and allows you to load the script asynchronously without worrying about
waiting for it to be ready.

  1. <!-- Overlay configuration, see details below -->
  2. <script type="javascript">
  3. window.CaptainFactOverlayConfig = { /* Config here */ }
  4. </script>
  5. <!-- Import CaptainFact main script -->
  6. <script
  7. src="https://embed.captainfact.io/captain-fact-overlay-injector.min.js"
  8. async
  9. ></script>

Imperative approach

You can also import the library and instantiate it yourself:

  1. <script src="https://embed.captainfact.io/captain-fact-overlay-injector.min.js" ></script>

Then:

  1. let injector = new window.CaptainFactOverlayInjector({
  2. /* Config here */
  3. })

Configuration

(!) For now the overlay can only be injected to one video per page. It’s not a small change to make, but
we haven’t done it yet.

  1. window.CaptainFactOverlayConfig = {
  2. injector: {
  3. // Required
  4. /**
  5. * Function that selects all the nodes containing your video containers.
  6. * If `factsInjector` is not defined, facts will be added inside returned nodes.
  7. */
  8. videosSelector: undefined,
  9. /**
  10. * Function that resolves URL for a given video
  11. *
  12. * @param {object} video - The video tag as returned by videosSelector
  13. */
  14. urlExtractor: undefined,
  15. /**
  16. * Function that resolves an URL for a given video
  17. *
  18. * @param {object} video - The video tag as returned by videosSelector
  19. * @param {object} adapters - adapters list for different types of players.
  20. * Only `html5` is supported at the moment
  21. *
  22. * You can also implement your own, check `src/lib/video_adapters/html5.js`
  23. * if you need an example.
  24. *
  25. * Injector support a null return value, which can be used if you just
  26. * want to display facts without player binding.
  27. */
  28. getPlayer: undefined,
  29. // Optional
  30. /**
  31. * By default, facts are added in a new div added to video children.
  32. * You can change this behaviour by setting a custom function here.
  33. * Mounting `visibilityToggle` is optional
  34. *
  35. * @param mountFunc {function} - mount components (ex: mountFunc(myDiv, facts))
  36. * @param video - the video, as returned by videosSelector
  37. * @param facts - the facts component generator to pass to `mountFunc`
  38. * @param visibilityToggle - the visibilityToggle component generator to pass to `mountFunc`
  39. * (only for "overlay" display mode)
  40. */
  41. factsInjector: undefined,
  42. /**
  43. * Function that return a list of HTML node where
  44. * CaptainFact ON / OFF toggle should be injected
  45. */
  46. onOffToggleSelector: undefined,
  47. },
  48. app: {
  49. /**
  50. * Display type
  51. * overlay (default) - a right sidebar appearing above video, with a button to show / hide it
  52. * block - a solid block to inject facts somewhere else. **You MUST specify factsInjector if using this mode**
  53. */
  54. display: 'overlay',
  55. /**
  56. * Language used by default in UI: English
  57. */
  58. language: 'en',
  59. /**
  60. * Add a slide effect on sidebar entrance / leave when using overlay display. This will add a 'overflow: hidden'
  61. * for your component. Turn this off if the animation breaks your UI.
  62. */
  63. animate: true,
  64. /**
  65. * Enable autosize. It looks at parent container's size and adapt `baseSize` based on it
  66. */
  67. autoSize: true,
  68. /**
  69. * Minimum text size.
  70. */
  71. baseSize: '15px',
  72. /**
  73. * Graphics resources URL. Can be used to override default icons
  74. */
  75. graphics: {
  76. logo: {
  77. neutral: undefined,
  78. confirm: undefined,
  79. refute: undefined,
  80. },
  81. newTab: undefined,
  82. star: undefined,
  83. next: undefined,
  84. prev: undefined,
  85. close: undefined,
  86. },
  87. },
  88. }

API methods

The injector these methods:

  1. /**
  2. * (static) Return the current lib version
  3. * @returns {string}
  4. */
  5. getVersion()
  6. /**
  7. * Enable the fact injector
  8. * @returns {boolean} - returns false if already enabled or mounted
  9. */
  10. enable()
  11. /**
  12. * Disable fact injector and unmount all mounted facts
  13. */
  14. disable()
  15. /**
  16. * Unmount existing overlay and reload everything (except configuration)
  17. */
  18. reload()
  19. /**
  20. * @returns {boolean} true if enabled, false otherwise
  21. */
  22. isEnabled()
  23. /**
  24. * Autosize only triggers on window size change or fullscreen toggle.
  25. * If your application has special needs or resize events, you can use
  26. * this method to force autosize refresh
  27. */
  28. forceResize()
  29. /**
  30. * Change the locale for all instanced components
  31. * @param {string} locale - Two-chars locale ('en' or 'fr')
  32. */
  33. changeLanguage(locale)

Developing

Start the API

See https://github.com/CaptainFact/captain-fact-api

Start the Frontend

See https://github.com/CaptainFact/captain-fact-frontend

Start the injector development interface

  • Install

    • NodeJS, ideally using asdf-vm with NODEJS_CHECK_SIGNATURES=no asdf install
    • App dependencies: npm install
  • Run:

    • npm start - Start the injector web-interface
    • npm run test - Runs all unit tests

Linked projects