-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbookmarklet.js
47 lines (41 loc) · 1.33 KB
/
bookmarklet.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
/**
* PlayInVLC
*
* A short script, intended to be used as a bookmarklet, to send a link present on a given page to a VLC server.
*
* VLC basics:
*
* Playing a file:
* http://192.168.1.73:8080/requests/status.xml?command=in_play&input=FILENAME
*
* Full screen:
* http://192.168.1.73:8080/requests/status.xml?command=fullscreen
*
*/
(function () {
"use strict";
var vlcHost = 'http://192.168.1.65:8080',
fileSuffix = 'hi.mp4',
anchors = document.querySelectorAll('a'),
i = 0;
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
function addScript(src) {
var head = document.getElementsByTagName('head')[0],
script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
head.appendChild(script);
}
for (i = 0; i <= anchors.length; i += 1) {
if (anchors[i].href.endsWith(fileSuffix)) {
if (confirm("Play immediately?\nPress Cancel to add to queue.")) {
addScript(vlcHost + '/requests/status.xml?command=in_play&input=' + anchors[i]);
} else {
addScript(vlcHost + '/requests/status.xml?command=in_enqueue&input=' + anchors[i]);
}
break;
}
}
})();