This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
56 lines (50 loc) · 2.1 KB
/
index.html
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
<html>
<head>
<meta charset="UTF-8">
<script src="https://lpcdn.lpsnmedia.net/unifiedwindow/widgetSDK.min.js"></script>
</head>
<body>
<div id="youtubediv"></div>
<script type="text/javascript">
(function () {
var youTubeString = "See this video:";
var lpWidgetSDK,
widgetSDKAPI = lpTag.LPWidgetSDK.API;
window.addEventListener("load", function () {
var bindingEvent = [widgetSDKAPI.events.CONVERSATION_INFO,
widgetSDKAPI.events.MESSAGES],
opts = {bind: {}};
bindingEvent.forEach(function (eventName) {
opts.bind[eventName] = {func: _onEvent, context: this};
});
lpWidgetSDK = lpTag.LPWidgetSDK.init(opts);
}.bind(this));
function _onEvent(eventData) {
console.log(eventData);
if(eventData.data.content.includes(youTubeString)){
var href = eventData.data.content.match(/href="([^"]*)/)[1];
console.log(href);
href = /=(.+)/.exec(href)[1];
console.log(href);
document.getElementById("youtubediv").innerHTML = '<iframe width="100%" height="100%" src="https://www.youtube.com/embed/'+href+'?autoplay=1"></iframe>'
//window.location.href = href;
sendNotification("Event received!");
}
}
function sendNotification(text) {
if (typeof text === "string") {
lpWidgetSDK.notify({content: text}, function (err) {
if (err) {
console.log("Error on sending notification from widget");
}
});
}
}
function disposeWidget() {
lpWidgetSDK.dispose(function (data) {
console.log("widget disposed");
});
}
})();
</script>
</body>