1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-04 18:29:39 +02:00

Make sure unload works

This commit is contained in:
Daniel 2021-08-02 15:06:40 -03:00
parent 786e48d71a
commit c8c5201a80

View file

@ -448,7 +448,11 @@ function addView(videos_id, currentTime) {
_addView(videos_id, currentTime); _addView(videos_id, currentTime);
} }
var _addViewBeaconAdded = false;
function addViewBeacon() { function addViewBeacon() {
if(_addViewBeaconAdded){
return false;
}
if (typeof player === 'object' && typeof mediaId !== 'undefined') { if (typeof player === 'object' && typeof mediaId !== 'undefined') {
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID; var url = webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID;
url = addGetParam(url, 'id', mediaId); url = addGetParam(url, 'id', mediaId);
@ -456,6 +460,7 @@ function addViewBeacon() {
url = addGetParam(url, 'seconds_watching_video', seconds_watching_video); url = addGetParam(url, 'seconds_watching_video', seconds_watching_video);
var beacon = new Image(); var beacon = new Image();
beacon.src = url; beacon.src = url;
_addViewBeaconAdded = true;
} }
} }
@ -1244,8 +1249,11 @@ function checkDescriptionArea() {
} }
}); });
} }
$(document).ready(function () { $(document).ready(function () {
window.onbeforeunload = function() {
addViewBeacon();
};
$(window).on("unload", function () { $(window).on("unload", function () {
addViewBeacon(); addViewBeacon();
}); });