MediaWiki:Deadvideo/code.js

// //dead video link detector //uses 3rd-party proxy (noembed.com) to connect to youtube //maintainer: user:fngplg (function($) {   var dv = {};    dv.cpage = 0; //current page    dv.deadhlp = function (data) {        //dead helper        dv.txtDead.val(dv.txtDead.val + data.file + '|' + data.eurl + '\n');    };//deadhlp    dv.process = function  {        if (dv.cpage === 0) {            return;        }        dv.txtSPage.get(0).value = dv.cpage;        var url = '/wiki/Special:Video?format=json&page=' + dv.cpage;        $.getJSON(url).done(function(data){ if (data && data.videos && data.videos.length>0) { //add videos to list var eurl; for (var i=0, len=data.videos.length, v=data.videos; i 2) { dv.stop;//debug return this; }*/           setTimeout(dv.process.bind(this), 500); });//getjson   };//process    dv.isalive = function (vid, file, eurl) {        var prom = new Promise(function (resolve, reject) { var url = 'http://www.youtube.com/watch?v=' + vid; $.getJSON('https://noembed.com/embed?callback=?', {'format': 'json', 'url': url}).done(function(data){               if (data && data.title) {                    //alive                    resolve({file: file, eurl: eurl, data: data});                } else {                    reject({file: file, eurl: eurl, data: data});                }//if data            }).fail(function(e){reject({file: file, eurl: eurl, e: e})});//getjson });//promise       return prom;    };//isalive    dv.start = function (ev) {        dv.cpage = parseInt(dv.txtSPage.get(0).value || 1, 10) || 1;        dv.txtSPage.get(0).value = dv.cpage;        dv.btnStart.get(0).disabled = true;        dv.btnStop.get(0).disabled = false;        dv.process;    };//start    dv.stop = function  {        dv.cpage = 0;        dv.btnStart.get(0).disabled = false;        dv.btnStop.get(0).disabled = true;    };//stop    dv.init = function init  {        dv.createGui;        dv.btnShow=$(' ', {text:'dead video'}).on('click', function{ dv.Gui.toggle; });//btnShow.click       //$btn.css('float', 'right');        $('.page-header__contribution .page-header__contribution-buttons').prepend(dv.btnShow);    };//init    dv.createGui = function  {        dv.Gui=$(' ', {class:'deadvideo-gui'});        dv.Gui.hide;        $('#mw-content-text').prepend(dv.Gui);        dv.guiHead=$(' ', {class:'dv-head', id:'dv-head'}).appendTo(dv.Gui);        dv.lblSPage=$(' ', {text:'page'}).appendTo(dv.guiHead);        dv.txtSPage=$(' ', {id:'dv-start-page'}).appendTo(dv.guiHead);        dv.txtSPage.css('width', '3em');        dv.guiBtn=$(' ', {class:'dv-btn', id:'dv-btn'}).appendTo(dv.guiHead);        dv.guiBtn.css('display', 'inline-flex').css('float', 'right');        dv.btnStart=$(' ', {text:'start', id:'dv-btn-start'}).appendTo(dv.guiBtn);        $(dv.Gui).on('click', '#dv-btn-start', dv.start);        dv.btnStop=$(' ', {text:'stop', id:'dv-btn-stop', disabled: true}).appendTo(dv.guiBtn); $(dv.Gui).on('click', '#dv-btn-stop', dv.stop); dv.guiData=$(' ', {id:'dv-data'}).appendTo(dv.Gui); dv.txtFile=$(' ', {id:'dv-data-file'}).appendTo(dv.guiData); dv.txtFile.css('width', '100%').css('height', '100px'); dv.txtDead=$(' ', {id:'dv-data-dead'}).appendTo(dv.guiData); dv.txtDead.css('width', '100%').css('height', '100px'); };//createGui $(dv.init); })(jQuery);