forked from chriszarate/bookmarkleter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
browser-tool.js
57 lines (41 loc) · 1.11 KB
/
browser-tool.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
var angular = require('angular');
var bookmarkleter = require('./bookmarkleter');
var app = angular.module('bookmarkleter', []);
var defaultName = 'My Bookmarklet';
app.config(['$compileProvider', function ($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/./);
}]);
app.controller('appController', ['$scope', function ($scope) {
$scope.options = {
urlencode: true,
iife: true,
minify: true,
transpile: false,
jQuery: false
};
$scope.name = $scope.displayName = defaultName;
$scope.error = null;
$scope.updateBookmarklet = function (options) {
var code = $scope.input;
var name = $scope.name;
if (name.trim().length === 0) {
name = defaultName;
}
$scope.displayName = name;
if (!code) {
$scope.output = '';
$scope.error = null;
return;
}
// Make a bookmarklet and show to user. Capture parse errors.
try {
$scope.output = bookmarkleter(code, options);
$scope.error = null;
} catch (err) {
$scope.error = err.message;
$scope.output = null;
return;
}
};
}]);