Fix closure compile (#24)

1 file changed
tree: 1c86160b67e72e3a943dbc5ca5054d1a2c08a9ce
  1. demo/
  2. src/
  3. tools/
  4. .gitignore
  5. .prettierignore
  6. .prettierrc
  7. CONTRIBUTING.md
  8. karma.conf.js
  9. LICENSE
  10. package-lock.json
  11. package.json
  12. README.md
README.md

Text Fragments Polyfill

This is an attempt to polyfill the Text Fragments feature for browsers that don't support it directly.

There are still many limitations and the code is very hacky, but it serves well as a proof of concept. This could be used in Chrome for iOS by injecting the script with WKUserScript.

Installation

From npm:

npm install text-fragments-polyfill

From unpkg:

<script type="module>
  if (!('fragmentDirective' in Location.prototype) &&
      !('fragmentDirective' in document)) {
    import('https://unpkg.com/text-fragments-polyfill');
  }
</script>

Usage

// Only load the polyfill in browsers that need it.
if (
  !('fragmentDirective' in Location.prototype) &&
  !('fragmentDirective' in document)
) {
  import('text-fragments.js');
}

Demo

Try the demo on a browser that does not support Text Fragments.

Development

  1. Hack in /src.
  2. Run npm run start and open http://localhost:8080/demo/ in a browser that does not support Text Fragments URLs directly, for example, Safari.
  3. Hack, reload, hack,…
  4. You can modify the Text Fragments URLs directly in /demo/index.html (look for location.hash).

License

Apache 2.0. This is not an official Google product.