MihaiPanciu / Mihai QRmp3 YouTube

// ==UserScript==
// @name         Mihai QRmp3 YouTube
// @namespace    http://your.homepage/
// @version      0.5
// @description  This script generata a QR code to youtube page and if you scan with your smart phone. You get MP3 from video.
// @author       You
// @match        http*://www.youtube.com/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @grant        none
// ==/UserScript==


function afterNavigate() {
    if ('/watch' === location.path) {
        alert('Watch page!');
    }
}
(document.body || document.documentElement).addEventListener('transitionend',
  function(/*TransitionEvent*/ event) {
    if (event.propertyName === 'width' && event.target.id === 'progress') {
        mihaiqr();
    }
}, true);
// After page load
mihaiqr();

function youtubePageChange()
{
    mihaiqr();
    $('body').on('transitionend', function(event)
    {
        if (event.target.id != 'progress') return false;
        youtubeFunction();
    });
}

var old_l = "0";
var new_l;

function verific()
{
    
    var video_id = window.location.search.split('v=')[1];
    var ampersandPosition = video_id.indexOf('&');
    if(ampersandPosition != -1) {
     video_id = video_id.substring(0, ampersandPosition);
    }

    if(old_l == "0")
       old_l = video_id;
    else
      new_l = video_id;
      
      if(old_l != new_l)
      {
            old_l = new_l;
            mihaiqr();
      }
      setTimeout(verific, 5000);
}

function verific2()
{
    var myElem = document.getElementById('qrmihai');
    if (myElem === null)
    {
        mihaiqr();
    }
    setTimeout(verific2, 5000);
}

youtubePageChange();
setTimeout(verific, 5000);
setTimeout(verific2, 5000);


function mihaiqr(){
setTimeout(verific, 5000);
setTimeout(verific2, 5000);

var video_id = window.location.search.split('v=')[1];
var ampersandPosition = video_id.indexOf('&');
if(ampersandPosition != -1) {
  video_id = video_id.substring(0, ampersandPosition);
}

var my_div = document.getElementById('watch7-sidebar-ads')
my_div.innerHTML = '';
    
my_div = document.getElementById('watch7-sidebar-offer')
my_div.setAttribute("align", "center");

var dwidth = document.getElementById('watch7-sidebar-contents').offsetWidth - 40;
my_div.innerHTML = '<div id="qrmihai" style="padding-bottom: 10px;"><a href="http://www.mzone.site90.com/qrmp3.php?url='+video_id+'" target="_blank"><img style="-webkit-user-select: none" width: 100%;max-height: 100% src="https://api.qrserver.com/v1/create-qr-code/?size='+dwidth+'x'+dwidth+'&amp;data=http://www.mzone.site90.com/qrmp3.php?url='+video_id+'"></a><h5> </h5><div>';
}