Skip to content

Commit

Permalink
Merge pull request #1 from talis/TENT-2468-universal-extension
Browse files Browse the repository at this point in the history
TENT-2468: Refactor to make work in Chrome and MS Edge
  • Loading branch information
rsinger authored Aug 31, 2017
2 parents aaf01eb + 26e5fbd commit 4e3d0be
Show file tree
Hide file tree
Showing 34 changed files with 1,892 additions and 116 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

bower_components/
dist/
node_modules/
82 changes: 82 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
distdir: './dist',
copy: {
bower: {
files: [
{
expand: true,
cwd: './',
src: [
'bower_components/bootstrap/dist/js/bootstrap.min.js',
'bower_components/bootstrap/dist/css/bootstrap.min.css',
'bower_components/jquery/dist/jquery.min.js'
],
dest: 'dist'
}
]
},
common: {
files: [
{
expand: true,
cwd: './',
src: [
'*.html',
'_locales/**',
'images/**',
'css/**',
'js/*.js',
'!js/ms'
],
dest: 'dist'
}
]
},
msedge: {
files: [
{
expand: true,
cwd: './',
src: [
'js/ms/**'
],
dest: 'dist'
}
]
}
}
});

grunt.loadNpmTasks('grunt-contrib-copy');

grunt.registerTask('create-dist-dir', 'Creates the dist directory', function () {
grunt.file.delete(grunt.config('distdir'));
grunt.file.mkdir(grunt.config('distdir'));
});
grunt.registerTask('write-manifest', 'Writes the manifest file to dist', function (browser) {
var manifest = grunt.file.readJSON('manifest.json');
manifest.version = grunt.config('pkg.version');
if (grunt.option('identifier')) {
manifest.applications = { 'gecko': { 'id': grunt.option('identifier') } };
}
if (browser !== 'msedge') {
delete(manifest['-ms-preload']);
}
grunt.file.write(grunt.config('distdir') + '/manifest.json', JSON.stringify(manifest, null, 2));
});
grunt.registerTask(
'dist-common',
'Create distribution for Web Extension browsers',
['create-dist-dir', 'write-manifest:common', 'copy:bower', 'copy:common']
);
grunt.registerTask(
'dist-msedge',
'Create distribution for Web Extension browsers',
['create-dist-dir', 'write-manifest:msedge', 'copy:bower', 'copy:common', 'copy:msedge']
);
grunt.registerTask('default', ['dist-common']);
};
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Talis Education Limited

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.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Talis Aspire Reading Lists Bookmarking Extension
================================================

Requirements:
- [npm](https://www.npmjs.com/)

This project provides an alternative to the Talis Aspire Reading Lists Bookmarking Bookmarklet,
which can be forked and rebranded for distribution in institutional enterprise environments.

The extension should work with:
- Google Chrome/Chromium
- Microsoft Edge
- Firefox
- Opera
- Vivaldi

To customize for your institution:

Replace images/icon*.png with appropriate images for your institution.

You will need images with the following dimensions (all dimensions in pixels):
- 128 x 128
- 48 x 48
- 40 x 40
- 32 x 32
- 30 x 30
- 25 x 25
- 24 x 24
- 20 x 20
- 16 x 16

The different sizes will be used by different browsers in different ways.

All strings in the extension can be edited by changing the values in the language files in the `_locales` directory.

To build the files for the extension,
```
$ npm install # This should also run bower install
# replace ./images/*.png and ./_locales with institutional preferences
$ grunt # This will build a Chrome/Opera/Vivaldi extension
$ grunt dist-msedge # This will build a Microsoft Edge extension
$ grunt --identifier="{AMO UUID}" # This will build the extension with a Mozilla Add-on Identifier
```

The `./dist` directory should then contain everything you need for a `.crx`, `.xpi`, `.zip`, etc.
2 changes: 1 addition & 1 deletion _locales/cy/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"description": "Manually specify tenant short code option"
},
"optionsShortCodeLabel": {
"message": "Cod byr",
"message": "Cod byr:",
"description": "Manually add tenant by short code input label"
},
"optionsSave": {
Expand Down
2 changes: 1 addition & 1 deletion _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"description": "Manually specify tenant short code option"
},
"optionsShortCodeLabel": {
"message": "Short code",
"message": "Short code:",
"description": "Manually add tenant by short code input label"
},
"optionsSave": {
Expand Down
6 changes: 6 additions & 0 deletions background.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<script type="text/javascript" src="js/allTenants.js"></script>
<script type="text/javascript" src="js/tenants.js"></script>
<script type="text/javascript" src="js/bookmarker.js"></script>
<script type="text/javascript" src="js/background.js"></script>
</html>
17 changes: 0 additions & 17 deletions background.js

This file was deleted.

22 changes: 0 additions & 22 deletions bookmarklet.js

This file was deleted.

24 changes: 24 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "talis-reading-lists-bookmarker",
"homepage": "https://github.com/talis/rl-chrome-extension-spike",
"authors": [
"[email protected]"
],
"description": "A browser extension to bookmark resources to Talis Aspire Reading Lists",
"main": "manifest.json",
"keywords": [
"extension"
],
"license": "MIT",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"bootstrap": "3.3.6"
}
}
5 changes: 0 additions & 5 deletions css/bootstrap.min.css

