Skip to content

Commit 962775a

Browse files
author
Nadeem Haidar
committed
Add Chrome Extension source files
1 parent 200ae44 commit 962775a

5 files changed

Lines changed: 70 additions & 0 deletions

File tree

YouTube15-Helper/YouTube15.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
var id = uniqueId();
2+
3+
var title = document.getElementsByClassName("watch-title")[0].getAttribute("title");
4+
5+
var uploader = document.getElementsByClassName("yt-user-info")[0].innerText;
6+
7+
var video = document.getElementsByTagName("video")[0];
8+
9+
var timeout = 0;
10+
11+
var repeat = setInterval(function() {
12+
sendData(title, uploader, video.currentTime, video.duration, video.paused, false);
13+
}, 500);
14+
15+
window.onbeforeunload = function () {
16+
clearInterval(repeat);
17+
// send termination flag when tab or browser is closing.
18+
sendData(title, uploader, video.currentTime, video.duration, video.paused, true);
19+
};
20+
21+
function sendData(title, uploader, currentTime, duration, paused, terminate){
22+
var xhttp = new XMLHttpRequest();
23+
xhttp.open("POST", "http://127.0.0.1:60024/", true);
24+
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
25+
var data = {
26+
"id" : id,
27+
"title" : title,
28+
"uploader": uploader,
29+
"currentTime": currentTime,
30+
"duration": duration,
31+
"paused" : paused,
32+
"terminate": terminate
33+
};
34+
xhttp.send(JSON.stringify(data));
35+
//return xhttp.status;
36+
}
37+
38+
function uniqueId () {
39+
// desired length of Id
40+
var idStrLen = 32;
41+
// always start with a letter -- base 36 makes for a nice shortcut
42+
var idStr = (Math.floor((Math.random() * 25)) + 10).toString(36) + "";
43+
// add a timestamp in milliseconds (base 36 again) as the base
44+
idStr += (new Date()).getTime().toString(36) + "";
45+
// similar to above, complete the Id using random, alphanumeric characters
46+
do {
47+
idStr += (Math.floor((Math.random() * 35))).toString(36);
48+
} while (idStr.length < idStrLen);
49+
50+
return (idStr);
51+
}

YouTube15-Helper/icon128.png

31.5 KB
Loading

YouTube15-Helper/icon16.png

18.3 KB
Loading

YouTube15-Helper/icon48.png

20.9 KB
Loading

YouTube15-Helper/manifest.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "YouTube15 Chrome Helper",
4+
"version": "1.0.0",
5+
"description": "Sends YouTube video info to YouTube15 (Applet for Logitech G15)",
6+
"permissions": ["tabs", "*://*.youtube.com/watch*", "http://127.0.0.1/"],
7+
"icons": {
8+
"16":"icon16.png",
9+
"48":"icon48.png",
10+
"128":"icon128.png"
11+
},
12+
"content_scripts": [
13+
{
14+
"run_at": "document_end",
15+
"matches": ["*://*.youtube.com/*"],
16+
"js": ["YouTube15.js"]
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)