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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// ==UserScript==
// @include http://vk.com/*
// @require utils.js
// ==/UserScript==
// This placeholder gets munged with real data at build time.
var WebappsGettextDict = JSON.parse(unescape(
"%7B%22GETTEXT%22%3A%22PLACEHOLDER%22%7D"
));
var Unity = external.getUnityObject(1);
window.Unity = Unity;
function isCorrectPage() {
var i, ids = ['top_links', 'logout_link'];
for (i = 0; i < ids.length; i++) {
if (!document.getElementById(ids[i])) {
return false;
}
}
return true;
}
function playerSetup() {
// Chromium: This function is being injected into the webpage e.g. in a different
// JS context than the content script's. You cannot close over content script variables.
Unity = window.Unity || external.getUnityObject(1);
var audioPlayer = window.audioPlayer;
if (!audioPlayer) {
return;
}
if (audioPlayer.player) {
if (!audioPlayer.player.paused()) {
Unity.MediaPlayer.setPlaybackState(Unity.MediaPlayer.PlaybackState.PLAYING);
} else {
Unity.MediaPlayer.setPlaybackState(Unity.MediaPlayer.PlaybackState.PAUSED);
}
}
Unity.MediaPlayer.onPlayPause(function () {
if (audioPlayer.player.paused()) {
audioPlayer.playTrack();
} else {
audioPlayer.pauseTrack();
}
});
Unity.MediaPlayer.setTrack({
title: audioPlayer.lastSong[6],
album: null,
artist: audioPlayer.lastSong[5],
artLocation: null
});
Unity.MediaPlayer.onNext(function () {
audioPlayer.nextTrack();
});
Unity.MediaPlayer.onPrevious(function () {
audioPlayer.prevTrack();
});
}
function messagingIndicatorSetup() {
var countElement = document.evaluate('//li[@id="l_msg"]/a/span[2]', document, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null).singleNodeValue;
function checkMessagesCount() {
var count = countElement.textContent;
if (!count.length) {
count = '0';
}
Unity.MessagingIndicator.showIndicator(_("Inbox"), { count: count });
}
countElement.addEventListener('DOMSubtreeModified', checkMessagesCount, false);
checkMessagesCount();
evalInPageContext('function () {setInterval(' + playerSetup + ', 1000);}');
}
if (isCorrectPage()) {
Unity.init({ name: _("vk.com"),
domain: 'vk.com',
homepage: 'http://vk.com',
iconUrl: 'icon://unity-webapps-vkontakte-ru',
onInit: messagingIndicatorSetup });
}
|