This file was deleted.

1 change: 1 addition & 0 deletions css/options.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
body { min-width: 500px; padding: 20px 0 20px 0; }
Binary file added images/icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon30.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon40.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions js/allTenants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Use this to populate the list of institutions in the options menu. In order for a tenant to
* appear, it *must* have an `apps.rl` value (which can be anything)
*
* The non-branded 'Talis' extension should use the tenant list from:
* https://talis-public.s3-eu-west-1.amazonaws.com/talis.com/customers.json
*/
var allTenants = {
"broadminster" : {
"name" : "Broadminster University",
"apps" : {
"rl" : true
}
},
"broadminster_old" : {
"name" : "Old Broadminster University",
"apps" : {
"rl" : true
}
},
"cst" : {
"name" : "CST | Talis Training",
"apps" : {
"rl" : true
}
}
};
34 changes: 34 additions & 0 deletions js/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Background script.
*
* This only does anything when the bookmarking button is clicked
*/
chrome.browserAction.onClicked.addListener(function(tab) {
// If no institution has been set, go to the options page to set one
getActiveTenant(function (tenantCode) {
if (!tenantCode) {
if (window.confirm(chrome.i18n.getMessage('noTenantAlert'))) {
chrome.runtime.openOptionsPage();
}
}
// Edge does not support the promise-based APIs (chrome.*), but, conveniently, it also
// requires the bookmarker to be injected via a content_script (whereas other browsers
// seem fine as background scripts), so we'll use that to differentiate
if (this.browser) {
browser.tabs.executeScript(
{ code: 'bookmarkPage("' + tenantCode + '")'}
);
} else {
// This is effectively the same as bookmarker.js
var bookmarkCode = 'var bookmarker = document.createElement(\'script\');' +
'bookmarker.setAttribute(\'src\', ' +
'\'https://bookmarking.talis.com/' + tenantCode + '/parser?bookmarkButtonVersion=1&uri=\' + ' +
'encodeURIComponent(encodeURI(window.location.href)) + \'&bookmarkVersion=1&title=\' + ' +
'encodeURIComponent(document.title) + \'&hasJquery=no\');document.body.appendChild(bookmarker);';
chrome.tabs.executeScript(
tab.id,
{ code: bookmarkCode}
);
}
});
});
21 changes: 21 additions & 0 deletions js/bookmarker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* This exists for MS Edge, and should more or less be functionally identical to `bookmarkCode`
* in `background.js`.
* Edge needs this to be a content_script that is injected, however.
* @todo Find a way to not duplicate this.
*/
/**
* Injected into page to redirect to the dynamic page parser
*
* @param {String} tenantCode
*/
function bookmarkPage(tenantCode) {
var bookmarker = document.createElement('script');
bookmarker.setAttribute(
'src',
'https://bookmarking.talis.com/' + tenantCode + '/parser?bookmarkButtonVersion=1&uri=' +
encodeURIComponent(encodeURI(window.location.href)) + '&bookmarkVersion=1&title=' +
encodeURIComponent(document.title) + '&hasJquery=no'
);
document.body.appendChild(bookmarker);
}
6 changes: 0 additions & 6 deletions js/bootstrap.min.js

This file was deleted.

4 changes: 0 additions & 4 deletions js/jquery-3.2.1.min.js

This file was deleted.

6 changes: 6 additions & 0 deletions js/ms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MS Edge Support Files
=====================

The files in `js/ms` were automatically generated by the Microsoft Edge Extension Toolkit.

See: https://www.microsoft.com/en-US/store/p/microsoft-edge-extension-toolkit/9nblggh4txvb?rtc=1 for details.
Loading

0 comments on commit 4e3d0be

Please sign in to comment.