Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 8bd9b61

Browse files
authored
Merge pull request #407 from UMD-ARLIS/background
Refactor web extension
2 parents 1a643a4 + 0c46836 commit 8bd9b61

File tree

9 files changed

+1953
-530
lines changed

9 files changed

+1953
-530
lines changed

build/UserALEWebExtension/background.js

Lines changed: 700 additions & 152 deletions
Large diffs are not rendered by default.

build/UserALEWebExtension/content.js

Lines changed: 36 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
/*
2-
* Licensed to the Apache Software Foundation (ASF) under one or more
3-
* contributor license agreements. See the NOTICE file distributed with
4-
* this work for additional information regarding copyright ownership.
5-
* The ASF licenses this file to You under the Apache License, Version 2.0
6-
* (the "License"); you may not use this file except in compliance with
7-
* the License. You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
*/
17-
18-
/* eslint-disable */
19-
20-
// these are default values, which can be overridden by the user on the options page
21-
var userAleHost = 'http://localhost:8000';
22-
var userAleScript = 'userale-2.4.0.min.js';
23-
var toolUser = 'nobody';
24-
var toolName = 'test_app';
25-
var toolVersion = '2.4.0';
26-
27-
/* eslint-enable */
28-
291
/*
302
* Licensed to the Apache Software Foundation (ASF) under one or more
313
* contributor license agreements. See the NOTICE file distributed with
@@ -1107,6 +1079,37 @@ function options(newConfig) {
11071079
return config;
11081080
}
11091081

1082+
/*
1083+
* Licensed to the Apache Software Foundation (ASF) under one or more
1084+
* contributor license agreements. See the NOTICE file distributed with
1085+
* this work for additional information regarding copyright ownership.
1086+
* The ASF licenses this file to You under the Apache License, Version 2.0
1087+
* (the "License"); you may not use this file except in compliance with
1088+
* the License. You may obtain a copy of the License at
1089+
*
1090+
* http://www.apache.org/licenses/LICENSE-2.0
1091+
*
1092+
* Unless required by applicable law or agreed to in writing, software
1093+
* distributed under the License is distributed on an "AS IS" BASIS,
1094+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1095+
* See the License for the specific language governing permissions and
1096+
* limitations under the License.
1097+
*/
1098+
1099+
1100+
// browser is defined in firefox, but chrome uses the 'chrome' global.
1101+
var browser = browser || chrome;
1102+
function rerouteLog(log) {
1103+
console.log(log);
1104+
browser.runtime.sendMessage({
1105+
type: ADD_LOG,
1106+
payload: log
1107+
});
1108+
return false;
1109+
}
1110+
1111+
/* eslint-enable */
1112+
11101113
/*
11111114
* Licensed to the Apache Software Foundation (ASF) under one or more
11121115
* contributor license agreements. See the NOTICE file distributed with
@@ -1124,59 +1127,15 @@ function options(newConfig) {
11241127
* limitations under the License.
11251128
*/
11261129

1127-
1128-
// browser is defined in firefox, but not in chrome. In chrome, they use
1129-
// the 'chrome' global instead. Let's map it to browser so we don't have
1130-
// to have if-conditions all over the place.
1131-
1132-
var browser = browser || chrome;
1133-
1134-
// creates a Future for retrieval of the named keys
1135-
// the value specified is the default value if one doesn't exist in the storage
1136-
browser.storage.local.get({
1137-
sessionId: null,
1138-
userAleHost: userAleHost,
1139-
userAleScript: userAleScript,
1140-
toolUser: toolUser,
1141-
toolName: toolName,
1142-
toolVersion: toolVersion
1143-
}, storeCallback);
1144-
function storeCallback(item) {
1145-
injectScript({
1146-
url: item.userAleHost,
1147-
userId: item.toolUser,
1148-
sessionID: item.sessionId,
1149-
toolName: item.toolName,
1150-
toolVersion: item.toolVersion
1151-
});
1152-
}
1153-
function queueLog(log) {
1154-
browser.runtime.sendMessage({
1155-
type: ADD_LOG,
1156-
payload: log
1157-
});
1158-
}
1159-
function injectScript(config) {
1160-
options(config);
1161-
// start(); not necessary given that autostart in place, and option is masked from WebExt users
1130+
browser.storage.local.get("useraleConfig", function (res) {
1131+
options(res.useraleConfig);
11621132
addCallbacks({
1163-
"function": function _function(log) {
1164-
queueLog(Object.assign({}, log, {
1165-
pageUrl: document.location.href
1166-
}));
1167-
console.log(log);
1168-
return false;
1169-
}
1133+
reroute: rerouteLog
11701134
});
1171-
}
1135+
});
11721136
browser.runtime.onMessage.addListener(function (message) {
11731137
if (message.type === CONFIG_CHANGE) {
1174-
options({
1175-
url: message.payload.userAleHost,
1176-
userId: message.payload.toolUser,
1177-
toolName: message.payload.toolName,
1178-
toolVersion: message.payload.toolVersion
1179-
});
1138+
options(message.payload);
11801139
}
11811140
});
11821141

0 commit comments

Comments
 (0)