Script para ies

Script que agrega funcionalidades al tid

  1. // ==UserScript==
  2. // @name Script para ies
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.7
  5. // @description Script que agrega funcionalidades al tid
  6. // @author Falaz
  7. // @match http://tid.ies21.edu.ar/*
  8. // @grant none
  9. // @run-at document-end
  10. // ==/UserScript==
  11.  
  12. (function init() {
  13. try{
  14. var tiempoInicial = new Date();
  15. var a = document.querySelector('.ui-grid-c');
  16. var li = document.createElement('li');
  17. li.classList.add('ui-block-d');
  18. li.id = "achild";
  19. li.innerHTML = '<a href="javascript:void(0)" data-icon="gear" data-ajax="false" data-corners="false" data-shadow="false" data-theme="a" class="ui-btn ui-btn-up-a ui-btn-inline ui-btn-icon-top"><span class="ui-btn-inner"><span class="ui-btn-text">Falaz´s tools </span><span class="ui-btn-text" id="TimeSpan">00:00</span><span class="ui-icon ui-icon-gear ui-icon-shadow ">&nbsp;</span></span></a>';
  20. try {
  21. a.appendChild(li);
  22. a.classList.remove('ui-grid-c');
  23. a.classList.add('ui-grid-d');
  24. } catch (error) {
  25. console.log("Será porque lo hace dos veceS?");
  26. }
  27. li.onclick = function () {
  28. tiempoInicial = new Date();
  29. console.log("me hiciste click:D");
  30. return false;
  31. };
  32. var timeSpan = document.querySelector('#TimeSpan');
  33.  
  34. // Calcular tiempo de lectura
  35. var todosLosP = document.getElementsByTagName("p");
  36. var texto = "";
  37. for (var i = 0; i < todosLosP.length; i++) {
  38. texto += (todosLosP[i].innerText);
  39. }
  40. texto = texto.replace(/[ ]+/g, " ");
  41. texto = texto.replace(/^ /, "");
  42. texto = texto.replace(/ $/, "");
  43. var textoTroceado = texto.split(" ");
  44.  
  45. var numeroPalabras = textoTroceado.length;
  46.  
  47. console.log("Palabras contadas: " + numeroPalabras);
  48. console.log("El tiempo estimado de lectura, se basa en unas 150 o 100 palabras por minuto");
  49. console.log("Tiempo inicial: " + tiempoInicial);
  50. try{
  51. timeSpan.innerText = Math.round(numeroPalabras / 170) + " - " + Math.round(numeroPalabras / 130) + " min aprox\n";
  52. }catch(error){}
  53. var time = setInterval(myTimer, 1000);
  54.  
  55. function myTimer() {
  56. var c = new Date();
  57. var segundos = (c.getTime() - tiempoInicial.getTime()) / 1000;
  58. var min = Math.floor(segundos / 60);
  59. segundos = Math.round(segundos % 60);
  60.  
  61. }
  62.  
  63. function replaceLinks() {
  64. var botones = document.getElementsByClassName('ui-btn');
  65. var linksPrincipal = document.getElementsByClassName('ui-link-inherit');
  66. var i = 0;
  67. for (i = 0; i < linksPrincipal.length; i++) {
  68. linksPrincipal[i].onclick = function () {
  69. $(document).on('pageshow', function (e) {
  70. init();
  71. });
  72. };
  73. }
  74. // for (i = 0; i < botones.length; i++) {
  75. // botones[i].onclick = function () {
  76. // $(document).on('pageshow', function (e) {
  77. // init();
  78. // });
  79. // };
  80. // }
  81. //console.log("links reemplazados");
  82. }
  83.  
  84. function replaceMedia() {
  85. var medias = $('.textoc'),
  86. mediasLinks = $('a'),
  87. medias2 = $('.tc'),
  88. link, tipo, div, i = 0;
  89. for (i = 0; i < medias.length; i++) {
  90. if (medias[i].children) {
  91. console.log("tiene hijos");
  92. if (medias[i].children.length > 0 && medias[i].children[0] !== null) {
  93. link = '';
  94. tipo = 'video';
  95. link = medias[i].children[0].href;
  96. div = document.createElement('div');
  97. replaceVideo(link, div, medias[i]);
  98. div.id = 'media' + [i];
  99. medias[i].appendChild(div);
  100. }
  101. }
  102. // $('#media' + [i]).load(link + '#containingBlock');
  103. }
  104. for(i = 0;i<medias2.length;i++){
  105. if(medias2[i].children){
  106. if(medias2[i].children.length >0 && medias2[i].children[0] !== null){
  107. link = "";
  108. tipo = 'object';
  109. link = medias2[i].children[0].href;
  110. div = document.createElement('div');
  111. replaceVideo(link,div,medias2[i]);
  112. div.id = "media" + medias2[i];
  113. medias2[i].appendChild(div);
  114. }
  115. }
  116. }
  117. for (i = 0; i < mediasLinks.length; i++) {
  118. if (mediasLinks[i].href.match(/media/)) {
  119. if (mediasLinks[i].attributes.getNamedItem('data-rel') == null) {
  120. //console.log(mediasLinks[i].href);
  121. link = '';
  122. tipo = 'object';
  123. link = mediasLinks[i].href;
  124. div = document.createElement('div');
  125. replaceVideo(link, div, mediasLinks[i]);
  126. div.id = 'media' + [i];
  127. mediasLinks[i].appendChild(div);
  128. }
  129. }
  130. }
  131. }
  132.  
  133. function replaceVideo(link, div, medias) {
  134. if(link === undefined){/*console.log(link, div, medias);*/return null;}
  135. var xhr = new XMLHttpRequest();
  136. xhr.withCredentials = true;
  137.  
  138. xhr.addEventListener("readystatechange", function () {
  139. if (this.readyState === 4 && div.dataset.tipo == undefined) {
  140. //tomar el iframe del response. Para los videos de youtube.
  141. if (xhr.response.includes('iframe')) {
  142. //remove link and img from div
  143.  
  144. medias.children[0].remove();
  145. var index = xhr.response.indexOf('<iframe');
  146. var j = xhr.response.lastIndexOf('iframe>');
  147. j += 7;
  148. var iframetext = xhr.response.substring(index, j);
  149. var iframeSrc = iframetext.match(/src="([^"]+)"/);
  150. var iframe = document.createElement('iframe');
  151. iframe.src = iframeSrc[1];
  152. iframe.height = 400;
  153. iframe.width = 600;
  154. div.dataset.tipo = "video";
  155. div.appendChild(iframe);
  156. // div.append("aquí estaba un video");
  157. } else if (xhr.response.includes('video')){
  158. medias.children[0].remove();
  159. var iVideo = xhr.response.indexOf('<video');
  160. var jVideo = xhr.response.indexOf('video>');
  161. var videotext = xhr.response.substring(iVideo, jVideo);
  162. var src = videotext.match(/src="([^"]+)\./);
  163. var video = document.createElement('video');
  164. video.controls = true;
  165. video.poster = src[1] + ".jpg";
  166. video.width = 640; video.height = 480;
  167. //in video
  168. var source = document.createElement('source');source.src = src[1] + ".mp4";source.type = "video/mp4";
  169. var object = document.createElement('object');object.width ="100%";object.height=480;object.type = "application/x-shockwave-flash";object.data = "fp//flashmediaelement.swf";
  170. //in object
  171. var paramMovie = document.createElement('param');paramMovie.name = "movie"; paramMovie.value = "fp/flashmediaelement.swf";
  172. var paramAllow = document.createElement('param');paramAllow.name = "allowScriptAccess";paramAllow.value="always";
  173. var paramFlash = document.createElement('param');paramFlash.name = "flashvars";paramFlash.value = "autoplay=false&autohide=false&controls=true&file=../" + src[1] + ".mp4";
  174. var paramImg = document.createElement('img');paramImg.width = 640;paramImg.height = 480;paramImg.src = src[1] + ".jpg";
  175. object.appendChild(paramMovie);object.appendChild(paramAllow);object.appendChild(paramFlash);object.appendChild(paramImg);
  176. video.appendChild(source);
  177. video.appendChild(object);
  178. div.appendChild(video);
  179. //console.log("incluye video :DD");
  180. div.dataset.tipo = "video";
  181. } else if (xhr.response.includes('object')) {
  182. //console.log("Soy un object :D");
  183. medias.children[0].remove();
  184. var iObject = xhr.response.indexOf('<object');
  185. var jObject = xhr.response.indexOf('.swf"');
  186. //console.log(iObject, jObject);
  187. jObject += 5;
  188. var objectText = xhr.response.substring(iObject, jObject);
  189. var objectData = objectText.match(/data="([^"]+)"/);
  190. var objectWidth = objectText.match(/width="([^"]+)"/);
  191. var objectHeight = objectText.match(/height="([^"]+)"/);
  192. var iframeObject = document.createElement('object');
  193. iframeObject.data = objectData[1];
  194. iframeObject.height = parseInt(objectHeight[1]) + 100;
  195. //if (objectWidth[1].match(/%/)){
  196. // iframeObject.width = 600;
  197. //}else{
  198. iframeObject.width = objectWidth[1];
  199. //}
  200. div.dataset.tipo = "object";
  201. div.appendChild(iframeObject);
  202. }else if(xhr.response.includes('div id="containingBlock"')){
  203. //console.log("Es una imagen :DD");
  204. } else {
  205. //console.log("hola, agregué un iframe :D");
  206. medias.children[0].remove();
  207. var iFrameEntirePage = document.createElement('iframe');
  208. iFrameEntirePage.src = link;
  209. iFrameEntirePage.width = 800;
  210. iFrameEntirePage.height = 600;
  211. var exist = false;
  212. div.appendChild(iFrameEntirePage);
  213. div.dataset.tipo = "iframe";
  214.  
  215. }
  216.  
  217. }
  218. });
  219. xhr.open("GET", link);
  220. xhr.send('cache-control');
  221. }
  222.  
  223. setTimeout(replaceLinks(), 1000);
  224. setTimeout(replaceMedia(), 1000);
  225. document.onmouseup = function(e) {
  226. if(e.srcElement.localName == "p"){
  227. if (e.shiftKey){apptx.mSeleccion(1);}
  228. else{apptx.mSeleccion(2);}
  229. }
  230. };
  231. }catch(error){}
  232. })();