A chrome extension for tagging words with semantic information.
Go to file
Nils Norman Haukås fec1faa8b9 add no github badge 2024-01-22 15:17:52 +01:00
src bump version number 2017-07-11 18:26:52 +02:00
test prevent tags from wrapping 2017-07-11 10:59:42 +02:00
.gitignore Lay the ground for having unit tests. 2017-05-01 21:47:21 +02:00
README.md add no github badge 2024-01-22 15:17:52 +01:00
build.sh Ask user to login with google email on startup 2016-08-25 18:46:22 +02:00
config.js update browser loading files. Update typescript dl to 2.0.7 2017-04-15 23:06:53 +02:00
karma.conf.js formatting adjustment 2017-07-09 17:09:35 +02:00
karma.pre-test.js enabled karma tests to load the tagit-module before tests. 2017-06-06 21:32:50 +02:00
package-lock.json upgrade jquery, add package.json lock file. 2018-03-29 20:52:31 +02:00
package.json upgrade jquery, add package.json lock file. 2018-03-29 20:52:31 +02:00
package.sh update packaging setup. Update readme 2017-07-11 18:26:08 +02:00
screenshot1.png Adjust screenshot 2016-08-07 15:08:56 +02:00
screenshot_1280x800.png Added larger screenshot 2016-08-14 19:11:01 +02:00
tsconfig.json enabled karma tests to load the tagit-module before tests. 2017-06-06 21:32:50 +02:00
webpack.config.js enabled karma tests to load the tagit-module before tests. 2017-06-06 21:32:50 +02:00

README.md

tag-youre-it

Please don't upload to GitHub

A chrome extension for tagging words with semantic information.

Sample screenshot of the plugin in action

Development

What you need to do to get started developing this plugin.

Prerequisites:

  1. git clone this project.
  2. Run npm install
  3. Run npm start to serve up the prototype for live development. To configure what browser is started please see the npm start command found in the package.json file.

Please note: A workaround for CORS is needed for allowing the live development version to talk to the server.

Testing

  1. Run npm run webpack:watch in one terminal window to activate running code compilation.
  2. Run npm run test in another terminal window to start Karma tests.

Deployment

Steps to deploy an update to the Chrome extension.

  1. Increment the plugin version number found in src/plugin-specific/manifest.json
  2. Run npm run package to build a fresh dist/ folder and zip it into dist.zip.
  3. Log into Chrome Web Store Developer Dashboard - Google. You'll need to have access to the account that have publishing rights to this application.
  4. Within the dashboard upload the update .zip and hit publish.

Chrome testing

  1. Run npm run build to generate a dist/ folder.
  2. Inside chrome go to settings -> Extensions.
  3. Select Load unpacked extension and select the project's generated dist/ folder.
  4. You should now see a new browser icon. Go to a page and start tagging.
  5. In case of error: Press "f12" and have a look at the console log output.

Please note: After loading the plugin you'll see that it has a extension id in Chrome's list of loaded Extensions. Ensure that the file dist/menu.tpl.html point to this extension id. More info here about how the chrome plugin refers to files.

What's happening under the hood?

How is the plugin loaded? Manifest.json adds an icon and defines an event page called background.js. The event page adds a click listener to the plugin's browser icon. When triggered it will first load jquery and then inject the html menu in an iframe as well as create an iframe for housing the page content. The plugin is in fact reloading the page inside an iframe on the page. It will then continue loading dependencies before finally calling tagit.init() on the plugin which makes angular initialize itself making it possible to interact with the injected menu. When loading the plugin it will check localstorage for previously made tags and add them to the page. The plugin will also add click listeners to the iframe(s) containing the content to be tagged.

Why iframes? I originally tried to just inject the menu into the page to tag. This was the source of a number of issues. Tags need to be related to the original page structure but was disturbed by the injected non-static plugin menu. CSS was also quite unmanageable as the original page's css would disturb the plugin menu and vice versa. In really bad cases the content to be tagged would seep out of its containing <div></div> element and overlap the plugin menu. All things considered iframes seem like a decent approach since they shield our menu and the taggable content from each other.

How does tagging happen? After the plugin has been loaded it will have added click listeners to the iframe(s) containing the taggable content. When a click is registered the plugin will check if a word was selected. If a new word has been selected it will query a backend service (url endpoint) for possible definitions to tag the word with and display them in the menu. When the user selects a definition the plugin tags the word, saves the tag in localstorage and posts the result back to the backend service.

Particularities to tagging: When tagging a selection the plugin must always relate the tag position to the original DOM object (original web page structure). Thus the plugin will remove all tags and selections before saving a word selection or saving a tag. Tags also need to be loaded in a bottom up order so that their range.startOffset is always in relation to the original DOM. StartOffset is simply a position number of where the node (html element etc.) is located within the DOM tree-structure that starts with 0 (document root).

Even more particularities to tagging: When a word is selected rangy.js adds invisible selection markers (spans) to the page which safeguards against accidentally unselecting the word we are trying to tag or accidentally tagging the wrong word. The selection markers will be removed when loading the selection again (making the right word selected in blue on the page). After loading the selection we tag the word by wrapping it in a span that contains tagging information and style information which highlights the tagged word. A button element is also added inside the span for removing the tag.

Licensed under the MIT License

Copyright (c) 2016 Nils Norman Haukås

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.