Commit 3a89d3ac authored by Nick Stenning's avatar Nick Stenning

Make settings loader CSP-compatible

I forgot about CSP! We disallow inline scripts in the Chrome extension,
so 18c47ba broke the extension. This commit replaces an inline script
with some JSON data, parsed by the settings factory.
parent f00cd272
...@@ -7,18 +7,20 @@ var angular = require('angular'); ...@@ -7,18 +7,20 @@ var angular = require('angular');
* @name settings * @name settings
* *
* @description * @description
* The 'settings' factory exposes shared application settings, read from the * The 'settings' factory exposes shared application settings, read from a
* global variable 'hypothesis.settings' in the app page. * script tag with type "application/json" and id "hypothesis-settings" in the
* app page.
*/ */
// @ngInject // @ngInject
function settings($window) { function settings($document) {
var data = {}; var settingsElement = $document[0].querySelector(
'script[type="application/json"]#hypothesis-settings');
if ($window.hypothesis && $window.hypothesis.settings) { if (settingsElement) {
angular.copy($window.hypothesis.settings, data); return angular.fromJson(settingsElement.textContent);
} }
return data; return {};
} }
module.exports = settings; module.exports = settings;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment