FreeTubeApp / freetube-redirect

Browser extension to open YouTube links into FreeTube
MIT License
56 stars 12 forks source link

won't always work #15

Open i300220 opened 3 years ago

i300220 commented 3 years ago

Let me explain.

2 issuse here:

1- If the link doesn't exist in the page when the extension is loaded. i.e. if the youtube link is created dynamically in the dom afterwards, it doesn't work and the youtube page is getting fired nevertheless.

What would be required I think is something like that (untested) , fired out periodically.

var cnt = 0; function manClick(){ var loadNewhref = $("A"); if(loadNewhref.length) { if (cnt > 0) return; cnt++; loadNewhref.click( function() { setTimeout( function() { window.addEventListener("click", (event) => { checkUrl(event); }); cnt = 0; window.setInterval(manClick, 30000); }, 20000); }); window.clearInterval(manClick); } };

window.setInterval(manClick, 30000);

2- Also this section in your original code fails sometimes: if (target.href.includes('youtube.com') || target.href.includes('youtu.be') || target.href.includes('hooktube.com')){ window.stop(); e.stopImmediatePropagation(); e.preventDefault(); let url = 'freetube://' + target.href; console.log(url); window.location = url; return false; } }

The youtube windows is fired nevertheless, th freetube does not open, or worst, both start playing simultaneously.

Would be happy to assist.

Here's an example where it fails. I don't think th link will be valid for a long time halas: https://www.upwork.com/jobs/Create-own-indicator-from-someone-else-indicator-software_~01d3b31336d39f8df2/

Go there and click the youtube link. A youtube window will opn and freetube never open.

Best regards, Marccel